update init_scripts

This commit is contained in:
Roger Pàmies Fabra 2023-01-25 00:21:59 +01:00
parent df3b7447e6
commit 1e95f868b0
2 changed files with 58 additions and 11 deletions

View File

@ -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_GOTIFY_APP>/$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

View File

@ -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="<TOKEN_GOTIFY_APP>"