-
Notifications
You must be signed in to change notification settings - Fork 5
/
signal-auth-setup
executable file
·95 lines (85 loc) · 3.21 KB
/
signal-auth-setup
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
#!/usr/bin/env bash
#
# (C) James Murphy 2016, licensed under GPLv2
#
# Script to setup system for signal authentication
if ! command -v signal-cli >/dev/null 2>&1; then
echo >&2 "signal-cli not found, aborting."
exit 1
fi
SIGNAL_CLI="$(which signal-cli)"
SIGNAL_HOME="/var/lib/signal-authenticator"
IFS="
"
function sanitize_phone_number {
echo "$1" | tr -cd "0123456789+"
}
function looks_like_phone_number {
if [[ "$1" =~ ^\+[0-9]+$ ]]; then
return 0
else
return 1
fi
}
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
printf \
"Usage: signal-auth-setup [-h|--help] [as-linked] [override]
Setup signal authentication on your system.
Options:
[no argument]\tSetup the signal-authenticator user's home by registering a
\t\tsignal number
as-linked\tSetup the signal-authenticator user's home by linking as a
\t\tsubordinate device of an existing signal authenticator.
override\tDon't abort if config alerady exists.
-h --help\tShow this help message.\n" && exit 0
fi
if [[ "$(id -u)" -ne 0 ]]; then
echo >&2 "Must be root to setup for the system user, aborting."
exit 1
fi
if [[ -f "$SIGNAL_HOME/.signal_authenticator" ]] || [[ -d "$SIGNAL_HOME/.signal" ]]; then
if [[ "$1" != "override" ]] && [[ "$2" != "override" ]]; then
echo >&2 "It looks like signal-authenticator's home is already setup, aborting."
echo >&2 "Use the override argument to bypass."
echo >&2 "Bypassing will completely remove all previous"\
"configuration, including stored keys and fingerprints."
exit 2
else
echo >&2 "It looks like signal-authenticator's home is already setup, continuing anyway."
fi
fi
read -p "Input signal username to send tokens from (e.g. +15553331234): " USERNAME
USERNAME=$(sanitize_phone_number $USERNAME)
echo "Sanitized number: $USERNAME"
if ! looks_like_phone_number $USERNAME; then
echo >&2 "Bad phone number: $USERNAME, aborting"
exit 4
fi
echo "Creating $SIGNAL_HOME/.signal_authenticator"
echo "username=$USERNAME" > "$SIGNAL_HOME/.signal_authenticator"
chmod o-rwx "$SIGNAL_HOME/.signal_authenticator"
chown signal-authenticator:signal-authenticator "$SIGNAL_HOME/.signal_authenticator"
echo "Removing old config, if it exists"
rm -rf "$SIGNAL_HOME/.config/signal" >/dev/null 2>&1
echo "Registering signal username"
if [[ "$1" == "as-linked" ]] || [[ "$2" == "as-linked" ]]; then
echo "Registering as subordinate (linked) device."
echo "To complete linking, you must run signal-auth-link from the primary device."
echo "It will ask for the following tsdevice:/ link."
sudo -u signal-authenticator "$SIGNAL_CLI" -u "$USERNAME" link
if [[ "$?" != "0" ]]; then
echo >&2 "Failed to link, aborting."
exit 3
fi
else
sudo -u signal-authenticator "$SIGNAL_CLI" -u "$USERNAME" register
read -p "Verify code (sent SMS to $USERNAME): " CODE
sudo -u signal-authenticator "$SIGNAL_CLI" -u "$USERNAME" verify "$CODE"
if [[ "$?" != "0" ]]; then
echo >&2 "Failed to verify $USERNAME, aborting."
exit 3
fi
fi
chmod -R o-rwx "$SIGNAL_HOME/.config/signal"
chown -R signal-authenticator:signal-authenticator "$SIGNAL_HOME/.config/signal"
echo "Your signal authentication is now setup."