Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit b6a80eb

Browse files
authored
Merge pull request #10 from AutumnalAntlers/secure
Exit on archive integrity failures
2 parents e3f06a2 + 6874ae8 commit b6a80eb

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

proton-ge-custom-updater.sh

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,28 @@ install() {
3838
curl -L "$url" --output "$filename"
3939
# Verify file integrity if sha512sum is availible and a hash can be obtained
4040
if hash sha512sum && sha512_hash=$(curl -Lf "${url%.tar.gz}.sha512sum" 2>/dev/null); then
41-
echo "--> Verfiying file integrity..."
42-
if ! sha512sum -c <<< "${sha512_hash%% *} ${filename}"; then
43-
# If the session is interactive, we ask the user whether or not to accept a failed checksum,
44-
# but permissively default to continuing if the session is not interactive or no response is given.
45-
if [[ -v PS1 ]] || [[ $- = *i* ]]; then
46-
while true; do
47-
read -p "--> File integrity check failed. Continue? ([Y]/n) "
48-
case "$REPLY" in
49-
[yY][eE][sS]|[yY]|'') break ;;
50-
[nN][oO]|[nN]) exit 1 ;;
51-
*) echo "Invalid input..." ;;
52-
esac
53-
done
54-
else
55-
echo "--> WARNING: File integrity check failed."
41+
echo "--> Verfiying file integrity..."
42+
if ! printf '%s' "${sha512_hash%% *} ${filename}" | sha512sum -c /dev/stdin; then
43+
# If stdin is a terminal, we ask whether
44+
# or not to accept a failed checksum,
45+
# but otherwise exit.
46+
if [ -t 0 ]; then
47+
while true; do
48+
printf '%s' "--> File integrity check failed. Continue? (y/[N]) "
49+
read -r REPLY
50+
case "$REPLY" in
51+
[yY][eE][sS]|[yY]) break ;;
52+
[nN][oO]|[nN]|'') exit 1 ;;
53+
*) echo "Invalid input..." ;;
54+
esac
55+
done
56+
else
57+
echo "--> ERROR: File integrity check failed." 1>&2
58+
exit 1
59+
fi
5660
fi
57-
fi
58-
else
59-
echo "--> Skipping file integrity check (hash not found)."
61+
else
62+
echo "--> Skipping file integrity check (hash not found)."
6063
fi
6164
echo "--> Extracting $filename..."
6265
tar -xf "$filename"

0 commit comments

Comments
 (0)