From 1e95f868b0f1f8b1f22e345d0f883470cda03d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20P=C3=A0mies?= Date: Wed, 25 Jan 2023 00:21:59 +0100 Subject: [PATCH] update init_scripts --- init_scripts.sh | 63 +++++++++++++++++++++++++++++++++++++-------- updates_notifier.sh | 6 +++++ 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/init_scripts.sh b/init_scripts.sh index 987690e..44eaefe 100644 --- a/init_scripts.sh +++ b/init_scripts.sh @@ -1,5 +1,11 @@ #!/bin/bash +readonly SCRIPTS_FOLDER="e7scripts" +readonly GOTIFY_SCRIPT_NAME="gotifypush.sh" +readonly GOTIFY_SCRIPT_URL="https://git.studi7.com/roger/bashscripts/raw/branch/master/gotifypush.sh" +readonly UPDATES_SCRIPT_NAME="updates_notifier.sh" +readonly UPDATES_SCRIPT_URL="https://git.studi7.com/roger/bashscripts/raw/branch/master/updates_notifier.sh" + #verify run as root or sudo if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" @@ -8,23 +14,58 @@ fi echo "/////////////////////////////////////" echo "Benvingut a l'instalador d'Scripts" -echo "/////////////////////////////////////" - -# Choose script to install -echo "0) Sortir de l'instalador" -echo "1) Notificador d'actualitzacions" -echo "2) Escaneig de rootkits amb RK Hunter" -echo "3) Escaneig de rootkits amb CHK Rootkit" -echo "4) Escaneig de virus amb ClamAV" +echo -e "/////////////////////////////////////\n" finished=false while [ "$finished" != "true" ] do - read -p 'Indica quin script vols instal·lar: ' SCRIPT_NUM + +# Choose script to install +echo "0) Sortir de l'instalador" +echo "1) Notificador dels resultats dels scripts (Gotify Push Notifications)" +echo "2) Notificador d'actualitzacions" +echo "3) Escaneig de rootkits amb RK Hunter" +echo "4) Escaneig de rootkits amb CHK Rootkit" +echo -e "5) Escaneig de virus amb ClamAV\n" + +choosed=false +while [ "$choosed" != "true" ] +do + read -p 'Indica quin script vols instal·lar (0 per sortir): ' SCRIPT_NUM case $SCRIPT_NUM in ("") echo "El número no pot ser buit";; (*[!0-9]*) echo "Has d'introduir un número";; - (*[5-9]*) echo "Aquest número d'script no existeix";; - (*) finished=true #echo "just numeric";; + (*) choosed=true #echo "just numeric";; esac done + +if [ "$SCRIPT_NUM" = "0" ]; then + finished=true + exit 0 +elif [ "$SCRIPT_NUM" = "1" ]; then + mkdir -p $SCRIPTS_FOLDER + wget -O "$SCRIPTS_FOLDER/$GOTIFY_SCRIPT_NAME" $GOTIFY_SCRIPT_URL + read -p 'Indica el domini de gotify: ' GOTIFY_DOMAIN + sed -i "s/push.example.com/$GOTIFY_DOMAIN/" "$SCRIPTS_FOLDER/$GOTIFY_SCRIPT_NAME" + chmod +x "$SCRIPTS_FOLDER/$GOTIFY_SCRIPT_NAME" + echo -e "Script instal·lat correctament\n" +elif [ "$SCRIPT_NUM" = "2" ];then + mkdir -p $SCRIPTS_FOLDER + wget -O "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME" $UPDATES_SCRIPT_URL + read -p 'Indica el token del canal de gotify: ' TOKEN + sed -i "s//$TOKEN/" "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME" + sed -i "s/Hostname/$(hostname)/" "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME" + chmod +x "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME" + #https://stackoverflow.com/questions/878600/how-to-create-a-cron-job-using-bash-automatically-without-the-interactive-editor + #remove previous crontab + (crontab -l | grep -v -F "$UPDATES_SCRIPT_NAME") | crontab - + #add crontab + (crontab -l ; echo "05 10 * * * cd $(pwd)/$SCRIPTS_FOLDER/ && ./$UPDATES_SCRIPT_NAME 2>&1") | crontab - + echo -e "Script instal·lat correctament\n" + #TODO Function cron get period + +else + echo -e "Aquest número d'script no existeix. Tornar a intentar-ho\n" +fi + +done diff --git a/updates_notifier.sh b/updates_notifier.sh index 90a9aa9..db562c1 100644 --- a/updates_notifier.sh +++ b/updates_notifier.sh @@ -2,6 +2,12 @@ PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin +#verify run as root or sudo +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + # vars gotify readonly TOKEN=""