-
Notifications
You must be signed in to change notification settings - Fork 3
/
signal_install.sh
executable file
·732 lines (661 loc) · 19 KB
/
signal_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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
#!/bin/bash
#$Id:$
SCRIPTVERSION="3.29"
# Author: Adimarantis
# License: GPL
#Install script for signal-cli
SIGNALPATH=/opt
SIGNALUSER=signal-cli
LIBPATH=/usr/lib
SIGNALVERSION="0.13.9"
#Check for latest valid version at https://github.com/AsamK/signal-cli/releases
LIBRARYVERSION="0.58.2"
#Check for latest valid version at https://github.com/exquo/signal-libs-build/releases
#Make sure this matches the required version for signal-cli (see lib/libsignal-client-0.xx.x.jar version in signal-cli)
LIBSIG=libsignal_jni.tgz
SIGNALVAR=/var/lib/$SIGNALUSER
DBSYSTEMD=/etc/dbus-1/system.d
DBSYSTEMS=/usr/share/dbus-1/system-services
SYSTEMD=/etc/systemd/system
LOG=/tmp/signal_install.log
TMPFILE=/tmp/signal$$.tmp
DBVER=0.22
OPERATION=$1
JAVACMD=java
JAVA_VERSION=21.0
JDK_PACKAGE=openjdk-21-jre-headless
JAVA_NATIVE=yes
#Check if Java 21 installation is available for this system
JDK_VER=`apt-cache search --names-only $JDK_PACKAGE`
if ! [ "$JAVA_HOME" = "" ]; then
JAVACMD=$JAVA_HOME/bin/java
JAVA_NATIVE=no
fi
if [ -e "/opt/java/bin/java" ]; then
JVER=`/opt/java/bin/java --version | grep -m1 -o '[0-9][0-9]\.[0-9]'`
if [ "$JVER" = "$JAVA_VERSION" ]; then
JAVACMD="/opt/java/bin/java"
export JAVA_HOME="/opt/java"
JAVA_NATIVE=no
fi
fi
JVER=`$JAVACMD --version | grep -m1 -o '[0-9][0-9]\.[0-9]'`
if [ "$JDK_VER" == "" ]; then
JAVA_NATIVE=no
if [ "$JVER" != "$JAVA_VERSION" ]; then
JAVA_NATIVE=download
echo "Warning: No Java $JAVA_VERSION found - will try download of a Java $JAVA_VERSION package"
JAVACMD="/opt/java/bin/java"
fi
fi
#Get OS data
if [ -e /etc/os-release ]; then
source /etc/os-release
cat /etc/os-release >$LOG
else
echo "Could not find OS release data - are you on Linux?"
exit
fi
if grep -q docker /proc/1/cgroup; then
echo "You seem to run in a docker environment."
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
USER=`id | grep root`
if [ -z "$USER" ]; then
echo "Docker Installation needs to run under root"
exit
fi
DOCKER=yes
if [ -n "$FHEMUSER" ]; then
SIGNALUSER=$FHEMUSER
fi
#overide path so its in the "real" world
SIGNALPATH=/opt/fhem
fi
#
install_and_check() {
#Check availability of tools and install via apt if missing
TOOL=$1
PACKAGE=$2
echo -n "Checking for $TOOL..."
WHICH=`which $TOOL`
if [ -z "$WHICH" ]; then
echo -n "installing ($PACKAGE)"
apt-get -q -y install $PACKAGE >>$LOG
WHICH=`which $TOOL`
if [ -z "$TOOL" ]; then
echo "Failed to install $TOOL"
exit
else
echo "done"
fi
else
echo "available"
fi
}
install_by_file() {
#Check availability of tools and install via apt if missing
FILE=$1
PACKAGE=$2
echo -n "Checking for $FILE..."
if ! [ -e "$FILE" ]; then
echo -n "installing ($PACKAGE)..."
apt-get -q -y install $PACKAGE >>$LOG
if ! [ -e "$FILE" ]; then
echo "Failed to install $FILE"
exit
else
echo "done"
fi
else
echo "available"
fi
}
check_and_create_path() {
#Check if path is available and create of not
CHECK=$1
echo -n "Checking for $CHECK..."
if ! [ -d $CHECK ]; then
mkdir $1
if ! [ -d $CHECK ]; then
echo "Failed to create $CHECK - did you run on sudo?"
exit
else
echo "created"
fi
else
echo "found"
fi
if ! [ -w $CHECK ]; then
echo "Cannot write to $CHECK - did you start this script with sudo?"
exit
fi
}
check_and_compare_file() {
#Check if a file exists and compare if its the same as our internal reference file
CHECK=$1
COMPARE=$2
echo -n "Checking for $CHECK..."
if [ -e $CHECK ]; then
echo "found"
diff $CHECK $COMPARE
DIFF=`diff -q $CHECK $COMPARE`
if ! [ -z "$DIFF" ]; then
echo "$CHECK differs, update (Y/n)? "
read REPLY
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
cp $COMPARE $CHECK
echo "$CHECK updated"
else
echo "$CHECK left untouched"
fi
fi
else
cp $COMPARE $CHECK
echo "$CHECK installed"
fi
}
#Main part - do always, check basic system requirements like OS, packages etc - does not install any signal specific stuff
ARCH=`arch`
OSNAME=`uname`
APT=`which apt`
GLIBC=`ldd --version | grep -m1 -o '[0-9]\.[0-9][0-9]' | head -n 1`
if [ $ARCH = "armv7l" ]; then
ARCH="armhf"
ARCHL="armv7-unknown-linux-gnueabihf.tar.gz"
ARCHJ="arm"
elif [ $ARCH = "x86_64" ]; then
ARCH="amd64"
ARCHL="x86_64-unknown-linux-gnu.tar.gz"
ARCHJ="x64"
elif [ $ARCH = "aarch64" ]; then
BITS=`getconf LONG_BIT`
if [ "$BITS" = "64" ]; then
ARCH="aarch64"
ARCHL="aarch64-unknown-linux-gnu.tar.gz"
ARCHJ="aarch64"
else
ARCH="armhf"
ARCHL="armv7-unknown-linux-gnueabihf.tar.gz"
ARCHJ="arm"
fi
fi
if [ $OSNAME != "Linux" ]; then
echo "Only Linux systems are supported (you: $OSNAME), quitting"
exit
fi
if [ -z "$APT" ]; then
echo "Your system does not have apt installed, quitting"
exit
fi
if [ -z "$OPERATION" ] || [ "$OPERATION" = "system" ] || [ "$OPERATION" = "install" ] || [ "$OPERATION" = "all" ]; then
echo "This script will help you to install signal-cli as system dbus service"
echo "and prepare the use of the FHEM Signalbot module"
echo
echo "Please verify that these settings are correct:"
echo "Signal-cli User: $SIGNALUSER"
echo "Signal-cli Install directory: $SIGNALPATH"
echo "Signal config storage: $SIGNALVAR"
echo "Signal version: $SIGNALVERSION (libsignal-client v$LIBRARYVERSION)"
echo "System library path: $LIBPATH"
echo "System architecture: $ARCH"
echo "System GLIBC version: $GLIBC"
echo "Using Java version: $JAVACMD"
echo "Native Java $JAVA_VERSION $JAVA_NATIVE (current version:$JVER)"
fi
if [ ! $(id -u) = 0 ] ; then
# the script needs to be executed with sudo (or root)
echo
echo "Please run $0 with sudo"
exit 1
fi
check_and_update() {
check_and_create_path $LIBPATH
check_and_create_path /etc/dbus-1
check_and_create_path $DBSYSTEMD
check_and_create_path /usr/share/dbus-1
check_and_create_path $DBSYSTEMS
check_and_create_path $SYSTEMD
check_and_create_path /run/dbus
if [ -n "$DOCKER" ]; then
echo -n "Running in Docker, performing apt update/upgrade..."
apt-get -q -y update
apt-get -q -y upgrade
echo "done"
fi
install_and_check apt-ftparchive apt-utils
install_and_check wget wget
install_and_check sudo sudo
install_and_check haveged haveged
install_and_check java default-jre
install_and_check diff diffutils
install_and_check dbus-send dbus
install_and_check cpan cpanminus
install_and_check zip zip
install_and_check qrencode qrencode
if [ -z "$BASH" ]; then
echo "This script requires bash for some functions. Check if bash is installed."
install_and_check bash bash
echo "Please re-run using bash"
exit
fi
#For DBus check a number of Perl modules on file level
install_by_file /usr/include/dbus-1.0/dbus/dbus.h libdbus-1-dev
install_by_file /usr/share/build-essential/essential-packages-list build-essential
install_by_file /usr/share/doc/libimage-librsvg-perl libimage-librsvg-perl
install_by_file /usr/share/perl5/URI.pm liburi-perl
cat >$TMPFILE <<EOF
#!/usr/bin/perl -w
use strict;
use warnings;
use Protocol::DBus;
print \$Protocol::DBus::VERSION."\n";
EOF
echo -n "Checking for Protocol::DBus..."
NETDBUS=`perl $TMPFILE`
if [ "$NETDBUS" = "$DBVER" ]; then
echo "V$NETDBUS found"
else
export PERL_MM_USE_DEFAULT=1
echo -n "Installing latest Protocol::DBus..."
cpan -T install Protocol::DBus >>$LOG 2>>$LOG
echo "done"
fi
echo -n "Checking user $SIGNALUSER ..."
if id "$SIGNALUSER" &>/dev/null; then
echo 'found'
else
adduser --disabled-password --gecos none $SIGNALUSER
echo 'created'
fi
if [ "$JAVA_NATIVE" = "download" ]; then
cd /opt
if [ "$ARCHJ" = "arm" ]; then
echo -n "Downloading private jdk21 build for armv7l platform..."
JAVA_ARC=openjdk-21.0.35-armv7l-glibc2.28.tar.gz
wget -qN https://github.com/bublath/FHEM-Signalbot/raw/main/java/$JAVA_ARC
else
echo -n "Downloading Java from adoptium..."
JAVA_ARC=OpenJDK21U-jdk_$ARCHJ\_linux_hotspot_21.0.2_13.tar.gz
wget -qN https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2%2B13/$JAVA_ARC
fi
if [ -z $JAVA_ARC ]; then
echo "failed"
exit
fi
echo "successful"
echo -n "Unpacking ..."
tar zxf $JAVA_ARC
rm -rf /opt/java
mv jdk* java
rm $JAVA_ARC
echo "done"
JAVA_NATIVE=no
export JAVA_HOME=/opt/java
fi
JVER=`$JAVACMD --version | grep -m1 -o '[0-9][0-9]\.[0-9]'`
if [ "$JAVA_NATIVE" = "yes" ] && [ "$JVER" != "$JAVA_VERSION" ]; then
PKG=$(dpkg-query -W --showformat='${Status}\n' $JDK_PACKAGE | grep "install")
if [ -z "$PKG" ]; then
echo -n "Installing $JDK_PACKAGE..."
apt-get -q -y install $JDK_PACKAGE >>$LOG
else
echo "$JDK_PACKAGE already installed but Java $JVER found. Please use"
echo "sudo update-alternatives --config java"
echo "to activate Java $JAVA_VERSION or set your JAVA_HOME environment variable"
exit
fi
JVER=`$JAVACMD --version | grep -m1 -o '[0-9][0-9]\.[0-9]'`
if [ "$JVER" = "$JAVA_VERSION" ]; then
echo "done"
else
echo "failed"
echo "Error: Installation of $JDK_PACKAGE not successful"
echo "Please try manually and restart installation once successful"
echo "sudo apt-get install $JDK_PACKAGE"
exit
fi
fi
#Final check
JVER=`$JAVACMD --version | grep -m1 -o '[0-9][0-9]\.[0-9]'`
if ! [ "$JVER" = "$JAVA_VERSION" ]; then
echo "Error: Java $JVER found, but Java $JAVA_VERSION required"
echo "Something went wrong that this script cannot resolved - please fix manually"
exit
else
echo "Checking for Java $JAVA_VERSION...successful"
fi
}
#Check, install the signal-cli package as system dbus
#After this, signal-cli should be running and ready to use over dbus
install_signal_cli() {
IDENTSTR=libsignal_v$LIBRARYVERSION/libsignal_jni.so-v$LIBRARYVERSION-$ARCHL
GETLIBS=1
echo -n "Checking/downloading native library..."
wget -qN https://github.com/exquo/signal-libs-build/releases/download/$IDENTSTR -O /tmp/$LIBSIG
if [ -s /tmp/$LIBSIG ]; then
echo "done"
else
echo "error"
echo "Could not find native lib $LIBRARYVERSION for $ARCHL"
GETLIBS=0
exit
fi
check_and_create_path $SIGNALPATH
check_and_create_path $SIGNALVAR
NEEDINSTALL=0
echo -n "Checking for existing signal-cli installation..."
if [ -x "$SIGNALPATH/signal/bin/signal-cli" ]; then
echo "found"
echo -n "Checking signal-cli version..."
CHECKVER=`$SIGNALPATH/signal/bin/signal-cli --version`
echo $CHECKVER
if [ "$CHECKVER" = "signal-cli $SIGNALVERSION" ]; then
echo "signal-cli matches target version...ok"
else
echo -n "Update to current version $SIGNALVERSION (y/N)? "
read REPLY
if [ "$REPLY" = "y" ]; then
NEEDINSTALL=1
fi
fi
else
echo "not found"
NEEDINSTALL=1
fi
if [ $NEEDINSTALL = 1 ]; then
echo "Proceed with signal cli installation"
stop_service
cd /tmp
echo -n "Downloading signal-cli $SIGNALVERSION..."
wget -qN https://github.com/AsamK/signal-cli/releases/download/v$SIGNALVERSION/signal-cli-$SIGNALVERSION-Linux.tar.gz -O signal-cli-$SIGNALVERSION.tar.gz
if [ ! -s signal-cli-$SIGNALVERSION.tar.gz ]; then
#Try alternative name used in 0.12.3
wget -qN https://github.com/AsamK/signal-cli/releases/download/v$SIGNALVERSION/signal-cli-$SIGNALVERSION.tar.gz -O signal-cli-$SIGNALVERSION.tar.gz
fi
if [ -s signal-cli-$SIGNALVERSION.tar.gz ]; then
echo "done"
echo "Unpacking ..."
cd $SIGNALPATH
tar zxf /tmp/signal-cli-$SIGNALVERSION.tar.gz
rm -rf signal
mv "signal-cli-$SIGNALVERSION" signal
if [ "$GETLIBS" = 1 ]; then
cd /tmp
tar zxf $LIBSIG
echo "Updating native libs for $IDENTSTR"
zip -u $SIGNALPATH/signal/lib/libsignal-client-*.jar libsignal_jni.so
fi
echo "done"
rm -f /tmp/signal-cli-$SIGNALVERSION.tar.gz
rm -f /tmp/$LIBSIG
else
echo "failed"
exit
fi
fi
#Updating ownership anyway - just if case
chown -R $SIGNALUSER: $SIGNALVAR
chown -R $SIGNALUSER: $SIGNALPATH/signal
if [ -z "$DOCKER" ]; then
#Don't do this in Docker environment
cat >$TMPFILE <<EOF
<?xml version="1.0"?> <!--*-nxml-*-->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="$SIGNALUSER">
<allow own="org.asamk.Signal"/>
<allow send_destination="org.asamk.Signal"/>
<allow receive_sender="org.asamk.Signal"/>
</policy>
<policy context="default">
<allow send_destination="org.asamk.Signal"/>
<allow receive_sender="org.asamk.Signal"/>
</policy>
</busconfig>
EOF
check_and_compare_file $DBSYSTEMD/org.asamk.Signal.conf $TMPFILE
cat >$TMPFILE <<EOF
[D-BUS Service]
Name=org.asamk.Signal
Exec=/bin/false
User=$SIGNALUSER
SystemdService=dbus-org.asamk.Signal.service
EOF
check_and_compare_file $DBSYSTEMS/org.asamk.Signal.service $TMPFILE
cat >$TMPFILE <<EOF
[Unit]
Description=Send secure messages to Signal clients
Requires=dbus.socket network-online.target
After=dbus.socket network-online.target
Wants=network-online.target
[Service]
Type=dbus
Environment="SIGNAL_CLI_OPTS=-Xms2m"
Environment="JAVA_HOME=$JAVA_HOME"
ExecStartPre=/bin/sleep 10
ExecStart=$SIGNALPATH/signal/bin/signal-cli --config $SIGNALVAR daemon --system
User=$SIGNALUSER
BusName=org.asamk.Signal
[Install]
WantedBy=multi-user.target
Alias=dbus-org.asamk.Signal.service
EOF
check_and_compare_file $SYSTEMD/signal.service $TMPFILE
#Reload config after change
systemctl daemon-reload
systemctl enable signal.service
systemctl reload dbus.service
fi
}
#stop service depending on Docker or not
stop_service() {
if [ -z "$DOCKER" ]; then
echo "Stopping signal-cli service"
service signal stop
else
SIGSERVICE=`ps -eo pid,command | grep $SIGNALVAR | grep -v grep`
if [ -n "$SIGSERVICE" ]; then
echo "Stopping signal-cli daemon for Docker"
ARRAY=($SIGSERVICE)
PID=${ARRAY[0]}
kill $PID
fi
fi
}
#start service depending on Docker or not
start_service() {
if [ -z "$DOCKER" ]; then
echo "Start signal-cli service"
service signal start
else
DBDAEMON=`ps -eo command | grep dbus-daemon | grep -v grep`
if [ -z "$DBDAEMON" ]; then
rm /run/dbus/pid
echo "Starting dbus daemon for Docker"
dbus-daemon --system --address=unix:path=/run/dbus/system_bus_socket >/var/log/dbus.log 2>/var/log/dbus.err &
fi
echo -n "Waiting for dbus to become ready."
WAIT=""
while [ -z "$WAIT" ]
do
WAIT=`ps -eo pid,command | grep dbus-daemon | grep -v grep`
echo -n "."
sleep 1
done
echo "running"
SIGSERVICE=`ps -eo pid,command | grep $SIGNALVAR | grep -v grep`
WAITCHECK="ps -eo pid,command | grep $SIGNALVAR | grep java | grep -v grep"
if [ -z "$SIGSERVICE" ]; then
cd $SIGNALPATH/signal/bin
echo "Starting signal-cli daemon for Docker"
sudo -u $SIGNALUSER ./signal-cli --config $SIGNALVAR daemon --system >/var/log/signal.log 2>/var/log/signal.err &
WAITCHECK="grep -i dbus /var/log/signal.err"
fi
echo -n "Waiting for signal-cli to become ready."
WAIT=""
while [ -z "$WAIT" ]
do
WAIT=`$WAITCHECK`
echo -n "."
sleep 1
done
echo "running"
fi
}
test_device() {
start_service
echo -n "Checking installation via dbus-send command..."
REPLY=`dbus-send --system --type=method_call --print-reply --dest="org.asamk.Signal" /org/asamk/Signal org.asamk.Signal.version`
REP1=`echo $REPLY | grep $SIGNALVERSION`
#REP2=`echo $REPLY | grep "boolean true"`
if [ -n "$REP1" ]; then
echo "success" # - "signal-cli running in standard registration mode"
else
echo "unexpected reply"
echo $REPLY
fi
#if [ -n "$REP2" ]; then
# echo "partial success - still running in -u mode - check $SYSTEMD/signal.service"
#fi
cat <<EOF >$TMPFILE
#!/usr/bin/perl -w
use strict;
use warnings;
use Protocol::DBus::Client;
my \$dbus = Protocol::DBus::Client::system();
\$dbus->initialize();
\$dbus->get_message();
my \$got_response;
my @recipients=('$RECIPIENT');
my @att=();
\$dbus->send_call(
path => '/org/asamk/Signal',
interface => 'org.asamk.Signal',
signature => '',
body => undef,
destination => 'org.asamk.Signal',
member => 'version',
)->then( sub {
print "reply received\n";
} )->catch( sub {
print "Error getting reply\n";
} )->finally( sub {
\$got_response = 1;
} );
\$dbus->get_message() while !\$got_response;
EOF
echo -n "Sending a message via perl Protocol::DBus..."
perl $TMPFILE
}
remove_all() {
#just in case paths are wrong to not accidentially remove wrong things
cd /tmp
echo "Warning. This will remove signal-cli and all related configurations from your system"
echo "Your configuration will be archived to $HOME/signalconf.tar.gz"
echo -n "Continue (y/N)? "
read REPLY
if ! [ "$REPLY" = "y" ]; then
echo "Abort"
exit
fi
stop_service
echo "Archiving config"
tar czf ~/signalconf.tar.gz $SIGNALVAR
echo "Removing files"
rm -rf $SIGNALVAR
rm -rf $SIGNALPATH/signal
rm -f $LIBPATH/libsignal_jni.so
rm -f $LIBPATH/libzkgroup.so
rm -f $DBSYSTEMD/org.asamk.Signal.conf
rm -f $DBSYSTEMS/org.asamk.Signal.service
rm -f $SYSTEMD/signal.service
echo "Disabling services"
if [ -z "$DOCKER" ]; then
systemctl daemon-reload
systemctl disable signal.service
systemctl reload dbus.service
else
DBDAEMON=`ps -eo pid,command | grep dbus-daemon | grep -v grep`
if [ -n "$DBDAEMON" ]; then
echo "Stopping dbus daemon for Docker"
ARRAY=($DBDAEMON)
PID=${ARRAY[0]}
kill $PID
fi
fi
}
if [ -z "$OPERATION" ] ; then
echo "This will update system packages, install or uninstall signal-cli"
echo
echo "system : prepare required system package (except signal-cli)"
echo "install : install signal-cli and setup as dbus system service"
echo "test : run a basic test if everything is installed and registered correctly"
echo "remove : Remove signal-cli and all configurations (will be archived)"
echo "start : Start the signal-cli service (or respective docker processes)"
echo "all : Run system, install, start and test (default)"
echo
OPERATION=all
else
echo "You chose the following option: $OPERATION"
fi
echo
if [ -z "$OPERATION" ] || [ "$OPERATION" = "system" ] || [ "$OPERATION" = "install" ] || [ "$OPERATION" = "all" ]; then
echo -n "Proceed (Y/n)? "
read REPLY
if [ "$REPLY" = "n" ]; then
echo "Aborting..."
exit
fi
fi
if [ $OPERATION = "docker" ]; then
OPERATION=""
fi
# Main flow without option: intall, register
if [ -z "$OPERATION" ] || [ $OPERATION = "all" ] || [ $OPERATION = "system" ]; then
check_and_update
fi
if [ -z "$OPERATION" ] || [ $OPERATION = "all" ] || [ $OPERATION = "install" ]; then
install_signal_cli
fi
if [ -z "$OPERATION" ] || [ $OPERATION = "all" ] || [ $OPERATION = "test" ]; then
test_device
exit
fi
# Other options
if [ $OPERATION = "remove" ]; then
remove_all
fi
if [ $OPERATION = "start" ]; then
start_service
fi
if [ $OPERATION = "backup" ]; then
echo "Creating backup of all configuration files"
stop_service
rm signal-backup.tar.gz
tar czPf signal-backup.tar.gz $SIGNALVAR $DBSYSTEMD/org.asamk.Signal.conf $DBSYSTEMS/org.asamk.Signal.service $SYSTEMD/signal.service
start_service
ls -l signal-backup.tar.gz
fi
if [ $OPERATION = "restore" ]; then
if ! [ -e signal-backup.tar.gz ]; then
echo "Make sure signal-backup.tar.gz is in current directory"
exit
fi
echo "Are you sure you want to restore all signal-cli configuration files?"
echo -n "Any existing configuration will be lost (y/N)? "
read REPLY
if ! [ "$REPLY" = "y" ]; then
echo "Aborting..."
exit
fi
stop_service
echo -n "Restoring backup..."
tar xPf signal-backup.tar.gz
chown -R $SIGNALUSER: $SIGNALVAR
echo "done"
start_service
fi
rm -f $TMPFILE
exit