-
Notifications
You must be signed in to change notification settings - Fork 18
/
INSTALL
394 lines (338 loc) · 11.9 KB
/
INSTALL
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/bin/bash
#check if script is run as root
if [ "$(id -u)" != "0" ]; then
echo "Please run as root"
exit 1
fi
#check if needed tools are installed(not perfect)
command -v java >/dev/null 2>&1 || { echo >&2 "This program requires java but it's not installed. Aborting.";}
command -v javac >/dev/null 2>&1 || { echo >&2 "This program requires javac but it's not installed. Aborting.";}
command -v jsvc >/dev/null 2>&1 || { echo >&2 "This program requires jsvc but it's not installed. Aborting.";}
command -v ant >/dev/null 2>&1 || { echo >&2 "This program requires ant but it's not installed. Aborting.";}
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#compile the project using apache ant
echo "compiling the project using Apache Ant"
ant -f $DIR -Dnb.internal.action.name=rebuild clean jar
PACKAGE_NAME="logigsk"
PACKAGE_VERSION="1.0.0"
TEMP_DIR="/tmp"
PACKAGE_SERVICE_NAME="logigsk-service"
sudo mkdir -p $TEMP_DIR/tmpscripts/daemon
sudo mkdir -p /usr/share/$PACKAGE_NAME
sudo mkdir -p /usr/share/$PACKAGE_NAME/lib
sudo mkdir -p /usr/share/doc/$PACKAGE_NAME
sudo chmod 755 /usr/share/$PACKAGE_NAME/
sudo chmod 755 /usr/share/$PACKAGE_NAME/lib/
sudo chmod 755 /usr/share/doc/$PACKAGE_NAME/
cat > $TEMP_DIR/tmpscripts/copyright <<'endmsg'
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: LogiGSK
Source: https://github.com/MohamadSaada/LogiGSK
Files: *
Copyright (C) 2017 Mohamad Saada
Licence: GPL 3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
.
On Debian systems, the full text of the GNU General Public
License version 3 can be found in the file
`/usr/share/common-licenses/GPL-3'.
endmsg
cat > $TEMP_DIR/tmpscripts/99_LogiGSK <<'endmsg'
#!/bin/bash
#This file should be place in /etc/pm/sleep.d/
USER=`who | grep ':0' | grep -o '^\w*' | head -n1`
case $1 in
hibernate)
#echo "Nothing to do"
;;
suspend)
#echo "Nothing to do"
;;
thaw)
if [ "$(id -u $USER)" != "0" ]; then
sudo -u $USER "/usr/share/logigsk/LogiGSK" restart
fi
;;
resume)
if [ "$(id -u $USER)" != "0" ]; then
sudo -u $USER "/usr/share/logigsk/LogiGSK" restart
fi
;;
*) #echo "Somebody is calling me totally wrong."
;;
esac
endmsg
cat > $TEMP_DIR/tmpscripts/logigsk <<'endmsg'
#!/bin/sh
case $1 in
UNINSTALL)
/usr/share/logigsk/UNINSTALL
;;
*)
java -jar /usr/share/logigsk/LogiGSK.jar
;;
esac
endmsg
cat > $TEMP_DIR/tmpscripts/logigsk-service <<'endmsg'
#!/bin/bash
case $1 in
start)
"/usr/share/logigsk/LogiGSK" start
;;
stop)
"/usr/share/logigsk/LogiGSK" stop
;;
restart)
"/usr/share/logigsk/LogiGSK" restart
;;
install)
if [ "$(id -u)" != "0" ]; then
if [ ! -f "$HOME/.config/autostart/LogiGSK.sh" ]; then
while true; do
read -p "Would you like to add automatic startup of this service? " yn
case $yn in
[Yy]* ) ln -sf /usr/share/logigsk/LogiGSK.sh "$HOME/.config/autostart/LogiGSK.sh"; echo "Successfully added LogiGSK service to automatically startup"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "LogiGSK service is already set to startup automatically"
fi
fi
;;
uninstall)
if [ "$(id -u)" != "0" ]; then
if [ -L "$HOME/.config/autostart/LogiGSK.sh" ]; then
while true; do
read -p "Would you like to remove automatic startup of this service? " yn
case $yn in
[Yy]* ) rm "$HOME/.config/autostart/LogiGSK.sh"; echo "Successfully removed LogiGSK service from automatic startup"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "LogiGSK service is not set to startup automatically"
fi
fi
;;
*)
echo "Usage: logigsk-service {start|stop|restart|install|uninstall}" >&2
exit 3
;;
esac
endmsg
cat > $TEMP_DIR/tmpscripts/logigsk.desktop <<'endmsg'
[Desktop Entry]
Encoding=UTF-8
Name=LogiGSK
Categories=Settings;Utility;
Comment=Logitech Keyboard Configuration Tool
Exec=/usr/bin/logigsk
Icon=/usr/share/logigsk/LogiGSK.png
Terminal=false
Type=Application
StartupNotify=true
endmsg
cat > $TEMP_DIR/tmpscripts/LogiGSK.rules <<'endmsg'
#G410 Atlas Spectrum
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c330", MODE="666"
#G610 Orion
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c333", MODE="666"
#G610 Orion
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c338", MODE="666"
#G810 Spectrum
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c331", MODE="666"
#G810 Spectrum
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c337", MODE="666"
#G910 Orion Spark
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c32b", MODE="666"
#G910 Orion Spectrum
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c335", MODE="666"
endmsg
cat > $TEMP_DIR/tmpscripts/LogiGSK.sh <<'endmsg'
#!/bin/bash
"/usr/share/logigsk/LogiGSK" start
endmsg
cat > $TEMP_DIR/tmpscripts/daemon/LogiGSK <<'endmsg'
#!/bin/sh
if [ "$(id -u)" = "0" ]; then
echo "Please don't run as root"
exit 1
fi
NAME="LogiGSK"
DESC="LogiGSK service"
# Setup variables
# The path to Jsvc
EXEC=/usr/bin/jsvc
# The path to the folder containing the java runtime
#JAVA_HOME=/usr/lib/jvm/default-java
# The path to the folder containing the dameon and other needed libraries
CLASS_PATH_L="/usr/share/logigsk/lib/*.jar"
# The path to the folder containing the executable jar
CLASS_PATH_R="/usr/share/logigsk/LogiGSK.jar"
#Desktop
XDG_DESKTOP_TYPE=KDE
# The fully qualified name of the class to execute
CLASS=Logi.GSeries.Service.LogiGSKService
#The user to run the daemon as
#USER=hammi
# The file that will contain our process identification number (pid) for other scripts/programs that need to access it.
PID=$HOME/.local/share/LogiGSK/LogiGSKService.pid
# System.out writes to this file
LOG_OUT=$HOME/.local/share/LogiGSK/LogiGSKService.out
# System.err writes to this file...
LOG_ERR=$HOME/.local/share/LogiGSK/LogiGSKService.err
jsvc_exec()
{
export DISPLAY=:0
#export XDG_CURRENT_DESKTOP=$XDG_DESKTOP_TYPE
$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH_L":"$CLASS_PATH_R" -procname $NAME -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS
}
case "$1" in
start)
echo "Starting the $DESC..."
# Start the service
jsvc_exec
echo "The $DESC has started."
;;
stop)
if [ -f "$PID" ]; then
echo "Stopping the $DESC..."
# Stop the service
jsvc_exec "-stop"
echo "The $DESC has stopped."
else
echo "Daemon not running, no action taken"
fi
;;
restart)
if [ -f "$PID" ]; then
echo "Restarting the $DESC..."
# Stop the service
jsvc_exec "-stop"
# Start the service
jsvc_exec
echo "The $DESC has restarted."
else
echo "Daemon not running, no action taken"
fi
;;
*)
echo "Usage: /usr/share/logigsk/$NAME {start|stop|restart}" >&2
exit 3
;;
esac
endmsg
cat > $TEMP_DIR/tmpscripts/UNINSTALL <<'endmsg'
#!/bin/bash
#check if script is run as root
if [ "$(id -u)" != "0" ]; then
echo "Please run as root"
exit 1
fi
while true; do
read -p "Are you sure you want to uninstall LogiGSK? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit 0;;
* ) echo "Please answer yes or no.";;
esac
done
USER=`who | grep ':0' | grep -o '^\w*' | head -n1`
#stop the logigsk-service
if [ "$(id -u $USER)" != "0" ]; then
sudo -H -u $USER "/usr/share/logigsk/LogiGSK" stop
fi
rm -r /usr/share/doc/$PACKAGE_NAME
rm -f /usr/bin/$PACKAGE_NAME
rm -f /usr/bin/$PACKAGE_NAME-service
rm -f /usr/share/applications/logigsk.desktop
#remove links from udev, sleep.d and user's autostart directory
if [ -L /etc/udev/rules.d/LogiGSK.rules ]; then
sudo rm /etc/udev/rules.d/LogiGSK.rules
sudo udevadm control --reload-rules
fi
if [ -L /etc/pm/sleep.d/99_LogiGSK ]; then
sudo rm /etc/pm/sleep.d/99_LogiGSK
fi
if [ "$(id -u $USER)" != "0" ]; then
HOME=`eval echo ~$USER`
if [ -L "$HOME/.config/autostart/LogiGSK.sh" ]; then
sudo rm "$HOME/.config/autostart/LogiGSK.sh"
fi
fi
rm -r /usr/share/$PACKAGE_NAME
echo "LogiGSK has been successfully uninstalled"
endmsg
sed -i -e 's/$PACKAGE_NAME/'$PACKAGE_NAME'/g' $TEMP_DIR/tmpscripts/UNINSTALL
USER=`who | grep ':0' | grep -o '^\w*' | head -n1`
if [ "$(id -u $USER)" != "0" ]; then
if [ -f /usr/share/logigsk/LogiGSK ]; then
sudo -H -u $USER "/usr/share/logigsk/LogiGSK" stop
fi
fi
cp $TEMP_DIR/tmpscripts/logigsk.desktop /usr/share/applications/
chmod 0644 /usr/share/applications/logigsk.desktop
cp $TEMP_DIR/tmpscripts/copyright /usr/share/doc/$PACKAGE_NAME/
chmod 0644 /usr/share/doc/$PACKAGE_NAME/copyright
cp $TEMP_DIR/tmpscripts/LogiGSK.rules /usr/share/$PACKAGE_NAME/
chmod 0644 /usr/share/$PACKAGE_NAME/LogiGSK.rules
cp $TEMP_DIR/tmpscripts/LogiGSK.sh /usr/share/$PACKAGE_NAME/
chmod 755 /usr/share/$PACKAGE_NAME/LogiGSK.sh
cp $TEMP_DIR/tmpscripts/99_LogiGSK /usr/share/$PACKAGE_NAME/
chmod 755 /usr/share/$PACKAGE_NAME/99_LogiGSK
cp $DIR/dist/LogiGSK.jar /usr/share/$PACKAGE_NAME/
chmod 755 /usr/share/$PACKAGE_NAME/LogiGSK.jar
cp $DIR/dist/lib/*.jar /usr/share/$PACKAGE_NAME/lib/
chmod 0644 /usr/share/$PACKAGE_NAME/lib/*.jar
cp $TEMP_DIR/tmpscripts/daemon/LogiGSK /usr/share/$PACKAGE_NAME/
chmod 755 /usr/share/$PACKAGE_NAME/LogiGSK
cp $TEMP_DIR/tmpscripts/$PACKAGE_NAME /usr/bin/
chmod 755 /usr/bin/$PACKAGE_NAME
cp $TEMP_DIR/tmpscripts/$PACKAGE_SERVICE_NAME /usr/bin/
chmod 755 /usr/bin/$PACKAGE_SERVICE_NAME
cp $TEMP_DIR/tmpscripts/UNINSTALL /usr/share/$PACKAGE_NAME/
chmod 755 /usr/share/$PACKAGE_NAME/UNINSTALL
echo "$PACKAGE_NAME ($PACKAGE_VERSION); urgency=low" > changelog
echo " * Installed" >> changelog
echo " -- Mohamad Saada <[email protected]> `date -R`" >> changelog
gzip -9c changelog > /usr/share/doc/$PACKAGE_NAME/changelog.gz
cp $DIR/src/Logi/GSeries/Keyboard/Resources/Images/GSK_Icon.png /usr/share/$PACKAGE_NAME/LogiGSK.png
chmod 0644 /usr/share/$PACKAGE_NAME/LogiGSK.png
rm -r $TEMP_DIR/tmpscripts
#create links in udev, sleep.d and user's autostart directory
sudo ln -sf /usr/share/logigsk/LogiGSK.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo ln -sf /usr/share/logigsk/99_LogiGSK /etc/pm/sleep.d/
USER=`who | grep ':0' | grep -o '^\w*' | head -n1`
if [ "$(id -u $USER)" != "0" ]; then
HOME=`eval echo ~$USER`
if [ -d "$HOME/.config/autostart/" ]; then
sudo -u $USER ln -sf /usr/share/logigsk/LogiGSK.sh "$HOME/.config/autostart/LogiGSK.sh"
else
echo "failed to setup LogiGSK service startup file in autostart, please refere to website for more details."
fi
sudo -H -u $USER "/usr/share/logigsk/LogiGSK" start
else
echo "failed to setup LogiGSK service startup file in autostart, please refere to website for more details."
fi
echo "LogiGSK has been successfully installed"