-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest-install-linux-release.sh
More file actions
executable file
·179 lines (165 loc) · 5.83 KB
/
Copy pathtest-install-linux-release.sh
File metadata and controls
executable file
·179 lines (165 loc) · 5.83 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
175
176
177
178
179
#!/bin/sh
set -eu
root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
for command in curl jq openssl python3 sha256sum xxd; do
if ! command -v "$command" >/dev/null 2>&1; then
echo "Installer test requires $command." >&2
exit 1
fi
done
if [ "$(uname -s)" != Linux ] || [ "$(uname -m)" != x86_64 ]; then
echo "Installer test requires x86_64 Linux." >&2
exit 1
fi
if [ "$(id -u)" -eq 0 ]; then
echo "Installer test must run as an unprivileged user." >&2
exit 1
fi
temporary=$(mktemp -d)
# Never control the real user's systemd manager from installer fixtures.
mkdir -p "$temporary/bin"
printf '#!/bin/sh\nexit 0\n' > "$temporary/bin/systemctl"
chmod 755 "$temporary/bin/systemctl"
export PATH="$temporary/bin:$PATH"
server_pid=
cleanup() {
if [ -n "$server_pid" ]; then
kill "$server_pid" >/dev/null 2>&1 || true
wait "$server_pid" 2>/dev/null || true
fi
rm -rf "$temporary"
}
trap cleanup EXIT HUP INT TERM
server="$temporary/server"
mkdir -p "$server/releases"
private_key="$temporary/private.pem"
public_der="$temporary/public.der"
payload="$temporary/payload.json"
signature="$temporary/signature"
installer="$temporary/install-linux.sh"
version=9.8.7
openssl genpkey -algorithm Ed25519 -out "$private_key"
openssl pkey -in "$private_key" -pubout -outform DER -out "$public_der"
public_key=$(tail -c 32 "$public_der" | xxd -p -c 64)
sed \
-e "s/^expected_public_key=.*/expected_public_key=$public_key/" \
-e "s/--proto '=https'/--proto '=http,https'/g" \
-e "s/--proto-redir '=https'/--proto-redir '=http,https'/g" \
"$root/scripts/install-linux-release.sh" > "$installer"
unsigned="$temporary/hex"
cat > "$unsigned" <<EOF
#!/bin/sh
echo "voice-control $version"
EOF
chmod 755 "$unsigned"
sha256=$(sha256sum "$unsigned" | awk '{ print $1 }')
bytes=$(wc -c < "$unsigned" | tr -d ' ')
artifact="HEX-$version-$sha256-x86_64-linux"
cp "$unsigned" "$server/releases/$artifact"
jq -cn \
--arg version "$version" \
--arg artifact "$artifact" \
--arg sha256 "$sha256" \
--argjson bytes "$bytes" \
'{schema_version:1,channel:"stable",target:"x86_64-unknown-linux-gnu",version:$version,artifact:$artifact,bytes:$bytes,sha256:$sha256}' \
> "$payload"
openssl pkeyutl -sign -rawin -inkey "$private_key" \
-in "$payload" -out "$signature"
jq -n \
--arg payload "$(openssl base64 -A -in "$payload")" \
--arg signature "$(openssl base64 -A -in "$signature")" \
'{payload:$payload,signature:$signature}' > "$server/linux-update.json"
port=$((38000 + ($$ % 1000)))
python3 -m http.server "$port" --bind 127.0.0.1 --directory "$server" \
> "$temporary/server.log" 2>&1 &
server_pid=$!
attempt=0
until curl --fail --silent "http://127.0.0.1:$port/linux-update.json" >/dev/null; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 20 ]; then
echo "Fixture server did not start." >&2
exit 1
fi
sleep 0.1
done
home="$temporary/home"
export XDG_DATA_HOME="$home/.local/share"
export XDG_CONFIG_HOME="$home/.config"
install_dir="$home/.local/bin"
support_dir="$home/.local/share/voice-control"
mkdir -p "$support_dir"
printf 'preserve me\n' > "$support_dir/settings.json"
HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_dir" \
HEX_RELEASE_BASE_URL="http://127.0.0.1:$port" \
sh "$installer"
test -L "$install_dir/hex"
test "$("$install_dir/hex" --version)" = "voice-control $version"
grep -Fq 'X-HEX-Managed=true' "$home/.local/share/applications/hex.desktop"
grep -Fq 'X-HEX-Managed=true' "$home/.config/autostart/HEX.desktop"
grep -Fq '" start' "$home/.config/autostart/HEX.desktop"
grep -Fq '# X-HEX-Managed=true' "$home/.config/systemd/user/hex.service"
grep -Fq '" service' "$home/.config/systemd/user/hex.service"
grep -Fxq "EnvironmentFile=-$support_dir/session.env" "$home/.config/systemd/user/hex.service"
HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_dir" \
sh "$installer" uninstall
test ! -e "$install_dir/hex"
test ! -e "$support_dir/versions"
test ! -e "$home/.config/systemd/user/hex.service"
test -f "$support_dir/settings.json"
cp "$server/linux-update.json" "$temporary/feed.valid.json"
jq '.signature = "AAAA"' "$temporary/feed.valid.json" > "$server/linux-update.json"
if HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_dir" \
HEX_RELEASE_BASE_URL="http://127.0.0.1:$port" \
sh "$installer" > "$temporary/signature.log" 2>&1
then
echo "Installer accepted an invalid feed signature." >&2
exit 1
fi
test ! -e "$install_dir/hex"
test ! -e "$support_dir/versions"
cp "$temporary/feed.valid.json" "$server/linux-update.json"
printf 'X' | dd of="$server/releases/$artifact" bs=1 seek=0 conv=notrunc \
>/dev/null 2>&1
if HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_dir" \
HEX_RELEASE_BASE_URL="http://127.0.0.1:$port" \
sh "$installer" > "$temporary/tampered.log" 2>&1
then
echo "Installer accepted a same-size corrupted artifact." >&2
exit 1
fi
test ! -e "$install_dir/hex"
test ! -e "$support_dir/versions"
HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_dir" \
HEX_INSTALL_ARTIFACT="$unsigned" \
HEX_INSTALL_VERSION="$version" \
sh "$installer"
test "$("$install_dir/hex" --version)" = "voice-control $version"
HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_dir" \
sh "$installer" uninstall
important="$temporary/important"
support_link="$temporary/support-link"
mkdir -p "$important/versions"
touch "$important/versions/preserve"
ln -s "$important" "$support_link"
if HOME="$home" \
HEX_INSTALL_DIR="$install_dir" \
HEX_APPLICATION_SUPPORT_DIR="$support_link" \
sh "$installer" uninstall > "$temporary/symlink.log" 2>&1
then
echo "Uninstaller accepted a managed support symlink." >&2
exit 1
fi
test -f "$important/versions/preserve"
echo "Linux release installer smoke test passed."