From 867db34472c542f1e6758bd85098bec53966eedf Mon Sep 17 00:00:00 2001 From: Flo Date: Sun, 4 Aug 2024 21:31:58 +0200 Subject: [PATCH] first commit --- .DS_Store | Bin 0 -> 6148 bytes .idea/.gitignore | 8 +++++ .idea/dev.iml | 16 +++++++++ .idea/modules.xml | 8 +++++ .idea/php.xml | 22 ++++++++++++ .idea/vcs.xml | 8 +++++ bin/denv | 12 +++++++ bin/drun | 28 +++++++++++++++ bin/git | 11 ++++++ bin/script/exec | 19 ++++++++++ bin/script/foreachSystem | 20 +++++++++++ bin/script/prune | 10 ++++++ bin/script/pull | 15 ++++++++ bin/script/setup | 54 +++++++++++++++++++++++++++++ bin/script/upgrade | 14 ++++++++ bin/source | 7 ++++ build | 4 +++ docker/.gitignore | 1 + docker/docker-compose.yml | 27 +++++++++++++++ down | 4 +++ init | 4 +++ python/capture-thermometer-data.py | 37 ++++++++++++++++++++ stop | 4 +++ systems/.gitignore | 2 ++ up | 4 +++ 25 files changed, 339 insertions(+) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/dev.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml create mode 100755 bin/denv create mode 100755 bin/drun create mode 100755 bin/git create mode 100755 bin/script/exec create mode 100755 bin/script/foreachSystem create mode 100755 bin/script/prune create mode 100755 bin/script/pull create mode 100755 bin/script/setup create mode 100755 bin/script/upgrade create mode 100755 bin/source create mode 100755 build create mode 100644 docker/.gitignore create mode 100644 docker/docker-compose.yml create mode 100755 down create mode 100755 init create mode 100644 python/capture-thermometer-data.py create mode 100755 stop create mode 100644 systems/.gitignore create mode 100755 up diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d3ca7f37d88a7bd71578a78b850f3c230086384f GIT binary patch literal 6148 zcmeHK%Z}496uoX!nlc*H1qe1sk=Ry{K|(NM6FS3!EkUpVRGLX(qVdF4(h#AlQn$cA z@Cz*Y68INZaQtZ1Bp_CUVB{-ZAKUj_r#Y_en26Z8jQ5C!MC8IHIu}v=!em@}%Q~j# z5|F7e63Qrk#Klp>TWs556|f5YYYND<+oy=8bVMh#wSGl}h};$)z;FIghFXgqRmCjg ziv1;;@wAxx{x{a?I=u^hx9{$_FT-O|h4bmWEXLFPxokZVf=BE6GVkIUq}Hcw1|BEg;C*fIdYGUDqL(zQGrI>3rlY1(GAG}_WCU=^q<(ACYM zJpUj5{{CN2vMsBCRp4AHz?{SIaEw + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8cc3e82 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..9ef07eb --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..7f13aa8 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bin/denv b/bin/denv new file mode 100755 index 0000000..978286c --- /dev/null +++ b/bin/denv @@ -0,0 +1,12 @@ +#!/bin/bash + +ENVIRONMENT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../../ + +denv() { + if [ ! -z $1 ] + then + $ENVIRONMENT_DIR/$1 + else + cd $ENVIRONMENT_DIR + fi +} \ No newline at end of file diff --git a/bin/drun b/bin/drun new file mode 100755 index 0000000..bf43fef --- /dev/null +++ b/bin/drun @@ -0,0 +1,28 @@ +#!/bin/bash + +drun() { + # Überprüfen, ob die richtige Anzahl Argumente übergeben wurden + if [ $# -lt 2 ]; then + echo "Verwendung: drun " + return 1 + fi + + # Container-Namen extrahieren + local CONTAINER_NAME="$1" + shift # Das erste Argument entfernen + + # Den Rest der Argumente als Befehlszeichenfolge zusammenfügen + local COMMAND="$@" + + # Container-ID mithilfe des Container-Namens finden + local CONTAINER_ID=$(docker ps -qf "name=$CONTAINER_NAME-app") + + # Überprüfen, ob der Container gefunden wurde + if [ -z "$CONTAINER_ID" ]; then + echo "Container '$CONTAINER_NAME' wurde nicht gefunden." + return 1 + fi + + # Befehl im Container ausführen + docker exec -it "$CONTAINER_ID" $COMMAND +} diff --git a/bin/git b/bin/git new file mode 100755 index 0000000..feb31d1 --- /dev/null +++ b/bin/git @@ -0,0 +1,11 @@ +#!/bin/bash + +acp() { + git add . + git commit -m "$@" + git push +} + +co() { + git checkout $1 +} diff --git a/bin/script/exec b/bin/script/exec new file mode 100755 index 0000000..f12a32e --- /dev/null +++ b/bin/script/exec @@ -0,0 +1,19 @@ +#!/bin/bash + +COMMAND="$@" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +echo "Execute ${COMMAND} in denv" + +#MAC +if [[ "$OSTYPE" == "darwin"* ]]; then + docker compose -f "${SCRIPT_DIR}/../../docker/docker-compose-mac.yml" $COMMAND + +#LINUX +elif [[ "$OSTYPE" == "linux-gnu" ]]; then + docker compose -f "${SCRIPT_DIR}/../../docker/docker-compose.yml" $COMMAND + +else + echo "Dieses Skript wird auf deinem Gerät nicht unterstützt" + exit 1 +fi diff --git a/bin/script/foreachSystem b/bin/script/foreachSystem new file mode 100755 index 0000000..96b9f45 --- /dev/null +++ b/bin/script/foreachSystem @@ -0,0 +1,20 @@ +#!/bin/bash + +EXEC_DIR=$(pwd) +FILE_TO_EXECUTE=$1 + +if [ ! -z $1 ] +then + echo "Execute " $1 " in each system" +else + echo "Execute foreachSystem failed, because no parameter was provided" + exit +fi + + +for SYSTEM in systems/*/*/ ; do + echo "executing ${FILE_TO_EXECUTE} in ${SYSTEM}" + cd $SYSTEM + ./bin/script/$FILE_TO_EXECUTE + cd $EXEC_DIR +done diff --git a/bin/script/prune b/bin/script/prune new file mode 100755 index 0000000..4118be6 --- /dev/null +++ b/bin/script/prune @@ -0,0 +1,10 @@ +#!/bin/bash + +docker stop $(docker ps -aq) + +docker system prune -f + +docker network create homepage + +./pull +./bin/script/init diff --git a/bin/script/pull b/bin/script/pull new file mode 100755 index 0000000..8b6c798 --- /dev/null +++ b/bin/script/pull @@ -0,0 +1,15 @@ +#!/bin/bash + +EXEC_DIR=$(pwd) + +echo "Execute git pull in each system" + +#echo "denv" +#git pull + +for SYSTEM in $EXEC_DIR/systems/*/*/ ; do + echo $SYSTEM + cd $SYSTEM + git pull + cd $EXEC_DIR +done diff --git a/bin/script/setup b/bin/script/setup new file mode 100755 index 0000000..239688b --- /dev/null +++ b/bin/script/setup @@ -0,0 +1,54 @@ +#!/bin/bash + +echo $OSTYPE + +#MAC +if [[ "$OSTYPE" == "darwin"* ]]; then + home="$HOME" + +#LINUX +elif [[ "$OSTYPE" == "linux-gnu" ]]; then + home="$HOME" +else + echo "Dieses Skript wird nicht unter macOS oder Linux unterstützt." + exit 1 +fi + +script_path=$(pwd) +environment=$(basename $script_path) + +echo "source ~/$environment/bin/script/denv" >> ~/.profile +echo "source ~/$environment/bin/script/drun" >> ~/.profile +echo "source ~/$environment/bin/script/git" >> ~/.profile + +echo Running in $script_path +echo environment = $environment + +# $1 = frontend/backend +# $2 = repo name +fetch_repository() { + if [ ! -d "$1" ]; + then + echo "Create $1" + mkdir -p "$1" + fi + + cd $1 + + if [ ! -d "$2" ]; + then + gh repo clone TheFlawww/$2-$1 $2 + fi + + cd $script_path +} + + +#fetch all backends +fetch_repository backend weedkeeper + +#fetch all frontends +fetch_repository frontend weedkeeper + +# initialize +./bin/script/init diff --git a/bin/script/upgrade b/bin/script/upgrade new file mode 100755 index 0000000..d58e39a --- /dev/null +++ b/bin/script/upgrade @@ -0,0 +1,14 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +$SCRIPT_DIR/pull +source $SCRIPT_DIR/../source + +drun weedkeeper-backend composer da +drun weedkeeper-backend composer install +drun weedkeeper-backend composer dmm +drun weedkeeper-backend composer console rbac:update + +drun weedkeeper-frontend npm i +drun weedkeeper-frontend npm run build diff --git a/bin/source b/bin/source new file mode 100755 index 0000000..fee2747 --- /dev/null +++ b/bin/source @@ -0,0 +1,7 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +source $SCRIPT_DIR/denv +source $SCRIPT_DIR/drun +source $SCRIPT_DIR/git diff --git a/build b/build new file mode 100755 index 0000000..4f129c9 --- /dev/null +++ b/build @@ -0,0 +1,4 @@ +#!/bin/bash + +./bin/script/exec build +./bin/script/foreachSystem build diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 0000000..ec19369 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1 @@ +letsencrypt/* diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..b34894d --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,27 @@ +networks: + weedkeeper: + name: weedkeeper + +services: + traefik: + image: traefik:v3.0 + networks: + - weedkeeper + command: + - "--providers.docker=true" + - "--entrypoints.web.address=:80" + - "--entrypoints.web.http.redirections.entrypoint.to=websecure" + - "--entrypoints.web.http.redirections.entrypoint.scheme=https" + - "--entrypoints.websecure.address=:443" + - "--certificatesresolvers.le.acme.tlschallenge=true" + - "--certificatesresolvers.le.acme.email=florian_feistel@outlook.de" + - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json" + ports: + - "80:80" + - "443:443" + - "8080:8080" + volumes: + - "./letsencrypt:/letsencrypt" + - "/var/run/docker.sock:/var/run/docker.sock" + labels: + - "traefik.http.routers.traefik.rule=Host(`traefik.weedkeeper.de`)" diff --git a/down b/down new file mode 100755 index 0000000..ef738dc --- /dev/null +++ b/down @@ -0,0 +1,4 @@ +#!/bin/bash + +./bin/script/exec down +./bin/script/foreachSystem down diff --git a/init b/init new file mode 100755 index 0000000..4523edf --- /dev/null +++ b/init @@ -0,0 +1,4 @@ +#!/bin/bash + +./bin/script/exec init +./bin/script/foreachSystem init diff --git a/python/capture-thermometer-data.py b/python/capture-thermometer-data.py new file mode 100644 index 0000000..bca7d2c --- /dev/null +++ b/python/capture-thermometer-data.py @@ -0,0 +1,37 @@ +import asyncio +import json +from datetime import datetime +from bleak import BleakScanner + +async def handle_discovery(device, advertisement_data): + if device.address == "DB:17:6C:7D:81:F6": + keys = list(advertisement_data.manufacturer_data.keys()) + humKey = keys[len(keys)-1] + battery = humKey & 0xFF + temperature = (humKey >> 8)/10.0 + if humKey < 32767: #If Key is bigger than a smallint, temperature is lower than one byte (256) + temperature = temperature + 25.6 + + data = {} + data['temp'] = temperature + data['battery'] = battery / 256.0; + data['humid'] = advertisement_data.manufacturer_data[humKey][1] + data['timestamp'] = datetime.now().strftime("%d.%m.%Y %H:%M:%S") + + jsonString = json.dumps(data) + with open("/home/flo/local-weedkeeper/systems/backend/weedkeeper/var/temperature.data", "a") as dataFile: + dataFile.write(jsonString+",\n") + #print(jsonString) + await scanner.stop() + +async def scan(): + global scanner + scanner = BleakScanner(handle_discovery) + await scanner.start() + await asyncio.sleep(10) + await scanner.stop() + +async def main(): + await scan() + +asyncio.run(main()) diff --git a/stop b/stop new file mode 100755 index 0000000..82d3ba7 --- /dev/null +++ b/stop @@ -0,0 +1,4 @@ +#!/bin/bash + +./bin/script/exec stop +./bin/script/foreachSystem stop diff --git a/systems/.gitignore b/systems/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/systems/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/up b/up new file mode 100755 index 0000000..7f3abc8 --- /dev/null +++ b/up @@ -0,0 +1,4 @@ +#!/bin/bash + +./bin/script/exec up -d +./bin/script/foreachSystem up