Skip to content

Commit

Permalink
Merge pull request #963 from ivan-hc/dev
Browse files Browse the repository at this point in the history
"AM" 8.3: fix and improve apps updating / add torsocks support
  • Loading branch information
ivan-hc authored Sep 27, 2024
2 parents c4578c9 + 0e721ac commit ccff40a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
37 changes: 29 additions & 8 deletions APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="8.2.1"
AMVERSION="8.3"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down Expand Up @@ -1014,12 +1014,34 @@ function _update_determine_apps_version_changes() {
fi
}

function _update_updated_app_msg() {
end=$(date +%s)
echo "$APPNAME is updated, $((end - start)) seconds elapsed!"
}

function _update_run_updater() {
if grep -q "api.github.com" "$APPSPATH"/"$arg"/AM-updater; then
GH_API_ALLOWED=$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/releases/latest | sed 's/[()",{} ]/\n/g' | grep "^ivan-hc" | head -1)
if [ -z "$GH_API_ALLOWED" ]; then
if command -v torsocks 1>/dev/null; then
torsocks "$APPSPATH"/"$arg"/AM-updater >/dev/null 2>&1 && _update_updated_app_msg
else
echo "$APPNAME cannot be updated, you have reached GitHub API limit. Install \"torsocks\" from your system package manager and retry!" \
| fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
fi
else
"$APPSPATH"/"$arg"/AM-updater >/dev/null 2>&1 && _update_updated_app_msg
fi
else
"$APPSPATH"/"$arg"/AM-updater >/dev/null 2>&1 && _update_updated_app_msg
fi
}

function _update_app() {
APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
start=$(date +%s)
if [ -w "$APPSPATH"/"$arg"/AM-updater ]; then
start=$(date +%s) &&
sh -x "$APPSPATH"/"$arg"/AM-updater >/dev/null 2>&1 | echo -ne ' Updating "'"$APPNAME"'"...\r' &&
end=$(date +%s) &&
echo "$APPNAME is updated, $((end - start)) seconds elapsed!" &
_update_run_updater &
else
echo "$APPNAME is read-only, cannot update it!"
fi
Expand All @@ -1030,7 +1052,6 @@ function _update_all_apps() {
cd "$f" 2>/dev/null || exit 1
arg=$(printf '%s\n' "${PWD##*/}")
if test -f "$APPSPATH"/"$arg"/AM-updater; then
APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
_update_app
fi
done
Expand All @@ -1043,6 +1064,7 @@ function _update_all_apps() {
function _use_update() {
_online_check
_update_github_api_key_in_the_updater_files
_clean_all_tmp_directories_from_appspath >/dev/null
case $2 in
''|'--apps')
_clean_amcachedir
Expand All @@ -1060,14 +1082,13 @@ function _use_update() {
*)
ARGS="$(echo "$@" | cut -f2- -d ' ')"
for arg in $ARGS; do
APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
if test -f "$APPSPATH"/"$arg"/AM-updater; then
cd "$APPSPATH/$arg" 2>/dev/null || exit 1
_update_app
else
UPDATERS=$(cd "$APPSPATH"/"$arg" 2>/dev/null && find . -name "*update*" -print 2>/dev/null)
[ -n "$UPDATERS" ] && arg_autoupdatable=", it may have its update system"
echo " ✖ Cannot manage updates for \"$APPNAME\"$arg_autoupdatable"
echo " ✖ Cannot manage updates for \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\"$arg_autoupdatable"
fi
done
wait
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ The following are optional dependencies that some programs may require:
- "`binutils`", contains a series of basic commands, including "`ar`" which extracts .deb packages;
- "`unzip`", to extract .zip packages;
- "`tar`", to extract .tar* packages;
- "`torsocks`", to connect to the TOR network;
- "`zsync`", about 10% of AppImages depend on this to be updated.

### Proceede
Expand Down
17 changes: 16 additions & 1 deletion modules/install.am
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,22 @@ _install_arg() {
_apply_patches
echo ""
# Install script
$SUDOCMD ./"$arg"
if grep -q "api.github.com" ./"$arg"; then
GH_API_ALLOWED=$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/releases/latest | sed 's/[()",{} ]/\n/g' | grep "^ivan-hc" | head -1)
if [ -z "$GH_API_ALLOWED" ]; then
if command -v torsocks 1>/dev/null; then
$SUDOCMD torsocks ./"$arg"
else
echo " 💀 Cannot install \"$arg\", you have reached GitHub API limit. Install \"torsocks\" from your system package manager and retry!" \
| fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
return
fi
else
$SUDOCMD ./"$arg"
fi
else
$SUDOCMD ./"$arg"
fi
echo ""
_post_installation_processes
_ending_the_installation
Expand Down

0 comments on commit ccff40a

Please sign in to comment.