updated install script with cron jobs
All checks were successful
Tests / Run Go Tests (push) Successful in 1m35s
All checks were successful
Tests / Run Go Tests (push) Successful in 1m35s
This commit is contained in:
82
install.sh
82
install.sh
@@ -4,6 +4,10 @@ set -e
|
||||
envFile=Docker/.env
|
||||
envExample=Docker/env.example
|
||||
|
||||
autoBackupScript=Cron/autoBackup.sh
|
||||
autoHolidaysScript=Cron/autoHolidays.sh
|
||||
autoLogoutScript=Cron/autoLogout.sh
|
||||
|
||||
echo "Checking Docker installation..."
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Docker not found. Install Docker? [y/N]"
|
||||
@@ -18,12 +22,16 @@ else
|
||||
echo "Docker is already installed."
|
||||
fi
|
||||
|
||||
###########################################################################
|
||||
|
||||
echo "Checking Docker Compose..."
|
||||
if ! docker compose version >/dev/null 2>&1; then
|
||||
echo "Docker Compose plugin missing. You may need to update Docker."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
###########################################################################
|
||||
|
||||
echo "Preparing .env file..."
|
||||
if [ ! -f $envFile ]; then
|
||||
if [ -f $envExample ]; then
|
||||
@@ -44,6 +52,9 @@ if [ ! -f $envFile ]; then
|
||||
raw_val=$(printf "%s" "$rest" | sed 's/ *#.*//')
|
||||
default_value=$(printf "%s" "$raw_val" | sed 's/"//g')
|
||||
|
||||
# Replace __ROOT__ with script pwd
|
||||
default_value="${default_value/__ROOT__/$(pwd)}"
|
||||
|
||||
regex=""
|
||||
if [[ "$comment" =~ regex:(.*)$ ]]; then
|
||||
regex="${BASH_REMATCH[1]}"
|
||||
@@ -96,13 +107,80 @@ else
|
||||
echo "Using existing .env. (found at $envFile)"
|
||||
fi
|
||||
|
||||
###########################################################################
|
||||
|
||||
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
|
||||
read -r start_containersmkdi
|
||||
if [[ "$start_containers" =~ ^[Yy]$ ]]; then
|
||||
|
||||
cd Docker
|
||||
mkdir ../logs
|
||||
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
|
||||
if [[ "$setup_cron" =~ ^[Yy]$ ]]; then
|
||||
WEB_PORT=$(grep -E '^WEB_PORT=' $envFile | cut -d= -f2)
|
||||
if [ -z "$WEB_PORT" ]; then
|
||||
echo "WEB_PORT not found in .env using default 8000"
|
||||
WEB_PORT=8000
|
||||
fi
|
||||
|
||||
POSTGRES_DB=$(grep -E '^POSTGRES_DB=' $envFile | cut -d= -f2)
|
||||
if [ -z "$POSTGRES_DB" ]; then
|
||||
echo "arbeitszeitmessung not found in .env using default arbeitszeitmessung"
|
||||
POSTGRES_DB="arbeitszeitmessung"
|
||||
fi
|
||||
|
||||
sed -i "s/__PORT__/$WEB_PORT/" $autoHolidaysScript
|
||||
sed -i "s/__PORT__/$WEB_PORT/" $autoLogoutScript
|
||||
sed -i "s/__DATABASE__/$POSTGRES_DB/" $autoBackupScript
|
||||
|
||||
chmod +x $autoBackupScript $autoHolidaysScript $autoLogoutScript
|
||||
|
||||
# echo "Scripts build with PORT=$WEB_PORT and DATABSE=$POSTGRES_DB!"
|
||||
echo "Adding rules to crontab."
|
||||
|
||||
cron_commands=$(mktemp /tmp/arbeitszeitmessung-cron.XXX)
|
||||
|
||||
for file in Cron/*; do
|
||||
cron_timing=$(grep -E '^# cron-timing:' "$file" | sed 's/^# cron-timing:[[:space:]]*//')
|
||||
|
||||
if [ -z "$cron_timing" ]; then
|
||||
echo "No cron-timing found in $file, so it's not added to crontab."
|
||||
continue
|
||||
fi
|
||||
|
||||
( crontab -l ; echo "$cron_timing $(pwd)/$file" )| awk '!x[$0]++' | crontab -
|
||||
echo "Added entry to crontab: $cron_timing $(pwd)/$file."
|
||||
done
|
||||
|
||||
if systemctl is-active --quiet cron.service ; then
|
||||
echo "cron.service is running. Everything should be fine now."
|
||||
else
|
||||
echo "cron.service is not running. Please start and enable cron.service."
|
||||
echo "For how to start a service, see: https://wiki.ubuntuusers.de/systemd/systemctl UNITNAME will be cron.service"
|
||||
fi
|
||||
|
||||
else
|
||||
echo "Please setup cron manually by executing crontab -e and adding all files from inside the Cron directory!"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user