-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-update-cron.sh
executable file
·107 lines (95 loc) · 3.73 KB
/
auto-update-cron.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Version 1.6
#
# Script to add a cron job to check for, download, and install the most recent version from this git repo.
# This will auto-close signal-desktop before installing, default is to check after 5 min on reboot and every 2 days.
#
# NOTE: This client is assuming you have DNSSEC on and validating querys on your local domain/device; or that
# you are inherently trusting https://github.com and https://githubusercontent.com.
#
# Author: Shant Tchatalbachian
# Copy the script to /usr/bin/sd-updater if it doesn't exist
if [ ! -f /usr/bin/sd-updater ]; then
cp ./${0##*/} /usr/bin/sd-updater
chmod +x /usr/bin/sd-updater
apt update && apt install -y wget cron
echo "Script ${0##*/} installed to /usr/bin/sd-updater."
else
sleep 5m && echo "/usr/bin/sd-updater already exists, checking for update."
wget -q -O /usr/bin/sd-updater-tmp https://raw.githubusercontent.com/0mniteck/Signal-Desktop-Mobian/master/auto-update-cron.sh
new_sdu_version=$(sed -n '3p' /usr/bin/sd-updater-tmp)
sdu_version=$(sed -n '3p' /usr/bin/sd-updater)
if [ "$new_sdu_version" != "$sdu_version" ]; then
mv /usr/bin/sd-updater-tmp /usr/bin/sd-updater
chmod +x /usr/bin/sd-updater
echo "0 2 * * * root /usr/bin/sd-updater" > /etc/cron.d/sd-updater
echo "@reboot root /usr/bin/sd-updater" >> /etc/cron.d/sd-updater
echo "/usr/bin/sd-updater updated to $new_sdu_version"
else
rm -f /usr/bin/sd-updater-tmp
echo "/usr/bin/sd-updater $sdu_version"
fi
fi
# Function to check for internet connectivity
check_internet() {
wget -q --spider https://google.com
return $?
}
# Function to get the current version installed
get_current_version() {
if [ -f /usr/bin/signal-desktop ]; then
current_version=$(apt info signal-desktop | grep Version | awk '{print $2}')
echo "$current_version"
else
echo "not_installed"
fi
}
# Function to download the latest version info
download_latest_version_info() {
rm -f /tmp/latest-linux-arm64.yml
wget -q -O /tmp/latest-linux-arm64.yml https://raw.githubusercontent.com/0mniteck/Signal-Desktop-Mobian/master/builds/release/latest-linux-arm64.yml
}
# Function to extract the latest version from the downloaded file
get_latest_version() {
latest_version=$(grep 'version:' /tmp/latest-linux-arm64.yml | awk '{print $2}')
echo "$latest_version"
}
# Function to stop any running instances of signal-desktop
stop_running_instance() {
pkill -f signal-desktop
}
# Function to install the new version
install_new_version() {
rm -f /tmp/signal-desktop.deb
wget -q -O /tmp/signal-desktop.deb https://github.com/0mniteck/Signal-Desktop-Mobian/raw/refs/heads/master/builds/release/$(grep 'url:' /tmp/latest-linux-arm64.yml | awk '{print $3}')
apt install /tmp/signal-desktop.deb
}
# Check for internet
if check_internet; then
echo "Internet is available."
else
echo "No internet connection. Exiting."
exit 1
fi
current_version=$(get_current_version)
download_latest_version_info
latest_version=$(get_latest_version)
# Check if an update is needed
if [ "$current_version" != "$latest_version" ]; then
echo "Updating Signal Desktop from version $current_version to $latest_version"
stop_running_instance
install_new_version
rm -f /tmp/signal-desktop.deb
rm -f /tmp/latest-linux-arm64.yml
else
echo "Signal Desktop is already up to date - version $current_version"
rm -f /tmp/latest-linux-arm64.yml
fi
# Check if the cron job already exists
if [ ! -f /etc/cron.d/sd-updater ]; then
echo "0 2 * * * root /usr/bin/sd-updater" > /etc/cron.d/sd-updater
echo "@reboot root /usr/bin/sd-updater" >> /etc/cron.d/sd-updater
echo "Cron job added."
else
echo "Cron job already exists."
fi