#!/bin/bash

# Set the log file path
LOG_FILE="/root/Client/log/CM_updater_log.txt"

# Function to append the timestamp to each log entry
log () {
    TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
    echo "$TIMESTAMP $1" | tee -a "$LOG_FILE"
}

log "cronjob - Stopping Client Service"
sudo systemctl stop Client.service
sleep 5

log "cronjob - Upgrading Client"
unzip -o Client.zip

log "cronjob - Starting Client Service"
sudo systemctl start Client.service

log "cronjob - Cleanup Client zip"
rm -rf $HOME/Client.zip

log "cronjob - apply user rights to debian"
sudo chown debian:debian /root/Client/*
sudo chmod 700 /root/Client/*

log "cronjob - terminate"

(crontab -l | grep -v 'upgrader_cron') | crontab -


