fix: install script

added dynamic backup folder (fixed #79)
changed if statements
This commit is contained in:
2026-02-15 16:07:34 +01:00
parent 46218f9bca
commit 1d7b563a6d
3 changed files with 29 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
# cron-timing: 05 01 * * 1
container_name="arbeitszeitmessung-main-db-1"
filename=backup-$(date '+%d%m%Y').sql
backup_folder=__BACKUP_FOLDER__
database_name=__DATABASE__
docker exec $container_name pg_dump $database_name > /home/pi/arbeitszeitmessung-backup/$filename
docker exec $container_name pg_dump $database_name > $backup_folder/$filename
echo "created backup file: "$filename

View File

@@ -4,9 +4,10 @@ POSTGRES_API_USER=api_nutzer # Postgres API Nutzername (f
POSTGRES_API_PASS=password # Postgres API Passwort (für Arbeitszeitmessung)
POSTGRES_PATH=__ROOT__/DB # Datebank Pfad (relativ zu Docker Ordner oder absoluter pfad mit /...)
POSTGRES_DB=arbeitszeitmessung # Postgres Datenbank Name
POSTGRES_PORT=127.0.0.1:5432 # Postgres Port normalerweise nicht freigegeben. regex:^[0-9]{1,5}$
POSTGRES_PORT=5432 # Postgres Port normalerweise nicht freigegeben. regex:^[0-9]{1,5}$
TZ=Europe/Berlin # Zeitzone
API_TOKEN=dont_access # API Token für ESP Endpoints
WEB_PORT=8000 # Port unter welchem Webserver erreichbar ist. regex:^[0-9]{1,5}$
LOG_PATH=__ROOT__/logs # Pfad für Audit Logs
LOG_LEVEL=warn # Welche Log-Nachrichten werden in der Konsole erscheinen
BACKUP_FOLDER=__ROOT__/backup # Pfad für DB Backup Datein

View File

@@ -64,9 +64,9 @@ if [ ! -f $envFile ]; then
while true; do
if [ -z "$comment" ]; then
printf "Value for $key - $comment (default: $default_value"
else
printf "Value for $key (default: $default_value"
else
printf "Value for $key - $comment (default: $default_value"
fi
if [ -n "$regex" ]; then
printf ", must match: %s" "$regex"
@@ -113,27 +113,12 @@ LOG_PATH=$(grep -E '^LOG_PATH=' $envFile | cut -d= -f2)
if [ -z "$LOG_PATH" ]; then
echo "LOG_PATH not found in .env using default $(pwd)/logs"
LOG_PATH=$(pwd)/logs
else
LOG_PATH=Docker/$LOG_PATH
fi
mkdir -p $LOG_PATH
echo "Created logs folder at $LOG_PATH"
###########################################################################
echo -e "\n\n"
echo "Start containers with docker compose up -d? [y/N]"
read -r start_containers
if [[ "$start_containers" =~ ^[Yy]$ ]]; then
cd Docker
docker compose up -d
echo "Containers started."
else
echo "You can start them manually with: docker compose up -d"
fi
###########################################################################
echo -e "\n\n"
echo "Setup Crontab for automatic logout, backup and holiday creation? [y/N]"
read -r setup_cron
@@ -146,13 +131,20 @@ if [[ "$setup_cron" =~ ^[Yy]$ ]]; then
POSTGRES_DB=$(grep -E '^POSTGRES_DB=' $envFile | cut -d= -f2)
if [ -z "$POSTGRES_DB" ]; then
echo "arbeitszeitmessung not found in .env using default arbeitszeitmessung"
echo "POSTGRES_DB not found in .env using default arbeitszeitmessung"
POSTGRES_DB="arbeitszeitmessung"
fi
BACKUP_FOLDER=$(grep -E '^BACKUP_FOLDER=' $envFile | cut -d= -f2)
if [ -z "$BACKUP_FOLDER" ]; then
echo "BACKUP_FOLDER not found in .env using default $(pwd)/backup"
BACKUP_FOLDER="$(pwd)/backup"
fi
sed -i "s/__PORT__/$WEB_PORT/" $autoHolidaysScript
sed -i "s/__PORT__/$WEB_PORT/" $autoLogoutScript
sed -i "s/__DATABASE__/$POSTGRES_DB/" $autoBackupScript
sed -i "s/__BACKUP_FOLDER__/$BACKUP_FOLDER" $autoBackupScript
chmod +x $autoBackupScript $autoHolidaysScript $autoLogoutScript
@@ -184,3 +176,18 @@ if [[ "$setup_cron" =~ ^[Yy]$ ]]; then
else
echo "Please setup cron manually by executing crontab -e and adding all files from inside the Cron directory!"
fi
###########################################################################
echo -e "\n\n"
echo "Start containers with docker compose up -d? [y/N]"
read -r start_containers
if [[ "$start_containers" =~ ^[Yy]$ ]]; then
cd Docker
docker compose up -d
echo "Containers started."
else
echo "You can start them manually with: docker compose up -d"
fi
echo "Installation finished, you can re-run the script any time!"