-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_cron_self_update.sh
executable file
·50 lines (36 loc) · 1.27 KB
/
install_cron_self_update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
ATOMIQUE_ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
echo "Starting install from $ATOMIQUE_ROOT_DIR"
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
elif [ "$unamestr" = 'FreeBSD' ]; then
platform='freebsd'
else
echo "Unsupported platform: $unamestr. Aborting script."
exit 1
fi
#-----------------------
LOCALUSER=$(whoami)
DEST_CRON_UPD=/etc/cron.d/atomique_shell_cron_update_entry
echo "-------------------------------------"
echo " ⏰ ADDIN CRON UPDATE for git pull"
echo " dest path: $DEST_CRON_UPD"
echo "------------------------------------"
#THIS MUST RUN AS normal user (usually 'pi' but it can be root on DietPI)
sudo cp -f "$ATOMIQUE_ROOT_DIR/atomique_shell_cron_update_entry" $DEST_CRON_UPD
SEDOPTION="-i"
if [[ "$OSTYPE" == "darwin"* ]]; then
SEDOPTION="-i ''"
fi
#Replace the path of script and the user
#We use : and not / as separator so we don't have to escape slashes in path
sudo sed $SEDOPTION -e "s:REPLACEMEPATH:$ATOMIQUE_ROOT_DIR:g" "$DEST_CRON_UPD"
sudo sed $SEDOPTION -e "s:REPLACEMEUSER:$LOCALUSER:g" "$DEST_CRON_UPD"
#-----------------------
echo
echo ---------------
echo contents of $DEST_CRON_UPD :
echo ---------------
cat $DEST_CRON_UPD