From 69a72ff722513ea8cc9440a8eb1d85782ecb0ae3 Mon Sep 17 00:00:00 2001 From: Samuel <36420837+Samueru-sama@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:22:02 -0400 Subject: [PATCH 1/6] Add support for BINDIR --- modules/install.am | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/modules/install.am b/modules/install.am index ffe7a7b0e..6f79331fd 100644 --- a/modules/install.am +++ b/modules/install.am @@ -4,10 +4,12 @@ # THIS MODULE IS USED TO INSTALL APPS FROM THE DATABASE OR FROM LOCAL SCRIPTS ############################################################################# +BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}" + # If you use the --latest option, add the "latest" flag to scripts that point to a very common "release" function _if_latest() { if grep -q 'force-latest' "$AMCACHEDIR"/install-args; then - sed -i 's#/releases | jq #/releases/latest | jq #g' ./"$arg" + sed -i 's#/releases#/releases/latest#g' ./"$arg" fi } @@ -31,11 +33,11 @@ function _install_common_patch() { function _install_appman_local_patch() { sed -i "s#/opt/#$APPSPATH/#g" ./"$arg" sed -i "s# /opt# $APPSPATH#g" ./"$arg" - sed -i "s# /usr/local/bin# $HOME/.local/bin#g" ./"$arg" - sed -i 's# "/usr/local/bin# "'"$HOME"'/.local/bin#g' ./"$arg" - sed -i "s# /usr/bin# $HOME/.local/bin#g" ./"$arg" - sed -i "s# /usr/local/games# $HOME/.local/bin#g" ./"$arg" - sed -i "s# /usr/games# $HOME/.local/bin#g" ./"$arg" + sed -i "s# /usr/local/bin# $BINDIR#g" ./"$arg" + sed -i 's# "/usr/local/bin# "'"$BINDIR"'#g' ./"$arg" + sed -i "s# /usr/bin# $BINDIR#g" ./"$arg" + sed -i "s# /usr/local/games# $BINDIR#g" ./"$arg" + sed -i "s# /usr/games# $BINDIR#g" ./"$arg" sed -i "s# /usr/share/applications# $DATADIR/applications#g" ./"$arg" sed -i "s# /usr/local/share/applications# $DATADIR/applications#g" ./"$arg" sed -i "s# /usr/share/pixmaps# $DATADIR/icons#g" ./"$arg" @@ -58,12 +60,12 @@ function _apply_patches() { # Post-installation processes function _post_installation_processes() { - echo -ne " Configuring $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')...\r" && echo -ne " \r" && + echo -ne " Configuring $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')...\r" && echo -ne " \r" # Add a command to line 2 of the "remove" script to prevent use without root privileges # and take control of the directory to be able to manage and update the app without root privileges if [ "$AMCLI" == am ] 2>/dev/null; then - $SUDOCOMMAND sed -i '1 a if [ -z "$SUDO_COMMAND" ]; then echo "Permission denied"; exit 1; fi' "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/remove 2> /dev/null + $SUDOCOMMAND sed -i '1 a if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/remove 2> /dev/null $SUDOCOMMAND chown -R $currentuser "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)" 2> /dev/null fi # Check if an AM-updater script exists, so the CLI can manage updates for the installed app @@ -78,14 +80,14 @@ function _post_installation_processes() { if [ -z "$(ls -A "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/icons)" ]; then wget -q "$AMCATALOGUEICONS"/"$arg".png -O "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/icons/"$arg" fi - fi && + fi # Patch .desktop to change paths if the app is installed locally if [ "$AMCLI" == appman ] 2>/dev/null; then sed -i "s#Icon=/opt#Icon=$HOME/$APPSDIR#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null - sed -i "s#Exec=$arg#Exec=$HOME/.local/bin/$arg#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null - sed -i 's#Exec=$APP#Exec='"$HOME"'/.local/bin/$APP#g' "$DATADIR"/applications/AM*.desktop 2> /dev/null - sed -i "s#Exec=/usr/bin/#Exec=$HOME/.local/bin/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null - sed -i "s#Exec=/opt/#Exec=$HOME/.local/bin/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null + sed -i "s#Exec=$arg#Exec=$BINDIR/$arg#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null + sed -i 's#Exec=$APP#Exec='"$BINDIR"'/$APP#g' "$DATADIR"/applications/AM*.desktop 2> /dev/null + sed -i "s#Exec=/usr/bin/#Exec=$BINDIR/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null + sed -i "s#Exec=/opt/#Exec=$BINDIR/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null fi } @@ -290,8 +292,8 @@ while [ -n "$1" ]; do rm -R -f "$AMCACHEDIR/multirepo-args" _install_arg else - echo -e "\n ◆ FOUND $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]') FROM MULTIPLE SOURCES:\n" && - printf " Select a URL from this menu (read carefully) or press CTRL+C to abort:\n\n"; sleep 1; + printf '\n%s\n' " ◆ FOUND $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]') FROM MULTIPLE SOURCES:" + printf '%s\n\n' " Select a URL from this menu (read carefully) or press CTRL+C to abort:"; sleep 1 select d in $(cat "$AMCACHEDIR/multirepo-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done cd "$AMCACHEDIR" || return; mkdir -p tmp; cd tmp || return; wget -q "$d/$arg"; cd ..; mv ./tmp/"$arg" ./"$arg"; rmdir ./tmp rm -R -f "$AMCACHEDIR/multirepo-args" From 50444de2fb10318cf3bdbb7e9848e43259cd513a Mon Sep 17 00:00:00 2001 From: iVAN <88724353+ivan-hc@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:40:56 +0200 Subject: [PATCH 2/6] Update install.am --- modules/install.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/install.am b/modules/install.am index 6f79331fd..029a89d7f 100644 --- a/modules/install.am +++ b/modules/install.am @@ -65,7 +65,7 @@ function _post_installation_processes() { # Add a command to line 2 of the "remove" script to prevent use without root privileges # and take control of the directory to be able to manage and update the app without root privileges if [ "$AMCLI" == am ] 2>/dev/null; then - $SUDOCOMMAND sed -i '1 a if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/remove 2> /dev/null + $SUDOCOMMAND sed -i '1 a if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/remove 2> /dev/null $SUDOCOMMAND chown -R $currentuser "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)" 2> /dev/null fi # Check if an AM-updater script exists, so the CLI can manage updates for the installed app From db74b7e34fea42c6b230203fa92b42e1b661bd65 Mon Sep 17 00:00:00 2001 From: iVAN <88724353+ivan-hc@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:49:27 +0200 Subject: [PATCH 3/6] Stop patching the "remove" script --- APP-MANAGER | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/APP-MANAGER b/APP-MANAGER index 6ce176dc6..c6d5633d1 100755 --- a/APP-MANAGER +++ b/APP-MANAGER @@ -281,25 +281,6 @@ function _online_check() { fi } -####################### -# SECURE INSTALLED APPS -####################### - -function _prevent_apps_from_being_removed_by_third_parties() { - # Add a security layer to scripts named "remove" of installed apps to prevent file removal by non-privileged users - if [ "$AMCLI" == am ] 2>/dev/null; then - for r in /opt/*/; do - if test -f "$r"/remove; then - if ! grep -q '"$SUDO_COMMAND"' "$r"/remove 2> /dev/null; then - if [[ "$r" != "/opt/am/" ]]; then - sed -i '1 a if [ -z "$SUDO_COMMAND" ]; then echo "Permission denied"; exit 1; fi' "$r"/remove 2> /dev/null - fi - fi - fi - done - fi -} - ########################################### # FUNCTIONS RELATED TO THE DATABASE OF APPS ########################################### @@ -985,7 +966,6 @@ function _use_module() { } _am_security_check -_prevent_apps_from_being_removed_by_third_parties 2> /dev/null _am_databases_check "$@" case "$1" in From b13d7fb8d645a34ee0d191f30830ef98058614e3 Mon Sep 17 00:00:00 2001 From: iVAN <88724353+ivan-hc@users.noreply.github.com> Date: Thu, 27 Jun 2024 04:15:12 +0200 Subject: [PATCH 4/6] Change version check priority for "version" files --- APP-MANAGER | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/APP-MANAGER b/APP-MANAGER index c6d5633d1..cdbaa2a65 100755 --- a/APP-MANAGER +++ b/APP-MANAGER @@ -344,12 +344,12 @@ function _check_version_if_zsync_file_exists() { function _check_version_if_version_file_exists() { APPVERSION=$(cat "$APPSPATH"/"$arg"/version | head -1 | sed 's:.*/::' | sed "s/$arch//g; s/amd64//g; s/x86-64//g; s/x64//g;" | tr '-' '\n' | tr '_' '\n' | grep -vi "appimage\|$arg\|?\|tar." | grep "[0-9]" | head -1 | sed 's/^v//g') if [ -z "$APPVERSION" ]; then - if grep -q "/v[0-9]*" ./"$arg"/version; then - APPVERSION=$(cat "$APPSPATH"/"$arg"/version | tr '/' '\n' | grep "^v[0-9]" | head -1 | sed 's/^v//g') - elif grep -q "download$" ./"$arg"/version; then + if grep -q "download$" ./"$arg"/version; then APPVERSION=$(cat "$APPSPATH"/"$arg"/version | tr '/' '\n' | sed "s/$arch//g; s/amd64//g; s/x86-64//g; s/x64//g;" | tr '_' '\n' | grep -vi "appimage\|$arg\|?\|tar." | grep "[0-9]" | tail -1 | sed 's/^v//g') elif grep -q "://" ./"$arg"/version; then APPVERSION=$(cat ./"$arg"/version | tr '/' '\n' | grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1) + elif grep -q "/v[0-9]*" ./"$arg"/version; then + APPVERSION=$(cat "$APPSPATH"/"$arg"/version | tr '/' '\n' | grep "^v[0-9]" | head -1 | sed 's/^v//g') elif [ "$(cat ./"$arg"/version | wc -w)" == 1 ]; then APPVERSION=$(cat ./"$arg"/version | head -1) fi From 99d4f79f093c2a0440a6e0b9bc4fde7fb1da0daa Mon Sep 17 00:00:00 2001 From: iVAN <88724353+ivan-hc@users.noreply.github.com> Date: Thu, 27 Jun 2024 04:27:54 +0200 Subject: [PATCH 5/6] Update APP-MANAGER --- APP-MANAGER | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/APP-MANAGER b/APP-MANAGER index cdbaa2a65..c63f1541b 100755 --- a/APP-MANAGER +++ b/APP-MANAGER @@ -698,7 +698,7 @@ function _clean_old_modules() { function _use_clean() { echo -e "\n Cleaning temporary files and folders...\n" && sleep 0.1 && - for i in {100..000}; do + for i in {100..000}; do echo -ne " $i\r" && sleep 0.0001 done _clean_amcachedir_message @@ -839,7 +839,7 @@ function _use_sync() { } function _update_all_apps() { - for f in "$APPSPATH"/*/; do + for f in "$APPSPATH"/*/; do cd "$f" 2>/dev/null && if test -f ./AM-updater; then if [ -w ./AM-updater ]; then @@ -878,7 +878,7 @@ function _use_update() { _update_github_api while [ -n "$1" ]; do case $2 in - ''|'--apps') + ''|'--apps') _clean_amcachedir _list_updatable_apps echo '-----------------------------------------------------------------------------' @@ -904,7 +904,7 @@ function _use_update() { echo '-----------------------------------------------------------------------------' sleep 0.2 exit;; - *) + *) if test -f "$APPSPATH"/"$2"/AM-updater; then if [ -w "$APPSPATH"/"$2"/AM-updater ]; then start=$(date +%s); "$APPSPATH"/"$2"/AM-updater > /dev/null 2>&1 | echo -ne " UPDATING $(echo "$2" | tr '[:lower:]' '[:upper:]')\r"; end=$(date +%s) @@ -931,7 +931,7 @@ function _use_update() { function _use_force_latest() { case $2 in - '') + '') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit ;; *) From 4a7f63d9116174507f7d0bc336a65117b8153d56 Mon Sep 17 00:00:00 2001 From: iVAN <88724353+ivan-hc@users.noreply.github.com> Date: Thu, 27 Jun 2024 05:31:49 +0200 Subject: [PATCH 6/6] Update template.am: first step ahead --- modules/template.am | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/template.am b/modules/template.am index 8909f2806..2729b3372 100644 --- a/modules/template.am +++ b/modules/template.am @@ -32,9 +32,9 @@ function _template_if_github_source() { # CHECK THE DOWNLOAD LINK, THE ONE THAT POINTS TO THE LATEST RELEASE, NOTE THAT IT MAY BE A DEVELOPMENT VERSION, ADD "/latest" AFTER "/releases" TO POINT TO THE LAST STABLE VERSION q="'" if [ "$templatetype" == 0 ]; then - FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | jq '"$q"'.'"$q"' | grep browser_download_url | grep -i appimage | cut -d '"$q"'"'"$q"' -f 4 | head -1' + FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | grep browser_download_url | grep -i appimage | cut -d '"$q"'"'"$q"' -f 4 | head -1' elif [ "$templatetype" == 2 ]; then - FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | jq '"$q"'.'"$q"' | grep browser_download_url | cut -d '"$q"'"'"$q"' -f 4 | head -1' + FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | grep browser_download_url | cut -d '"$q"'"'"$q"' -f 4 | head -1' fi sed -i "s#FUNCTION)#$FUNCTION)#g" ./am-scripts/"$arch"/"$arg" } @@ -49,9 +49,9 @@ function _template_then_github_source() { ;; 'Y'|'y'|*) if [ "$templatetype" == 0 ]; then - echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -i appimage | cut -d '"' -f 4 | head -1 + echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -i appimage | cut -d '"' -f 4 | head -1 elif [ "$templatetype" == 2 ]; then - echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | cut -d '"' -f 4 | head -1 + echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | cut -d '"' -f 4 | head -1 fi echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n" ;; @@ -74,9 +74,9 @@ function _template_then_github_source() { ;; 'Y'|'y'|*) if [ "$templatetype" == 0 ]; then - echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -i "$response" | grep -i appimage | cut -d '"' -f 4 | head -1 + echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -i "$response" | grep -i appimage | cut -d '"' -f 4 | head -1 elif [ "$templatetype" == 2 ]; then - echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -i "$response" | cut -d '"' -f 4 | head -1 + echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -i "$response" | cut -d '"' -f 4 | head -1 fi echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n" ;; @@ -97,9 +97,9 @@ function _template_then_github_source() { ;; 'Y'|'y'|*) if [ "$templatetype" == 0 ]; then - echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -v "$response" | grep -i appimage | cut -d '"' -f 4 | head -1 + echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -v "$response" | grep -i appimage | cut -d '"' -f 4 | head -1 elif [ "$templatetype" == 2 ]; then - echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -v "$response" | cut -d '"' -f 4 | head -1 + echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -v "$response" | cut -d '"' -f 4 | head -1 fi echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n" ;;