-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.bash
More file actions
95 lines (65 loc) · 2.02 KB
/
Copy pathinstall.bash
File metadata and controls
95 lines (65 loc) · 2.02 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# How to execute (Install)
# sudo bash ./install.bash install
# How to execute (Uninstall)
# sudo bash ./install.bash uninstall
## PACKAGE DIRS
SCRIPT_DIR=$(cd $(dirname $0); pwd)
_USER=${SCRIPT_DIR##*home/}
USER=${_USER%%/*}
BASE_NAME=$(basename $SCRIPT_DIR)
## INSTALL DIRS
INSTALL_DIR='/usr/local'
BIN='/usr/local/bin'
SYSTEM='/etc/systemd/system'
## Check superuser ======================================
if [ $(id -u) -ne 0 ]; then
## ERROR MESSAGE
echo "You must execute this command as a superuser."
echo "'sudo bash ./install.bash install' or 'sudo bash ./install.bash uninstall'"
exit 1
fi
# if [ $# -ne 1 ]; then
## UNINSTALL =============================================
if [ "uninstall" = $1 ]; then
echo "uninstall ..."
for service_file in $INSTALL_DIR/$BASE_NAME/scripts/*.service ; do
## SETTING SERVICE BASE NAME
FILE=`basename $service_file`
## DISPLAY UNINSTALL MESSAGE
echo "uninstall" $FILE"..."
## REMOVE SERVICE
systemctl stop $FILE
systemctl disable $FILE
rm $SYSTEM/$FILE
done
## RELOAD SYSTEMD
systemctl daemon-reload
## REMOVE FOLDERS
rm -rf $INSTALL_DIR/$BASE_NAME
echo "uninstalled"
exit 0
## INSTALL =============================================
elif [ "install" = $1 ]; then
## COPY FILES
cp -r $SCRIPT_DIR/ $INSTALL_DIR/$BASE_NAME
for service_file in $INSTALL_DIR/$BASE_NAME/scripts/*.service ; do
## SETTING SERVICE BASE NAME
FILE=`basename $service_file`
## DISPLAY INSTALL MESSAGE
echo "setting "$FILE"..."
## SETTING SERVICE
cp $service_file $SYSTEM/
echo "User=$USER" >> $SYSTEM/$FILE
systemctl enable $FILE
done
## RELOAD SYSTEMD
systemctl daemon-reload
echo "installed"
exit 0
## ERROR =============================================
else
## ERROR MESSAGE
echo "options failed ('sudo bash ./install.bash install' or 'sudo bash ./install.bash uninstall')"
exit 1
fi