-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·148 lines (129 loc) · 2.62 KB
/
install.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#sudo apt install python3 python3-pip python3-dev -y && python3 -m pip install -r requirements.txt
#python3 -m pip install -U pip wheel setuptools
LOCK_FILE=/tmp/lock-gimxwebapi-install.lock
SERVICE_NAME=gimx-web.service
SERVICE_PATH=/etc/systemd/system/$SERVICE_NAME
PORT=51916
V=`cat version.txt`
ARCH=`dpkg --print-architecture`
function usage() {
printf "Usage:\
\t$0
\t$0 --help
\t$0 --uninstall
\t$0 [-p <PORT>] [--install-dir <DIRECTORY>] [--dont-install-gimx] [--mod <MOD>]\n"
}
function quit() {
rm $LOCK_FILE
exit $1
}
if [ "$#" -eq 1 ]; then
if [ "$1" == "--help" ]; then
usage
exit
fi
fi
if [ -f "$LOCK_FILE" ]; then
echo "$LOCK_FILE exists"
exit 2
fi
touch $LOCK_FILE
if [ "$#" -eq 1 ]; then
if [ "$1" == "--uninstall" ]; then
echo "Uninstalling..."
if [ -f $SERVICE_PATH ]; then
systemctl stop $SERVICE_NAME
systemctl disable $SERVICE_NAME
rm $SERVICE_PATH
fi
quit 0
fi
fi
INSTALL_DIR=""
INSTALL_GIMX=y
MOD=""
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--port)
PORT="$2"
shift # past argument
shift # past value
;;
--install-dir)
INSTALL_DIR="$2/$V"
shift # past argument
shift # past value
;;
--dont-install-gimx)
INSTALL_GIMX=n
shift
;;
--mod)
MOD=$2
shift
shift
;;
*) # unknown option
echo "Invalid option: $1"
quit 1
;;
esac
done
if [ -z "$INSTALL_DIR" ]; then
INSTALL_DIR="`pwd`"
EXEC_DIR="$INSTALL_DIR/src"
else
mkdir -p "$INSTALL_DIR"
EXEC_DIR="`realpath $INSTALL_DIR`/src"
if ! cp -r src auto_updater version.txt $INSTALL_DIR/.; then
quit 3
fi
fi
mkdir -p "$INSTALL_DIR/log"
echo "EXEC_DIR: $EXEC_DIR"
SERVICE_CONTENT="\
[Unit]
Description=GIMX Web Service
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$EXEC_DIR
ExecStart=/usr/bin/env python3 webAPI.py -p $PORT
[Install]
WantedBy=multi-user.target"
if systemctl is-active --quiet $SERVICE_NAME; then
sleep 2
fi
if [ "$INSTALL_GIMX" = "y" ]; then
curV=`gimx --version | cut -d" " -f2`
for f in build/gimx*$ARCH*$MOD*.deb; do
if [ -e "$f" ]; then
newV=`echo "$f" | cut -d"_" -f2 | cut -d"-" -f1`
if [ "$curV" = "$newV" ]; then
echo "GIMX $curV already installed."
break
else
#systemctl stop $SERVICE_NAME
echo "installing $f"
if ! dpkg -i $f; then
echo "Error in installing gimx."
quit 4
fi
fi
else
echo "Error in installing gimx. No deb file found."
quit 4
fi
break
done
fi
printf "$SERVICE_CONTENT" > $SERVICE_PATH
systemctl daemon-reload
rm $LOCK_FILE
echo "Installation successful!"
systemctl enable $SERVICE_NAME && systemctl restart $SERVICE_NAME