Skip to content

Instantly share code, notes, and snippets.

@yjeanrenaud
Forked from Vic3198/InstallSignalEN.py
Last active November 12, 2020 20:45
Show Gist options
  • Save yjeanrenaud/4cf05c0dad9b2cd1da3baef349c712b8 to your computer and use it in GitHub Desktop.
Save yjeanrenaud/4cf05c0dad9b2cd1da3baef349c712b8 to your computer and use it in GitHub Desktop.
Simple Python script for automating the installation of signal-cli, the DBus service, and registering a new user. It worked well for me and saved me a lot of time for each time I had to reinstall signal-cli on a new machine, but I cannot 100% guarantee that it will work for you.
#!/usr/bin/env python
#coding: utf-8
#
# Run this file with superuser rights ('sudo') to install the Signal client
raw_input("Welcome to the signal-cli install wizard.\nPress ENTER when you are ready.")
import os
javaInstalled = raw_input("\n\nSignal requires Java and the Java Cryptography extension.\nFor Java, just do 'sudo apt-get install default-jdk'.\nFor the JCE, download it at http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html\nand xopy the files in /usr/lib/jvm/<the Java folder>/lib/security/\nReplace the existing files if needed.\nAre Java and the JCE extension correctly installed? (Yes/No): ")
if javaInstalled in ['Oui', 'Yes', 'O', 'Y', 'oui', 'yes', 'o', 'y']:
# Ask for Signal number and check if raw_input is matching the required format
numberOK = False
while not numberOK:
number = raw_input("""\nType in the phone number that will be associated to your Signal account.\nThis nimber must be formatted as follows: +CCXXXXXXXXX (CC : Country Code).\ne.g. for France: +33601020304.\nNumber: """)
numberOK = True
if number[0] != '+':
numberOK = False
else:
for i in range(1,len(number)):
if number[i] not in ['0', '1', '2', '3', '4','5', '6', '7', '8', '9']:
numberOK = False
if numberOK == False:
print("\nThis is not a valid number. Please retry.")
# Ask for Signal version and check if raw_input is matching the required format
versionOK = False
while not versionOK:
version = raw_input("""\nPlease check the latest signal-cli version\non https://github.com/AsamK/signal-cli/releases and write it below.\nThe format must be x.y.z. e.g. : 0.6.2\nVersion: """)
versionOK = True
if len(version) != 6 or version[1] != '.' or version[3] != '.':
versionOK = False
else:
for i in [0,2,4]:
if version[i] not in ['0', '1', '2', '3', '4','5', '6', '7', '8', '9']:
versionOK = False
if versionOK == False:
print("\nThis is not a valid version. Please retry.")
os.system("cd /tmp ; wget https://github.com/AsamK/signal-cli/releases/download/v" + version + "/signal-cli-" + version + ".tar.gz")
os.system("tar xf /tmp/signal-cli-" + version + ".tar.gz -C /opt ; ln -sf /opt/signal-cli-" + version + "/bin/signal-cli /usr/local/bin/")
os.system('apt-get install -y git')
os.system("cd /tmp ; git clone https://github.com/AsamK/signal-cli.git")
os.system("cd /tmp/signal-cli/data ; cp org.asamk.Signal.conf /etc/dbus-1/system.d/ ; cp org.asamk.Signal.service /usr/share/dbus-1/system-services/ ; cp signal.service /etc/systemd/system/")
os.system("""sed -i -e "s|%dir%|/opt/signal-cli-""" + version + """/|" -e "s|%number%|""" + number + """|" /etc/systemd/system/signal.service""")
os.system("""sed -i -e 's|policy user="signal-cli"|policy user="root"|' /etc/dbus-1/system.d/org.asamk.Signal.conf""")
os.system("""sed -i -e 's|User=signal-cli|User=root|' /etc/systemd/system/signal.service""")
installMode = raw_input("\nA Signal account might be installed on several devices.\nIn this case, one of them is the master device,\nand the others must be linked via a QR Code before use.\nWill this computer be used as the master device for your Signal account? (Yes/No): ")
if installMode in ['Oui', 'Yes', 'O', 'Y', 'oui', 'yes', 'o', 'y']:
sms = raw_input("\nA validation PIN will be sent to the provided phone number.\nIf this phone cannot receive SMS (landline), the PIN will be given by a call.\nCan this phone number receive SMS? (Yes/No): ")
if sms in ['Oui', 'Yes', 'O', 'Y', 'oui', 'yes', 'o', 'y']:
os.system("signal-cli --config /var/lib/signal-cli -u " + number + " register")
else:
os.system("signal-cli --config /var/lib/signal-cli -u " + number + " register --voice")
# Ask for verfication code and check if raw_input is matching the required format
verifOK = False
while not verifOK:
verifCode = raw_input("Enter the 6-digit validation PIN you just received: ")
verifOK = True
if len(verifCode) != 6:
verifOK = False
else:
for i in range(6):
if verifCode[i] not in ['0', '1', '2', '3', '4','5', '6', '7', '8', '9']:
verifOK = False
if verifOK == False:
print("\nThis is not a valid number. Please retry.")
os.system('signal-cli --config /var/lib/signal-cli -u ' + number + ' verify ' + verifCode)
else:
deviceName = raw_input("""\nYou are about to generate a link beginning by tsdevice://...\nCopy it and paste it in a QR Code generator, like https://www.unitag.io.\nBe careful to choose "Text", not "Link" in the generator.\nUse the Signal app on your phone to flash the generated QR code.\nHow do you ant to name your device?: """)
os.system('''signal-cli --config /var/lib/signal-cli link -n "''' + deviceName + '''"''')
os.system("apt-get install libunixsocket-java")
os.system("cp /usr/lib/jni/libunix-java.so /lib") # Because sometimes it says that libunix-java is not in java.library.path
os.system("systemctl daemon-reload && systemctl enable signal.service && systemctl reload dbus.service && systemctl start signal.service")
print("\nInstallation finished.")
numberOK = False
while not numberOK:
number = raw_input("\nIn order to check if the installation completed correctly,\nplease provide a phone number linked to a Signal account (not this one).\nThis number must be formatted as follows: +CCXXXXXXXXX (CC : Country Code).\ne.g. for France: +33601020304.\nNumber: ")
numberOK = True
if number[0] != '+':
numberOK = False
else:
for i in range(1,len(number)):
if number[i] not in ['0', '1', '2', '3', '4','5', '6', '7', '8', '9']:
numberOK = False
if numberOK == False:
print("\nThis is not a valid number. Please retry.")
else:
os.system('''signal-cli --dbus-system send -m "Everything works as expected. The signal-cli client installation is finished.\nWell done!" ''' + number)
received = raw_input("\nA message has just been sent to this number.\nHave you received it? (Yes/No): ")
if received not in ['Oui', 'Yes', 'O', 'Y', 'oui', 'yes', 'o', 'y']:
numberOK = False
else:
print("\nGood! Have fun!")
@yjeanrenaud
Copy link
Author

I changed the version checking line due to AsamK is now on 0.6.11 which is a longer string than this script would expect it.
And I added a little farewell notice at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment