#!/bin/sh #AutoUpdate--V1.1 host=$(hostname) date=$(date +"%T") fail="Update Fail" success="Update Success" suc_reboot="Update Success and just rebooted" facility="Linux Server" red=$(tput setaf 1) green=$(tput setaf 2) yellow=$(tput setaf 3) sgr=$(tput sgr 0) json_fail='{"version": "1.1","host":"'$host'","facility":"'$facility'","short_message":"Raspberry wrong update","full_message":"The Ubuntu '$facility' was fail check '$host'","level":1,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}' json_success='{"version": "1.1","host":"'$host'","facility":"'$facility'","short_message":"Raspberry success update","full_message":"The Ubuntu '$facility' success","level":6,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}' json_suc_reboot='{"version": "1.1","host":"'$host'","facility":"'$facility'","short_message":"Raspberry updated and start reboot","full_message":"The Ubuntu '$facility' success '$host' start reboot","level":6,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}' echo "${yellow}! AutoUpdate start !${sgr}" apt update apt -y dist-upgrade if [[ $? > 0 ]]; then echo "${red}Wrong update${sgr}" && echo "${date} - ${fail}" > ./pal.log && echo $json_fail | gzip | nc -u -w 1 palgraylog01.pal.local 12201 notify-send "Se il dispositivo presenta problemi contattare il CED" exit else echo "${green}Don't worry about your device is updating${sgr}" fi apt -y autoremove apt clean apt purge -y $(dpkg -l | awk '/^rc/ { print $2 }') echo "${green}! Update completed !${sgr}" if [ ! -f /var/run/reboot-required ]; then # no reboot required (0=OK) echo "${green}Good: no reboot required${sgr}" && echo "${date} - ${success}" > ../pal.log && echo $json_success | gzip | nc -u -w 1 palgraylog01.pal.local 12201 notify-send "Aggiornamento eseguito con successo" exit 0 else # reboot required (1=WARN) echo "${red}WARNING: ${yellow}`cat /var/run/reboot-required`${sgr}" && echo "${date} - ${suc_reboot}" > ../pal.log && echo $json_suc_reboot | gzip | nc -u -w 1 palgraylog01.pal.local 12201 notify-send "Aggiornamento eseguito con successo il dispositivo si riavvia a breve" v reboot now exit 1 fi