Repository navigation
Expand file tree
/
Copy pathscript
More file actions
174 lines (138 loc) · 3.64 KB
/
Copy pathscript
File metadata and controls
174 lines (138 loc) · 3.64 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
set -euo pipefail
# Proton Linux app updater
#
# Dependencies:
# curl
# jq
# dpkg
# dpkg-query
# sha512sum
# sudo
declare -A APPS=(
[Mail]="proton-mail|https://proton.me/download/mail/linux/version.json"
[Authenticator]="proton-authenticator|https://proton.me/download/authenticator/linux/version.json"
[Pass]="proton-pass|https://proton.me/download/pass/linux/version.json"
)
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
update_app() {
local name="$1"
local package="$2"
local metadata_url="$3"
echo "==> $name"
# Check whether the package is installed.
if ! dpkg-query -W -f='${Status}' "$package" 2>/dev/null |
grep -q 'install ok installed'; then
echo " Not installed. Skipping."
echo
return 0
fi
local installed_version
installed_version=$(dpkg-query -W -f='${Version}\n' "$package")
echo " Installed: $installed_version"
# Download metadata.
local metadata="$TMP_DIR/${package}.json"
if ! curl -fsSL "$metadata_url" -o "$metadata"; then
echo " Failed to download version information."
echo
return 1
fi
# Find the newest fully rolled-out Stable release.
#
# Mail calls this RolloutProportion.
# Authenticator and Pass call it RolloutPercentage.
local release
release=$(jq -e '
[
.Releases[]
| select(.CategoryName == "Stable")
| select(
(.RolloutProportion // .RolloutPercentage // 0) >= 1
)
]
| sort_by(.Version | split(".") | map(tonumber))
| last
' "$metadata") || {
echo " Failed to find a fully rolled-out Stable release."
echo
return 1
}
local remote_version
remote_version=$(jq -r '.Version' <<<"$release")
echo " Latest: $remote_version"
# Compare versions using Debian's version comparison.
if dpkg --compare-versions "$remote_version" le "$installed_version"; then
echo " Up to date."
echo
return 0
fi
echo " Update available."
# Get the Debian package information.
local deb_url
local checksum
deb_url=$(jq -r '
.File[]
| select(.Identifier == ".deb (Ubuntu/Debian)")
| .Url
' <<<"$release")
checksum=$(jq -r '
.File[]
| select(.Identifier == ".deb (Ubuntu/Debian)")
| .Sha512CheckSum
' <<<"$release")
if [[ -z "$deb_url" || "$deb_url" == "null" ]]; then
echo " Failed to find DEB download URL."
echo
return 1
fi
if [[ -z "$checksum" || "$checksum" == "null" ]]; then
echo " Failed to find SHA-512 checksum."
echo
return 1
fi
local deb="$TMP_DIR/${package}.deb"
echo " Downloading..."
if ! curl -fL --progress-bar "$deb_url" -o "$deb"; then
echo " Download failed."
echo
return 1
fi
echo " Verifying checksum..."
if ! echo "$checksum $deb" | sha512sum --check --status -; then
echo " Checksum verification FAILED."
echo
return 1
fi
echo " Checksum OK."
echo " Installing..."
if ! sudo apt install -y "$deb"; then
echo " Installation FAILED."
echo
return 1
fi
# Verify that the expected version is now installed.
local new_version
new_version=$(dpkg-query -W -f='${Version}\n' "$package")
if dpkg --compare-versions "$new_version" ge "$remote_version"; then
echo " Successfully updated to $new_version."
echo
return 0
fi
echo " Installation completed, but version verification FAILED."
echo
return 1
}
# Main
failed=0
for name in "${!APPS[@]}"; do
IFS='|' read -r package metadata_url <<<"${APPS[$name]}"
if ! update_app "$name" "$package" "$metadata_url"; then
failed=1
fi
done
if ((failed)); then
echo "One or more Proton apps failed to update."
exit 1
fi
echo "All Proton apps are up to date."