2023-01-22 23:58:40 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-01-26 23:01:56 +01:00
|
|
|
# Functions
|
|
|
|
show_cron_help () {
|
|
|
|
echo "--------------------------------------------"
|
|
|
|
echo "* * * * * command to be executed"
|
|
|
|
echo "- - - - -"
|
|
|
|
echo "| | | | |"
|
|
|
|
echo "| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)"
|
|
|
|
echo "| | | ------- Month (1 - 12)"
|
|
|
|
echo "| | --------- Day of month (1 - 31)"
|
|
|
|
echo "| ----------- Hour (0 - 23)"
|
|
|
|
echo "------------- Minute (0 - 59)"
|
|
|
|
echo "Examples:"
|
|
|
|
echo "(predefined) @annually | @yearly | @monthly | @weekly | @daily | @hourly | @reboot"
|
|
|
|
echo "(every) @every 5s | @every 20h30m"
|
|
|
|
echo "(custom) 10 20 * * * | 0 3 * * 1-5"
|
|
|
|
echo -e "--------------------------------------------\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
get_cron () {
|
|
|
|
cron=false
|
|
|
|
while [ "$cron" != "true" ]
|
|
|
|
do
|
|
|
|
read -p 'Escriu el periode del cron: ' CRON
|
|
|
|
case $CRON in
|
|
|
|
("") echo "El cron no pot ser buit";;
|
|
|
|
(*) cron=true #echo "just numeric";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
echo "$CRON"
|
|
|
|
}
|
|
|
|
# End functions
|
|
|
|
|
2023-01-25 00:21:59 +01:00
|
|
|
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"
|
|
|
|
|
2023-01-22 23:58:40 +01:00
|
|
|
#verify run as root or sudo
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "This script must be run as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-01-26 23:01:56 +01:00
|
|
|
#set -f
|
|
|
|
#func_result="$(get_cron)"
|
|
|
|
#echo $func_result
|
|
|
|
#set +f
|
|
|
|
|
2023-01-27 15:36:13 +01:00
|
|
|
echo "/////////////////////////////////////////"
|
2023-01-22 23:58:40 +01:00
|
|
|
echo "Benvingut a l'instalador d'Scripts"
|
2023-01-25 00:21:59 +01:00
|
|
|
echo -e "/////////////////////////////////////\n"
|
|
|
|
|
|
|
|
finished=false
|
|
|
|
while [ "$finished" != "true" ]
|
|
|
|
do
|
2023-01-22 23:58:40 +01:00
|
|
|
|
|
|
|
# Choose script to install
|
|
|
|
echo "0) Sortir de l'instalador"
|
2023-01-25 00:21:59 +01:00
|
|
|
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"
|
2023-01-22 23:58:40 +01:00
|
|
|
|
2023-01-25 00:21:59 +01:00
|
|
|
choosed=false
|
|
|
|
while [ "$choosed" != "true" ]
|
2023-01-22 23:58:40 +01:00
|
|
|
do
|
2023-01-25 00:21:59 +01:00
|
|
|
read -p 'Indica quin script vols instal·lar (0 per sortir): ' SCRIPT_NUM
|
2023-01-22 23:58:40 +01:00
|
|
|
case $SCRIPT_NUM in
|
|
|
|
("") echo "El número no pot ser buit";;
|
|
|
|
(*[!0-9]*) echo "Has d'introduir un número";;
|
2023-01-25 00:21:59 +01:00
|
|
|
(*) choosed=true #echo "just numeric";;
|
2023-01-22 23:58:40 +01:00
|
|
|
esac
|
|
|
|
done
|
2023-01-25 00:21:59 +01:00
|
|
|
|
|
|
|
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"
|
2023-01-26 23:01:56 +01:00
|
|
|
echo -e "\nAFEGEIX EL CRON\n"
|
|
|
|
show_cron_help
|
|
|
|
cron="$(get_cron)"
|
2023-01-25 00:21:59 +01:00
|
|
|
#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
|
2023-01-26 23:01:56 +01:00
|
|
|
(crontab -l ; echo "$cron cd $(pwd)/$SCRIPTS_FOLDER/ && ./$UPDATES_SCRIPT_NAME 2>&1") | crontab -
|
2023-01-25 00:21:59 +01:00
|
|
|
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
|