Skip to content

Commit

Permalink
Update APP-MANAGER
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-hc authored Jun 27, 2024
1 parent a7924ff commit c587ca0
Showing 1 changed file with 11 additions and 79 deletions.
90 changes: 11 additions & 79 deletions APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="6.15.1"
AMVERSION="6.15.1-1"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down Expand Up @@ -33,17 +33,6 @@ function _clean_amcachedir() {
APPMANCONFIG="$CONFIGDIR/appman"
export SCRIPTDIR="$(xdg-user-dir DESKTOP 2>/dev/null || echo "$HOME")"

# Determine sytem package manager
function _system_package_manager_check() {
for cmd in dnf pacman emerge zypper apt-get apk; do
if command -v $cmd &> /dev/null; then
osPKGman="$cmd"
return
fi
done
osPKGman=""
}

# Colors
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'

Expand Down Expand Up @@ -201,40 +190,6 @@ function _use_betatester_off() {
rm -f "$AMPATH"/betatester
}

###############################
# DOWNLOAD PORTABLE DEPENDENCES
###############################

function _jq_installer() {
if ! command -v jq 1>/dev/null; then
_system_package_manager_check
if [[ -z "$osPKGman" ]];then
echo -e " ${RED}💀 ERROR!\033[0m Missing essential command ${Green}jq\033[0m\n"
read -r -p " Do you wish to install it using $AMCLI (Y,n)? " yn
case $yn in
'N'|'n')
echo -e "\n The \"jq\" command is essential for parsing JSON files on sites"
echo " for example api.github.com, to list the URLs of apps to download."
echo -e " You need to install it at least via your package manager to use \"$AMCLI\".\n\n Missing essential command ${RED}jq\033[0m, aborted!"; exit
;;
'Y'|'y'|*)
_clean_amcachedir
echo ""
source "$AMPATH"/modules/install.am -i jq 2>&1 | grep "INSTALLED"
echo ""
;;
esac
else
echo -e " ${RED}💀 ERROR!\033[0m Missing essential command ${Green}jq\033[0m\n"
echo " Install it from your system package manager and retry!"; exit
fi
fi
}

function _portable_dependences_setup() {
_jq_installer
}

###########################################
# FUNCTIONS RELATED TO THE SAFE USE OF "AM"
###########################################
Expand Down Expand Up @@ -281,25 +236,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
###########################################
Expand Down Expand Up @@ -363,12 +299,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
Expand Down Expand Up @@ -717,7 +653,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
Expand Down Expand Up @@ -858,7 +794,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
Expand Down Expand Up @@ -897,7 +833,7 @@ function _use_update() {
_update_github_api
while [ -n "$1" ]; do
case $2 in
''|'--apps')
''|'--apps')
_clean_amcachedir
_list_updatable_apps
echo '-----------------------------------------------------------------------------'
Expand All @@ -923,7 +859,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)
Expand All @@ -950,7 +886,7 @@ function _use_update() {

function _use_force_latest() {
case $2 in
'')
'')
echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit
;;
*)
Expand All @@ -960,10 +896,10 @@ function _use_force_latest() {
echo " ERROR: \"$AMCLI\" cannot manage updates for \"$2\""
elif ! grep -q "api.github.com" "$APPSPATH"/"$2"/AM-updater; then
echo " ERROR: \"$2\" source is not on Github"
elif ! grep -q "/releases | jq " "$APPSPATH"/"$2"/AM-updater; then
elif ! grep -q "/releases | " "$APPSPATH"/"$2"/AM-updater; then
echo " ERROR: \"$2\" does not redirect to a generic \"releases\""
else
sed -i 's#/releases | jq #/releases/latest | jq #g' "$APPSPATH"/"$2"/AM-updater
sed -i 's#/releases | #/releases/latest | #g' "$APPSPATH"/"$2"/AM-updater
"$AMCLIPATH" -u "$2"
fi
;;
Expand All @@ -985,7 +921,6 @@ function _use_module() {
}

_am_security_check
_prevent_apps_from_being_removed_by_third_parties 2> /dev/null
_am_databases_check "$@"

case "$1" in
Expand Down Expand Up @@ -1034,7 +969,6 @@ case "$1" in
_online_check
_if_appman_mode_enabled
_betatester_message_on
_portable_dependences_setup
_use_module "$@"
;;
'-t'|'template')
Expand Down Expand Up @@ -1069,7 +1003,6 @@ case "$1" in
;;
'--force-latest')
_online_check
_portable_dependences_setup
_use_force_latest "$@"
;;
'--system')
Expand All @@ -1088,7 +1021,6 @@ case "$1" in
;;
'update'|'-u'|'-U')
_online_check
_portable_dependences_setup
_use_update "$@"
;;
'version'|'-v'|'--version')
Expand Down

0 comments on commit c587ca0

Please sign in to comment.