-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptmanager
executable file
·51 lines (37 loc) · 1.1 KB
/
scriptmanager
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
50
51
#!/bin/bash
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ $1 == '--load' ]] ; then
if [ "$EUID" -ne 0 ] ; then
echo "Please run --load command as root"
exit
fi
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d : -f 6)
file_path="$USER_HOME/.bashrc"
echo "add scripts to PATH in $file_path"
cat >> $file_path <<- EOM
export PATH="$script_dir:\$PATH" # add my-script-manager scripts
EOM
exit 1
fi
if [[ $1 == '--sync' ]] ; then
echo "sync scripts..."
cd $script_dir
git pull
exit 1
fi
if [[ $1 == '--cron' ]] ; then
echo "add my-script-manager --sync cronjob..."
croncmd="$script_dir/scriptmanager --sync > $script_dir/sync-log.out 2>&1"
cronjob="*/5 * * * * $croncmd" # each 5 minutes
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
exit 1
fi
echo "Script Manager v0.1
Usage:
scriptmanager [COMMAND]
Commands:
--sync: pull from origin and sync scripts
--load: init my-script-manager and add scripts to PATH (use .profile)
--cron: add cronjob to --sync each 5 minutes
--help: show this message
"