-
-
Save jonowo/b33c9c41fa3ca1776cf3420c6cf4c360 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. Fork of https://gist.github.com/Vic3198/f0c9e17ef3d70e7b8c066bfd8cf4db2d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this Python 3 script with superuser rights ('sudo') to install the Signal client | |
input("Welcome to the signal-cli install wizard.\nPress ENTER when you are ready.") | |
import os | |
yes = ['Oui', 'Yes', 'O', 'Y', 'oui', 'yes', 'o', 'y'] | |
javaInstalled = input( | |
"\n\nSignal requires Java and the Java Cryptography extension.\n" | |
"For Java, just do 'sudo apt install openjdk-17-jdk'.\n" | |
"For the JCE, download it at http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html\n" | |
"and copy the files in /usr/lib/jvm/<the Java folder>/lib/security/" | |
"\nReplace the existing files if needed.\n" | |
"Are Java and the JCE extension correctly installed? (Yes/No): " | |
) | |
if javaInstalled in yes: | |
# Ask for Signal number and check if input is matching the required format | |
numberOK = False | |
while not numberOK: | |
number = input( | |
"\nType in the phone number that will be associated to your Signal account.\n" | |
"This number must be formatted as follows: +CCXXXXXXXXX (CC : Country Code).\n" | |
"e.g. for France: +33601020304.\n" | |
"Number: " | |
) | |
numberOK = number[0] == "+" and number[1:].isdecimal() | |
if not numberOK: | |
print("\nThis is not a valid number. Please retry.") | |
captchaToken = None | |
captchaNeeded = input( | |
"\nIf you are running this script again,\n" | |
"did your previous registration fail with captcha required error? (Yes/No): " | |
) | |
if captchaNeeded in yes: | |
captchaToken = input( | |
"\nObtain a captcha token by following the instructions " | |
"at https://github.com/AsamK/signal-cli/wiki/Registration-with-captcha.\n" | |
"Paste the token here: " | |
) | |
# Omit "signalcaptcha://" | |
if captchaToken.startswith("signalcaptcha://"): | |
captchaToken = captchaToken[len("signalcaptcha://"):] | |
# Ask for Signal version and check if input is matching the required format | |
versionOK = False | |
while not versionOK: | |
version = input( | |
"\nPlease check the latest signal-cli version\n" | |
"on https://github.com/AsamK/signal-cli/releases and write it below.\n" | |
"The format must be x.y.z. e.g. : 0.8.1\n" | |
"Version: " | |
) | |
# Original author didn't know numbers could be larger than 9 | |
versionOK = version.count(".") == 2 and all(s.isdecimal() for s in version.split(".")) | |
if not versionOK: | |
print("\nThis is not a valid number. Please retry.") | |
# Filename now includes OS | |
new_filename = "signal-cli-" + version + "-Linux.tar.gz" | |
os.system("cd /tmp ; wget https://github.com/AsamK/signal-cli/releases/download/v" + version + "/" + new_filename) | |
# Revert filename format because I'm scared of breaking things | |
os.system("mv /tmp/{} /tmp/{}".format(new_filename, "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 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-cli.service /etc/systemd/system/") | |
os.system("""sed -i -e "s|%dir%|/opt/signal-cli-""" + version + """/|" -e "s|%number%|""" + number + """|" /etc/systemd/system/signal-cli.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-cli.service""") | |
installMode = input( | |
"\nA Signal account might be installed on several devices.\n" | |
"In this case, one of them is the master device,\nand the others must be linked via a QR Code before use.\n" | |
"Will this computer be used as the master device for your Signal account? (Yes/No): " | |
) | |
if installMode in yes: | |
sms = input( | |
"\nA validation PIN will be sent to the provided phone number.\n" | |
"If this phone cannot receive SMS (landline), the PIN will be given by a call.\n" | |
"Can this phone number receive SMS? (Yes/No): " | |
) | |
command = "signal-cli --config /var/lib/signal-cli -u " + number + " register" | |
if sms not in yes: | |
command += " --voice" | |
if captchaToken: | |
command += " --captcha " + captchaToken | |
os.system(command) | |
# Ask for verfication code and check if input is matching the required format | |
verifOK = False | |
while not verifOK: | |
verifCode = input("Enter the 6-digit validation PIN you just received: ") | |
verifOK = len(verifCode) == 6 and verifCode.isdecimal() | |
if not verifOK: | |
print("\nThis is not a valid number. Please retry.") | |
os.system('signal-cli --config /var/lib/signal-cli -u ' + number + ' verify ' + verifCode) | |
else: | |
deviceName = input( | |
'\nYou are about to generate a link beginning by sgnl://...\n' | |
'Copy it and paste it in a QR Code generator, like https://www.the-qrcode-generator.com/.\n' | |
'Be careful to choose "Text", not "Link" in the generator.\n' | |
'Use the Signal app on your phone to flash the generated QR code.\n' | |
'How do you want to name your device?: ' | |
) | |
os.system('''signal-cli --config /var/lib/signal-cli link -n "''' + deviceName + '''"''') | |
os.system("apt 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-cli.service && systemctl reload dbus.service && systemctl start signal-cli.service") | |
print("\nInstallation finished.") | |
numberOK = False | |
while not numberOK: | |
number = input( | |
"\nIn order to check if the installation completed correctly,\n" | |
"please provide a phone number linked to a Signal account (not this one).\n" | |
"This number must be formatted as follows: +CCXXXXXXXXX (CC : Country Code).\n" | |
"e.g. for France: +33601020304.\n" | |
"Number: " | |
) | |
numberOK = number[0] == "+" and number[1:].isdecimal() | |
if not numberOK: | |
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 = input("\nA message has just been sent to this number.\nHave you received it? (Yes/No): ") | |
if received not in yes: | |
numberOK = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks..
This script working fine.
could you tell me that how can I see incoming message?