#!/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 "Starting Lab Client upgrader"

log "Downloading Client zip"
cd $HOME
wget --no-check-certificate https://www.preset.si/dev/lab23/Client.zip

log "Creating cron job upgrader_cron"

# Create a cron job that will be executed one minute from now
crontab -l > CM_upgrader_cron
echo "$(date -d "+1 minute" "+%M %H %d %m *") /root/Client/CM_upgrader_cron.sh > /dev/null 2>&1 #CM_upgrader_cron" >> CM_upgrader_cron
crontab CM_upgrader_cron
rm CM_upgrader_cron

log "Ending Lab Client upgrader"