replacing signal cli rest api with signal cli #89
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [[ "$(hostname)" != "jeeves" ]]; then
|
||||
echo "Signal device authorization must run on jeeves." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$EUID" -ne 0 ]]; then
|
||||
echo "Signal device authorization must run as root." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$#" -ne 1 ]]; then
|
||||
echo "Usage: signal_authorize.sh DEVICE_URI" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$1" != sgnl://linkdevice\?* ]]; then
|
||||
echo "Invalid Signal device link URI." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
service_name="signal-cli"
|
||||
data_dir="/var/lib/signal-cli"
|
||||
device_uri="$1"
|
||||
restart_service=false
|
||||
|
||||
cleanup() {
|
||||
if [[ "$restart_service" == true ]]; then
|
||||
systemctl start "$service_name"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
restart_service=true
|
||||
systemctl stop "$service_name"
|
||||
runuser -u signal-cli -- \
|
||||
signal-cli --data-dir "$data_dir" -a +12016554378 addDevice --uri "$device_uri"
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
host_name="$(hostname)"
|
||||
if [[ "$#" -ne 0 ]]; then
|
||||
echo "Usage: signal_link.sh" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
service_name="signal-cli"
|
||||
data_dir="/var/lib/signal-cli"
|
||||
link_pid=""
|
||||
temp_dir=""
|
||||
restart_service=false
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "$link_pid" ]] && kill -0 "$link_pid" 2>/dev/null; then
|
||||
kill "$link_pid" 2>/dev/null || true
|
||||
wait "$link_pid" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
if [[ -n "$temp_dir" ]]; then
|
||||
rm -f -- "$temp_dir/link-uri"
|
||||
rmdir -- "$temp_dir"
|
||||
fi
|
||||
|
||||
if [[ "$restart_service" == true ]]; then
|
||||
sudo systemctl start "$service_name"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
restart_service=true
|
||||
sudo systemctl stop "$service_name"
|
||||
|
||||
temp_dir="$(mktemp -d)"
|
||||
link_fifo="$temp_dir/link-uri"
|
||||
mkfifo "$link_fifo"
|
||||
|
||||
sudo -u signal-cli \
|
||||
signal-cli --data-dir "$data_dir" link --name "$host_name" >"$link_fifo" &
|
||||
link_pid="$!"
|
||||
|
||||
if ! IFS= read -r device_uri <"$link_fifo"; then
|
||||
wait "$link_pid"
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$device_uri" != sgnl://linkdevice\?* ]]; then
|
||||
echo "signal-cli returned an invalid device link URI." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Run this command manually on jeeves in another dotfiles dir:"
|
||||
printf "sudo ./scripts/signal/authorize.sh %q\n" "$device_uri"
|
||||
echo "Waiting for jeeves to authorize this device..."
|
||||
|
||||
wait "$link_pid"
|
||||
link_pid=""
|
||||
echo "$host_name is now linked to the Signal account on jeeves."
|
||||
Reference in New Issue
Block a user