Skip to content

Instantly share code, notes, and snippets.

@Vic3198
Last active January 26, 2024 04:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Vic3198/f0c9e17ef3d70e7b8c066bfd8cf4db2d to your computer and use it in GitHub Desktop.
Save Vic3198/f0c9e17ef3d70e7b8c066bfd8cf4db2d 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) != 5 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 number. 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
@AlenVelocity
Copy link

Ran this and got after installation

Failed to enable unit: Unit file signal.service does not exist

@yjeanrenaud
Copy link

as root?

@bosgnoom
Copy link

I took a look at this, as I'm reinstalling the AsamK's signal on my raspberry pi. In the data folder the signal.service file is called signal-cli.service right now. Perhaps names changed over time?

@Theblood
Copy link

Theblood commented Feb 2, 2021

Failed to send message: Unit dbus-org.asamk.Signal.service not found. !HELP MEEE!

@chodyo
Copy link

chodyo commented Nov 13, 2021

I encountered the same problem. The name was changed in this commit

AsamK/signal-cli@9e061c8#diff-3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7

Just change the instances of signal.service to signal-cli.service

@kovinet
Copy link

kovinet commented Dec 17, 2021

This script has no support for captcha. I couldn't finish the registration because it was needed to enter captcha before receiving pin.

@kovinet
Copy link

kovinet commented Dec 17, 2021

May I ask what was the reason to replace service user signal-cli, as provided in original config files with the root user?

@jonowo
Copy link

jonowo commented Feb 2, 2022

Here from https://tapucosmo.github.io/signal-bot/. (Edit: it doesn't work. Pain.) Some notes on installing signal-cli while my fourth OpenJDK installation takes an hour to complete because archive.ubuntu.com is being sus.

As of 2/2/2022, there are a few problems with this script:

  • Like others have pointed out, signal.service was changed to service-cli.service.
  • The latest version of signal-cli is v0.10.3. The version validation (lines 34-39) thinks this is wrong.
  • In version v0.10.3 (and likely onward), there is no longer signal-cli-[version].tar.gz, instead there is signal-cli-[version]-[OS].tar.gz.

These are fixed in my fork, which hopefully works for at least a while.

sudo apt-get install default-jdk may not install a new enough JDK version, in which case you will encounter the following error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/asamk/signal/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

You may use sudo apt install openjdk-17-jdk instead.

To generate a QR Code, I recommend https://www.the-qrcode-generator.com/ which requires no registration over the one mentioned in the script.

If you are installing signal-cli on WSL and encounter this error, you may find Distrod useful.

@emporerjoshuanorton
Copy link

I wasn't able to enter the version number v0.10.3. because "the format must be x.y.z." What should I be inputting for the version number?

@chodyo
Copy link

chodyo commented Feb 2, 2022

Try it without the v, e.g. 0.10.3

Copy link

ghost commented Feb 2, 2022

Seems like there is no captcha support on jonowo's fork? Any ways around this?

@jonowo
Copy link

jonowo commented Feb 3, 2022

@luczavestoski I just added captcha support in my fork, but I can't test it since I've never encountered the captcha required error. Please tell me if it works.

See how to obtain a captcha token at https://github.com/AsamK/signal-cli/wiki/Registration-with-captcha.

Copy link

ghost commented Feb 3, 2022

@jonowo Sweet. Everything seemed to work up until the receiving a message from the number registered. I'm getting the error

Dbus client failed: Failed to connect to bus: No such file or directory

Is there anything I can do to fix this? I'm doing this on WSL.

Edit: re-read output and I'm getting systemd error because of WSL. Will troubleshoot on my own.

@jonowo
Copy link

jonowo commented Feb 4, 2022

Apparently I have no idea how signal-cli and DBus works. I switched to signal-cli-rest-api which abstracts away the signal-cli installation and works really nicely for me. If anyone reading this wants to build a signal bot, please consider using signal-cli-rest-api.

@ameuret
Copy link

ameuret commented Jan 26, 2024

@jonowo 💖

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