#!/bin/bash

# Ścieżka do pliku logu
LOGFILE="/var/log/apt_update_upgrade.log"

# Aktualny czas
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")

# Funkcja logująca
log() {
    echo "$TIMESTAMP - $1" | tee -a $LOGFILE
}

# Logowanie daty i godziny uruchomienia skryptu
log "Script started"

# Wykonywanie apt-get update i zapis do logu
log "Starting apt-get update"
if apt-get update >> $LOGFILE 2>&1; then
    log "apt-get update completed successfully"
else
    log "apt-get update failed"
    exit 1
fi

# Wykonywanie apt-get upgrade i zapis do logu
log "Starting apt-get upgrade"
if apt-get upgrade -y >> $LOGFILE 2>&1; then
    log "apt-get upgrade completed successfully"
else
    log "apt-get upgrade failed"
    exit 1
fi

log "Update and upgrade process completed"