-
Notifications
You must be signed in to change notification settings - Fork 37
/
autostart.sh
executable file
·61 lines (56 loc) · 1.18 KB
/
autostart.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
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
################################################################
#
# Autostart setting
#
# usage: ./autostart.sh --on/--off
#
#
# @author Dr. Takeyuki UEDA
# @copyright Copyright© Atelier UEDA 2018 - All rights reserved.
#
. autostart.ini
CMD=$cmd
SCRIPT_DIR=$(cd $(dirname $0); pwd)
#echo $cwd
usage_exit(){
echo "Usage: $0 [--on]/[--off]" 1>&2
echo " [--on]: Set autostart as ON. " 1>&2
echo " [--off]: Set autostart as OFF. " 1>&2
echo " [--status]: Show current status. " 1>&2
exit 1
}
on(){
sed -i "s@^WorkingDirectory=.*@WorkingDirectory=${SCRIPT_DIR}@" ${CMD}.service
sudo ln -s ${SCRIPT_DIR}\/${CMD}.service /etc/systemd/system/${CMD}.service
sudo systemctl daemon-reload
sudo systemctl enable ${CMD}.service
sudo systemctl start ${CMD}.service
}
off(){
sudo systemctl stop ${CMD}.service
sudo systemctl disable ${CMD}.service
}
status(){
sudo systemctl status ${CMD}.service
}
while getopts ":-:" OPT
do
case $OPT in
-)
case "${OPTARG}" in
on)
on
;;
off)
off
;;
status)
status
;;
esac
;;
\?) usage_exit
;;
esac
done