Skip to content

Commit 860000d

Browse files
ivan-hcvishnu350
andauthored
"AM" 9.9.5 - add checksum verification (#2125)
* Added _use_verify() function into APP-MANAGER for checksum verification (#2124) * Update APP-MANAGER * Update install.am - Add checksum to post-installation processes * Refactoring on new function "_use_verify" * Reduce checksum messages when updating * Prevent duplicated checksum message in updates * Fit checksum message while updating * Do not specify the program name in the checksum... ...it is already specified in the options that use this function * Update APP-MANAGER Two changes: - If the checksum fails, do not prompt reinstallation. - The precaution to avoid repeating the message about missing shasum/md5sum dependencies no longer works. Removed. * Add spaces in updates to increase readability * Fix checksum in apps from third-party databases * Set DIVIDING_LINE dynamically * Update APP-MANAGER Keep update messages compat * Enable translation in checksum messages * Add checksum file after that ownership of directory is changed * Checksum is not required for tarball/zip files, also if direct download * Green check marks in version number :eyes * Update management.am - Checksum in "downgrade" and "nolibfuse" - "downgrade", run _use_verify - "nolibfuse", remove AM-VERIFIED if exists * Allow checksum on "$pure_arg" (used in "-i") * Validate checksum for auto-updatable portable apps for example firefox*, thunderbird*, tor-browser* and zotero * Fix checksum for archives * If no hashes & no AppImage, "Checksum verification not supported" * Checksum messages in variables to prevent syntax errors in translations * Update APP-MANAGER * Update APP-MANAGER, v9.9.5 --------- Co-authored-by: Vishnu <5123344+vishnu350@users.noreply.github.com>
1 parent 11a44c4 commit 860000d

3 files changed

Lines changed: 95 additions & 4 deletions

File tree

APP-MANAGER

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
AMVERSION="9.9.4-1"
3+
AMVERSION="9.9.5"
44

55
# Determine main repository and branch
66
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
@@ -93,11 +93,13 @@ RED='\033[0;31m'
9393
Gold='\033[0;33m'
9494
Green='\033[0;32m'
9595
LightBlue='\033[1;34m'
96-
DIVIDING_LINE="-----------------------------------------------------------------------------"
96+
97+
command -v tput >/dev/null 2>&1 && TERMINAL_WIDTH="$(("$(tput cols)"-"3"))" || TERMINAL_WIDTH="${COLUMNS:-80}"
98+
DIVIDING_LINE=$(printf '%*s' "$TERMINAL_WIDTH" '' | tr ' ' '-')
9799

98100
# Fit texts to an acceptable width
99101
_fit() {
100-
command -v tput >/dev/null 2>&1 && fold -sw "$(("$(tput cols)"-"3"))" | sed 's/^/ /g' || fold -sw 77 | sed 's/^/ /g'
102+
command -v tput >/dev/null 2>&1 && fold -sw "$TERMINAL_WIDTH" | sed 's/^/ /g' || fold -sw 77 | sed 's/^/ /g'
101103
}
102104

103105
# DEVELOPER MODE
@@ -845,6 +847,9 @@ _check_version() {
845847
if echo "$archived_apps" | grep -q "^$arg$"; then
846848
APPVERSION="$APPVERSION is ARCHIVED"
847849
fi
850+
if [ -f "$argpath"/AM-VERIFIED ]; then
851+
APPVERSION=$(echo "$APPVERSION" | awk '{gsub(/✓/, "\033[32m✓\033[0m"); print}')
852+
fi
848853
if echo "$obsolete_apps" | grep -q "^$arg [0-9]"; then
849854
obsolete_last_release=$(echo "$obsolete_apps" | grep "^$arg " | awk '{print $2}')
850855
APPVERSION="$APPVERSION, of $obsolete_last_release"
@@ -1402,6 +1407,80 @@ _use_sync() {
14021407
echo "$DIVIDING_LINE"
14031408
}
14041409

1410+
_use_verify() {
1411+
# Check if checksum calc tools exist
1412+
if command -v shasum &> /dev/null && command -v md5sum &> /dev/null; then
1413+
# Check if the download was a tarball/zip file
1414+
if { [ -f "$argpath/version" ] && grep -q '\.xz$\|\.zip$\|\.gz$' "$argpath/version"; } \
1415+
|| { [ -f "$argpath/AM-updater" ] && grep -q 'wget.*\.xz \|wget.*\.zip \|wget.*\.gz ' "$argpath/AM-updater"; } \
1416+
|| { [ ! -f "$argpath/version" ] && [ ! -f "$argpath/AM-updater" ] && [ -f "$argpath/updater.ini" ]; }; then
1417+
checksum_msg=$(echo $"Checksum is not required for tarball/zip files.")
1418+
printf "%b✔\033[0m %b \n" "${Green}" "$checksum_msg" | _fit
1419+
printf "Source is tarball/zip" > "$argpath"/AM-VERIFIED
1420+
return 1
1421+
# Search for hash files
1422+
elif [ -f "$argpath"/version ] && grep -qi "^http" "$argpath"/version; then
1423+
download_url=$(sort "$argpath"/version)
1424+
elif [ -f "$argpath"/AM-updater ] && grep -q "wget .*am-extras" "$argpath"/AM-updater; then
1425+
download_url=$(eval "$(grep "wget .*am-extras" "$argpath"/AM-updater | tr '()' '\n' | grep curl | head -1)" | xargs)
1426+
fi
1427+
if [ -n "$download_url" ]; then
1428+
# Search for zsync file
1429+
digest=$(curl -Ls "$download_url.zsync" | grep -a "SHA\|MD5")
1430+
# Search for DIGEST file if no zsync file
1431+
if [ -z "$digest" ]; then
1432+
digest=$(curl -Ls "$download_url.DIGEST")
1433+
if echo "$digest" | grep -qi "not found"; then
1434+
if head -c10 "$argpath"/"$arg" 2>/dev/null | grep -qa '^.ELF....AI$' || head -c10 "$argpath"/"$pure_arg" 2>/dev/null | grep -qa '^.ELF....AI$'; then
1435+
checksum_msg=$(echo $"Checksum cannot be verified, no hashes found.")
1436+
printf "%b⚠️\033[0m %b \n" "${Gold}" "$checksum_msg" | _fit
1437+
return 1
1438+
else
1439+
checksum_msg=$(echo $"Checksum verification not yet supported for this program.")
1440+
printf "%b?\033[0m %b \n" "${LightBlue}" "$checksum_msg" | _fit
1441+
return 1
1442+
fi
1443+
fi
1444+
fi
1445+
else
1446+
checksum_msg=$(echo $"Checksum cannot be verified, missing download URL.")
1447+
printf "%b⚠️\033[0m %b \n" "${Gold}" "$checksum_msg" | _fit
1448+
return 1
1449+
fi
1450+
# Calculate checksums and remove verified status
1451+
if [ -f "$argpath"/"$arg" ]; then
1452+
rm -f "$argpath"/AM-VERIFIED
1453+
checksum_sha1=$(shasum -a 1 "$argpath/$arg" | awk '{print $1}')
1454+
checksum_sha256=$(shasum -a 256 "$argpath/$arg" | awk '{print $1}')
1455+
checksum_sha512=$(shasum -a 512 "$argpath/$arg" | awk '{print $1}')
1456+
checksum_md5=$(md5sum "$argpath/$arg" | awk '{print $1}')
1457+
elif [ -f "$argpath"/"$pure_arg" ]; then
1458+
rm -f "$argpath"/AM-VERIFIED
1459+
checksum_sha1=$(shasum -a 1 "$argpath/$pure_arg" | awk '{print $1}')
1460+
checksum_sha256=$(shasum -a 256 "$argpath/$pure_arg" | awk '{print $1}')
1461+
checksum_sha512=$(shasum -a 512 "$argpath/$pure_arg" | awk '{print $1}')
1462+
checksum_md5=$(md5sum "$argpath/$pure_arg" | awk '{print $1}')
1463+
else
1464+
checksum_msg=$(echo $"Checksum cannot be verified, mismatch in binary name.")
1465+
printf "%b✖\033[0m %b \n" "${RED}" "$checksum_msg" | _fit
1466+
return 1
1467+
fi
1468+
# Grep for any matching checksum
1469+
results=$(echo "$digest" | grep -a "$checksum_md5\|$checksum_sha1\|$checksum_sha256\|$checksum_sha512")
1470+
if [ -z "$results" ]; then
1471+
checksum_msg=$(echo $"Checksum does not match, please manually verify file integrity.")
1472+
printf "%b✖\033[0m %b \n" "${RED}" "$checksum_msg" | _fit
1473+
else
1474+
checksum_msg=$(echo $"Checksum matches, verification successful.")
1475+
printf "%b✔\033[0m %b \n" "${Green}" "$checksum_msg" | _fit
1476+
printf "MD5: %b\nSHA1: %b\nSHA256: %b\nSHA512: %b" "$checksum_sha1" "$checksum_sha256" "$checksum_sha512" "$checksum_md5" > "$argpath"/AM-VERIFIED
1477+
fi
1478+
else
1479+
echo $"Checksum calculation tools do not exist, please install shasum/md5sum."
1480+
fi
1481+
unset checksum_sha1 checksum_sha256 checksum_sha512 checksum_md5 digest download_url results
1482+
}
1483+
14051484
################################################################################################################################################################
14061485
# UPDATE
14071486
################################################################################################################################################################
@@ -1475,9 +1554,15 @@ _update_run_updater() {
14751554
"$argpath"/AM-updater
14761555
fi
14771556
sed -i "s#$ALT_GH#https://api.github.com#g" "$argpath"/AM-updater 2>/dev/null
1557+
checksum_msg=$(_use_verify | xargs)
14781558
end=$(date +%s)
14791559
timelapsed=$((end - start))
1480-
[ "$timelapsed" = 1 ] && printf $" %b✔\033[0m $APPNAME is updated, $timelapsed second elapsed! \n" "${Green}" || printf $" %b✔\033[0m $APPNAME is updated, $timelapsed seconds elapsed! \n" "${Green}"
1560+
if [ "$timelapsed" = 1 ]; then
1561+
timelapsed_msg=$(printf $" %b✔\033[0m $APPNAME is updated, $timelapsed second elapsed! \n" "${Green}")
1562+
else
1563+
timelapsed_msg=$(printf $" %b✔\033[0m $APPNAME is updated, $timelapsed seconds elapsed! \n" "${Green}")
1564+
fi
1565+
printf -- "%b%b\n" "$timelapsed_msg" "$checksum_msg" | sed 's/^ //g; s/^/ /g'
14811566
[ -n "$debug_update" ] && echo "$DIVIDING_LINE"
14821567
}
14831568

modules/install.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ _post_installation_processes() {
219219
"${LASTDIRPATH}"/remove 2>/dev/null
220220
$SUDOCMD chown -R "$USER" "${LASTDIRPATH}" 2>/dev/null
221221
fi
222+
# Add checksum file
223+
argpath="$LASTDIRPATH"
224+
_use_verify
225+
echo ""
222226
# Check for AM-updater script sothat CLI can manage updates
223227
if [ -f "${LASTDIRPATH}"/AM-updater ]; then
224228
mkdir "${LASTDIRPATH}"/.am-installer 2>/dev/null

modules/management.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ _downgrade() {
206206
mv ./"$2".zsync.old ./"$2".zsync 2>/dev/null
207207
echo "$d" > ./version
208208
echo $"ROLLBACK SUCCESSFUL!"
209+
_use_verify
209210
}
210211

211212
################################################################################################################################################################
@@ -447,6 +448,7 @@ _nolibfuse() {
447448
echo $" so I added this command to the bottom of the \"AM-updater\" script!"
448449
fi
449450
echo $" Contact the upstream developers to make them officially upgrade!"
451+
rm -f ./AM-VERIFIED
450452
read -r -p $" Do you wish to remove the old libfuse2 AppImage? (Y/n) " yn
451453
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
452454
return 1

0 commit comments

Comments
 (0)