diff --git a/setup-debian.sh b/setup-debian.sh index b5ace9f3514fec67c0f996ac8d4324cc11891b2f..c5eb3267a340c69cba2f07fd6d547e884031371c 100755 --- a/setup-debian.sh +++ b/setup-debian.sh @@ -1,6 +1,8 @@ #!/bin/bash echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] Starting setup..." +echo -e "\nStorage profile:\n$(df -h)" +echo -e "\nDocker profile:\n$(sudo docker system df)" FORCE="$1" @@ -121,6 +123,7 @@ ensure_dependencies # Variables PROJECT_PATH="/home/admin/shepherd-enterprise" +GIT_BRANCH="main" ENV_SHEPHERD_PATH="$PROJECT_PATH/.env.shepherd" ENV_CLIENT_PATH="$PROJECT_PATH/.env.client" @@ -135,6 +138,8 @@ CADDYFILE_PATH="$PROJECT_PATH/Caddyfile" GRAFANADATA_PATH="$PROJECT_PATH/grafanadata" LOKIDATA_PATH="$PROJECT_PATH/lokidata" +GIT_PATH="$PROJECT_PATH/.git" + SCRIPT_PATH="$PROJECT_PATH/setup-debian.sh" SCRIPT_LOG_PATH="$PROJECT_PATH/cron-logs/setup-debian-cron.log" CRON_JOB="0 0 * * * $SCRIPT_PATH >> $SCRIPT_LOG_PATH 2>&1" @@ -157,6 +162,41 @@ VIMACOG_HARD_GEN_EXISTS=$(crontab -l | grep -F "$VIMACOG_HARD_GEN_PATH" | grep - VIMACOG_HARD_GEN_LOG_DIR="$PROJECT_PATH/vimacog/hard-gen-logs/" VIMACOG_HARD_GEN_BACKUP_DIR="$PROJECT_PATH/vimacog/hard-gen-backup/" +# Note: Cleanup temporary storgae +cleanup_git() { + echo "Initiating git cleanup..." + cd "$PROJECT_PATH" || exit + sudo du -hc $GIT_PATH + sudo git reflog expire --expire=now --expire-unreachable=now --all + sudo git prune --dry-run --verbose --expire=now + echo "Git cleanup complete." + sudo du -hc $GIT_PATH +} + +# NOTE: To be removed after one run +cleanup_loki() { + echo "Initiating loki logs cleanup..." + sudo du -hc $LOKIDATA_PATH + sudo rm -rf $LOKIDATA_PATH/* + echo "Loki logs cleanup complete." + sudo du -hc $LOKIDATA_PATH +} + +# NOTE: To be removed after one run +cleanup_docker() { + echo "Initiating docker cleanup..." + cd "$PROJECT_PATH" || exit + sudo docker system df + sudo docker compose down + sudo docker system prune -af --volumes + echo "Docker cleanup complete." + sudo docker system df +} + +cleanup_git +cleanup_loki +cleanup_docker + # Check for Git updates & pull if updates are available # Returns whether to hard run or soft run # Note: Runs always @@ -164,12 +204,12 @@ setup_git() { echo "Checking for git updates..." cd "$PROJECT_PATH" || exit # git config pull.rebase true - sudo git fetch origin main + sudo git fetch -fpPv origin $GIT_BRANCH if [ "$(git rev-parse HEAD)" != "$(git rev-parse FETCH_HEAD)" ]; then # Ignore all local changes(comitted & non-comitted) - sudo git reset --hard origin/main - # TODO: Change this to main branch - sudo git pull origin main --force + sudo git reset --hard origin/$GIT_BRANCH + # TODO: Change this to $GIT_BRANCH branch + sudo git pull -fpv origin $GIT_BRANCH echo "Repository updated. Applying updates..." # Ensure the scripts are executable after a potential update sudo chmod +x "$SCRIPT_PATH" @@ -337,7 +377,7 @@ setup_docker() { if [ "$force_update" = true ]; then echo "Force updating images..." sudo docker compose down - sudo docker system prune -af + sudo docker system prune -af --volumes sudo docker compose pull sudo docker compose --env-file ./.env up -d else @@ -383,5 +423,7 @@ setup_caddy $FORCE setup_docker $FORCE setup_vimacog +echo -e "\nStorage profile:\n$(df -h)" +echo -e "\nDocker profile:\n$(sudo docker system df)" echo "Setup complete." exit 0