|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -AMVERSION="9.9.4-1" |
| 3 | +AMVERSION="9.9.5" |
4 | 4 |
|
5 | 5 | # Determine main repository and branch |
6 | 6 | AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main" |
@@ -93,11 +93,13 @@ RED='\033[0;31m' |
93 | 93 | Gold='\033[0;33m' |
94 | 94 | Green='\033[0;32m' |
95 | 95 | 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 ' ' '-') |
97 | 99 |
|
98 | 100 | # Fit texts to an acceptable width |
99 | 101 | _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' |
101 | 103 | } |
102 | 104 |
|
103 | 105 | # DEVELOPER MODE |
@@ -845,6 +847,9 @@ _check_version() { |
845 | 847 | if echo "$archived_apps" | grep -q "^$arg$"; then |
846 | 848 | APPVERSION="$APPVERSION is ARCHIVED" |
847 | 849 | fi |
| 850 | + if [ -f "$argpath"/AM-VERIFIED ]; then |
| 851 | + APPVERSION=$(echo "$APPVERSION✓" | awk '{gsub(/✓/, "\033[32m✓\033[0m"); print}') |
| 852 | + fi |
848 | 853 | if echo "$obsolete_apps" | grep -q "^$arg [0-9]"; then |
849 | 854 | obsolete_last_release=$(echo "$obsolete_apps" | grep "^$arg " | awk '{print $2}') |
850 | 855 | APPVERSION="$APPVERSION, of $obsolete_last_release" |
@@ -1402,6 +1407,80 @@ _use_sync() { |
1402 | 1407 | echo "$DIVIDING_LINE" |
1403 | 1408 | } |
1404 | 1409 |
|
| 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 | + |
1405 | 1484 | ################################################################################################################################################################ |
1406 | 1485 | # UPDATE |
1407 | 1486 | ################################################################################################################################################################ |
@@ -1475,9 +1554,15 @@ _update_run_updater() { |
1475 | 1554 | "$argpath"/AM-updater |
1476 | 1555 | fi |
1477 | 1556 | sed -i "s#$ALT_GH#https://api.github.com#g" "$argpath"/AM-updater 2>/dev/null |
| 1557 | + checksum_msg=$(_use_verify | xargs) |
1478 | 1558 | end=$(date +%s) |
1479 | 1559 | 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' |
1481 | 1566 | [ -n "$debug_update" ] && echo "$DIVIDING_LINE" |
1482 | 1567 | } |
1483 | 1568 |
|
|
0 commit comments