add remote updater and improve init scripts
This commit is contained in:
parent
1e95f868b0
commit
cccc81172f
|
@ -1,5 +1,37 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
readonly SCRIPTS_FOLDER="e7scripts"
|
readonly SCRIPTS_FOLDER="e7scripts"
|
||||||
readonly GOTIFY_SCRIPT_NAME="gotifypush.sh"
|
readonly GOTIFY_SCRIPT_NAME="gotifypush.sh"
|
||||||
readonly GOTIFY_SCRIPT_URL="https://git.studi7.com/roger/bashscripts/raw/branch/master/gotifypush.sh"
|
readonly GOTIFY_SCRIPT_URL="https://git.studi7.com/roger/bashscripts/raw/branch/master/gotifypush.sh"
|
||||||
|
@ -12,6 +44,11 @@ if [[ $EUID -ne 0 ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#set -f
|
||||||
|
#func_result="$(get_cron)"
|
||||||
|
#echo $func_result
|
||||||
|
#set +f
|
||||||
|
|
||||||
echo "/////////////////////////////////////"
|
echo "/////////////////////////////////////"
|
||||||
echo "Benvingut a l'instalador d'Scripts"
|
echo "Benvingut a l'instalador d'Scripts"
|
||||||
echo -e "/////////////////////////////////////\n"
|
echo -e "/////////////////////////////////////\n"
|
||||||
|
@ -56,11 +93,14 @@ elif [ "$SCRIPT_NUM" = "2" ];then
|
||||||
sed -i "s/<TOKEN_GOTIFY_APP>/$TOKEN/" "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME"
|
sed -i "s/<TOKEN_GOTIFY_APP>/$TOKEN/" "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME"
|
||||||
sed -i "s/Hostname/$(hostname)/" "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME"
|
sed -i "s/Hostname/$(hostname)/" "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME"
|
||||||
chmod +x "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME"
|
chmod +x "$SCRIPTS_FOLDER/$UPDATES_SCRIPT_NAME"
|
||||||
|
echo -e "\nAFEGEIX EL CRON\n"
|
||||||
|
show_cron_help
|
||||||
|
cron="$(get_cron)"
|
||||||
#https://stackoverflow.com/questions/878600/how-to-create-a-cron-job-using-bash-automatically-without-the-interactive-editor
|
#https://stackoverflow.com/questions/878600/how-to-create-a-cron-job-using-bash-automatically-without-the-interactive-editor
|
||||||
#remove previous crontab
|
#remove previous crontab
|
||||||
(crontab -l | grep -v -F "$UPDATES_SCRIPT_NAME") | crontab -
|
(crontab -l | grep -v -F "$UPDATES_SCRIPT_NAME") | crontab -
|
||||||
#add crontab
|
#add crontab
|
||||||
(crontab -l ; echo "05 10 * * * cd $(pwd)/$SCRIPTS_FOLDER/ && ./$UPDATES_SCRIPT_NAME 2>&1") | crontab -
|
(crontab -l ; echo "$cron cd $(pwd)/$SCRIPTS_FOLDER/ && ./$UPDATES_SCRIPT_NAME 2>&1") | crontab -
|
||||||
echo -e "Script instal·lat correctament\n"
|
echo -e "Script instal·lat correctament\n"
|
||||||
#TODO Function cron get period
|
#TODO Function cron get period
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#verify run as root or sudo
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
echo "This script must be run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat .ssh/config | grep -E "^Host [^\*\*]" | sed "s/Host //"
|
||||||
|
|
Loading…
Reference in New Issue