diff --git a/APP-MANAGER b/APP-MANAGER index 3c2397985..638cea806 100755 --- a/APP-MANAGER +++ b/APP-MANAGER @@ -1,6 +1,6 @@ #!/usr/bin/env bash -AMVERSION="6.8.4" +AMVERSION="6.9" # Determine main repository and branch AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main" @@ -564,9 +564,9 @@ function _completion_lists() { cat "$AMPATH"/options >> "$AMPATH"/list } -############################################# -# OTHER FUNCTIONS RELATED TO INTERNAL OPTIONS -############################################# +##################################################################### +# FUNCTIONS RELATED TO INTERNAL OPTIONS TO MADE "AM" WORK AS "APPMAN" +##################################################################### # Function for the option "appman" or "--user" that helps "AM" function like "AppMan" function _appman_mode_enabled_message() { @@ -629,6 +629,287 @@ if [ "$AMCLI" == am ] 2>/dev/null; then fi fi +############################################################## +# FUNCTIONS RELATED TO INTERNAL OPTION TO CLEAN UNNEEDED FILES +############################################################## + +function _clean_launchers() { + for var in "$DATADIR"/applications/AppImages/*.desktop; do + APPIMAGENAME=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/\s.*$//') + MOUNTPOINTS=$(echo "$APPIMAGENAME" | cut -d'/' -f1-4) + if ! test -f "$APPIMAGENAME" 2> /dev/null; then + if ! test -d "$(echo "$MOUNTPOINTS")" 2> /dev/null; then + if echo "$MOUNTPOINTS" | grep -q "/media/"; then + echo -e "\n πŸ’€ERROR: cannot remove $(basename "$var")\n related AppImage is located in an unmounted path of /media\n" + elif echo "$MOUNTPOINTS" | grep -q "/mnt/"; then + echo -e "\n πŸ’€ERROR: cannot remove $(basename "$var")\n related AppImage is located in an unmounted path of /mnt\n" + fi + else + rm -f "$var" + rm -f "$HOME"/.local/bin/"$(basename -- "$(echo "$APPIMAGENAME" | tr A-Z a-z)")"* + cd "$HOME"/.local/bin && find . -xtype l -delete + fi + fi + done +} + +function _clean_old_modules() { + if [ $AMCLI == am ] 2>/dev/null; then + MODULES=$(cat /opt/am/APP-MANAGER | grep -Eo '\S*.am\S*' | sed 's@.*/@@' | grep -v ";" | grep ".am" | uniq | sort) + else + MODULES=$(cat "$AMCLIPATH" | grep -Eo '\S*.am\S*' | sed 's@.*/@@' | grep -v ";" | grep ".am" | uniq | sort) + fi + for m in "$APPSPATH"/"$AMCLI"/modules/*; do + if [[ "${MODULES}" != *"$(basename -- "$m")"* ]];then + rm -f "$m" + fi + done +} + +function _use_clean() { + echo -e "\n Cleaning of temporary files and folders in progress...\n" && sleep 0.1 && + for i in {1000..0000}; do + echo -ne " $i\r" && sleep 0.0001 + done + rm -R -f "$AMPATH"/.cache/* && echo " β—† Cleaning up the content of $AMPATH/.cache" + rm -R -f "$APPSPATH"/*/tmp && echo ' β—† Removed all '"$APPSPATH"'/*/tmp directories' + if test -f "$DATADIR"/applications/AppImages/*.desktop 2> /dev/null; then + _clean_launchers && echo ' β—† Removed orphaned launchers produced with the "--launcher" option' + fi + _clean_old_modules && echo ' β—† Removed obsolete modules' + echo -e "\n DONE!\n" +} + +######################################################################################### +# FUNCTIONS RELATED TO INTERNAL OPTIONS TO UPDATE "AM"/"APPMAN", THE APPS AND THE MODULES +######################################################################################### + +# Function to update GitHub API key in AM-updater files +function _update_github_api() { + local ghapikey_file="$AMPATH/ghapikey.txt" + if [[ -f "$ghapikey_file" ]]; then + ghapikey=$(<"$ghapikey_file") + local updater_files=("$APPSPATH"/*/AM-updater) # Assuming AM-updater is one level deeper + for f in "${updater_files[@]}"; do + if [[ -f "$f" ]] && grep -q "https://api.github.com" "$f"; then + # Check if the file already contains a valid API key + if ! grep -qE "(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})" "$f"; then + # Insert HeaderAuthWithGITPAT before the GitHub API URL + sed -i "s#https://api.github.com#$HeaderAuthWithGITPAT https://api.github.com#g" "$f" + else + # Replace existing API key with the one from ghapikey.txt + sed -i "s#\(gh[ps]_[a-zA-Z0-9]\{36\}\|github_pat_[a-zA-Z0-9]\{22\}_[a-zA-Z0-9]\{59\}\)#$ghapikey#g" "$f" + fi + fi + done + fi +} + +function _list_updatable_apps() { + _check_version + cd "$APPSPATH" && find -name 'AM-updater' -printf " %h\n" 2>/dev/null | sort -u | xargs -n 1 basename 2>/dev/null > "$AMPATH"/.cache/updatable-args + ARGS=$(cat "$AMPATH"/.cache/updatable-args) + for arg in $ARGS; do + app_version=$(cat "$AMPATH/.cache/version-args" | grep -w " β—† $arg |" | sed 's:.*| ::') + echo " β—† $arg $app_version" >> $AMPATH/.cache/updatable-args-list + done +} + +function _sync_installation_scripts() { + echo "-----------------------------------------------------------------------------" + echo -e " Checking for changes of the installation scripts in the online database..." + rm -R -f "$AMPATH"/.cache/sync-args && echo "" >> "$AMPATH"/.cache/sync-args + cd "$APPSPATH" && find -name 'AM-updater' -printf "%h\n" 2>/dev/null | sort -u | cut -c 3- > "$AMPATH"/.cache/sync-args + ARGS=$(cat "$AMPATH"/.cache/sync-args) + for arg in $ARGS; do + mkdir -p "$APPSPATH/$arg/.am-installer" + if test -f "$APPSPATH/$arg/.am-installer/$arg"; then + CURRENT=$(cat "$APPSPATH"/$arg/.am-installer/$arg) + SOURCE=$(wget -q "$APPSDB"/$arg -O -) + if [ "$CURRENT" == "$SOURCE" ]; then + echo -ne "\r" 2> /dev/null + else + echo -e " β—† Changed https://github.com/ivan-hc/AM/blob/main/programs/$arch/$arg" + fi + else + if curl --output /dev/null --silent --head --fail "$APPSDB"/$arg 1>/dev/null; then + echo -e " β—† No installation script for $arg, downloading one..." + mkdir -p "$APPSPATH/$arg/.am-installer" + wget -q "$APPSDB/$arg" -O "$APPSPATH/$arg/.am-installer/$arg" + fi + fi + done +} + +function _sync_modules() { + echo "-----------------------------------------------------------------------------" + echo -e " Check for updates in modules..." + MODULES=$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/contents/modules?ref="$AMBRANCH" | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*raw.*modules.*am$' | grep -v "sync\|update") + for v in $MODULES; do + cd "$AMPATH"/modules || return + MODULENAME=$(echo "$v" | sed 's:.*/::') + if ! test -f ./"$MODULENAME"; then + echo " β—† Downloading $MODULENAME (not previously installed)..." + wget -q "$v" + chmod a+x ./"$MODULENAME" + fi + CURRENT=$(cat ./"$MODULENAME") + SOURCE=$(wget -q "$v" -O -) + if [ "$CURRENT" == "$SOURCE" ]; then + echo -ne "\r" 2> /dev/null + else + echo " β—† Updating $MODULENAME..." + mkdir tmp + cd tmp || return + wget -q "$v" + cd .. + mv tmp/*.am ./ + chmod a+x ./*.am + rmdir tmp + fi + done + _clean_old_modules +} + +function _sync_amcli() { + echo "-----------------------------------------------------------------------------" + _completion_lists + rm -f /opt/am/appman + if [ "$AMCLIPATH" == /opt/am/appman ] 2>/dev/null; then + AMCLIPATH="/opt/am/APP-MANAGER" + CURRENT_AM_VERSION=$("$AMCLIPATH" -v) + else + CURRENT_AM_VERSION=$("$AMCLIPATH" -v) + fi + echo -ne '\n β—† SYNCHRONIZING "'"$(echo "$AMCLI" | tr a-z A-Z)"'" VERSION '"$CURRENT_AM_VERSION"'...\r'; sleep 1 + rm -R -f "$AMPATH"/.cache/* 1>/dev/null; cd "$AMPATH"/.cache || return + if [ "$AMCLI" == am ] 2>/dev/null; then + wget -q "$AMREPO"/APP-MANAGER && chmod a+x ./APP-MANAGER && chmod 777 ./APP-MANAGER + cd .. + echo y | mv "$AMPATH"/.cache/APP-MANAGER /opt/am/APP-MANAGER + else + wget -q "$AMREPO"/APP-MANAGER -O appman && chmod a+x ./"$AMCLI" + cd .. + echo y | mv "$AMPATH"/.cache/"$AMCLI" "$AMCLIPATH" + fi + if [ ! "$CURRENT_AM_VERSION" == "$("$AMCLIPATH" -v)" ] ; then + echo -ne ' A new release of "'"$(echo "$AMCLI" | tr a-z A-Z)"'" is available, please wait...\r' + echo -e ' β—† "'"$(echo "$AMCLI" | tr a-z A-Z)"'" IS NOW UPDATED TO THE BRAND NEW '"$("$AMCLIPATH" -v)"' VERSION! \n\n Replacement of version '"$CURRENT_AM_VERSION"' currently in use, COMPLETED!' + echo -e "\n See https://github.com/ivan-hc/AM/commits/main\n" + else + echo -e ' β—† "'"$(echo "$AMCLI" | tr a-z A-Z)"'" IS ALREADY UPDATED, CURRENT VERSION '"$CURRENT_AM_VERSION"'' + echo -e "\n See https://github.com/ivan-hc/AM/commits/$AMBRANCH\n" + fi +} + +function _use_sync() { + if [[ "$AMREPO" = *://* ]]; then + _sync_installation_scripts + _sync_modules + _sync_amcli + fi +} + +function _use_update() { + _update_github_api + while [ -n "$1" ]; do + case $2 in + ''|'--apps') + rm -R -f "$AMPATH"/.cache/* + _list_updatable_apps + echo '-----------------------------------------------------------------------------' + echo -e ' "'"$(echo "$AMCLI" | tr a-z A-Z)"'" CAN MANAGE UPDATES FOR THE FOLLOWING PROGRAMS:\n' + if test -f "$AMPATH/.cache/updatable-args-list"; then + cat "$AMPATH/.cache/updatable-args-list" + else + echo " None" + fi + echo -e '\n All self-updatable programs are excluded'; sleep 0.1 + echo '-----------------------------------------------------------------------------' + echo ' >> START OF ALL PROCESSES <<' + echo '-----------------------------------------------------------------------------' + + for f in "$APPSPATH"/*/; do + cd $f 2>/dev/null && + if test -f ./AM-updater; then + APPNAME=$(echo "$(printf '%s\n' "${PWD##*/}")") + start=$(date +%s) && sh -x ./AM-updater > /dev/null 2>&1 | echo -ne ' Updating "'"$APPNAME"'"...\r' && end=$(date +%s) && + echo -e " β—† $(echo "$APPNAME" | tr a-z A-Z) is updated, $(($end-$start)) seconds elapsed!" & + else + echo "" > /dev/null 2>&1 + fi + done + wait + + echo '-----------------------------------------------------------------------------' + + if test -f "$AMPATH"/.cache/updatable-args-list; then + mv "$AMPATH"/.cache/updatable-args-list "$AMPATH"/.cache/updatable-args-list-old + _list_updatable_apps + OLDVER="$AMPATH/.cache/updatable-args-list-old" + NEWVER="$AMPATH/.cache/updatable-args-list" + if cmp --silent -- "$NEWVER" "$OLDVER"; then + echo ' Nothing to do here!' + else + echo -e " The following apps have been updated:\n" + diff --new-line-format="" --unchanged-line-format="" "$NEWVER" "$OLDVER" + echo "" + fi + else + echo ' No apps to update here!' + fi + rm -R -f $APPSPATH/*/tmp + if [ -z "$2" ]; then + echo "-----------------------------------------------------------------------------" + _use_sync + fi + echo '-----------------------------------------------------------------------------' + echo ' >> END OF ALL PROCESSES << ' + echo '-----------------------------------------------------------------------------' + sleep 0.2 + exit;; + *) + if test -f "$APPSPATH"/$2/AM-updater; then + start=$(date +%s); "$APPSPATH"/$2/AM-updater > /dev/null 2>&1 | echo -ne " UPDATING $(echo $2 | tr a-z A-Z)\r"; end=$(date +%s) + echo -e " β—† $(echo $2 | tr a-z A-Z) is updated, $(($end-$start)) seconds elapsed!" + rm -R -f "$AMPATH"/.cache/* + _list_updatable_apps + break + else + echo ' "'"$(echo "$AMCLI" | tr a-z A-Z)"'" CANNOT MANAGE UPDATES FOR "'"$(echo $2 | tr a-z A-Z)"'"' + UPDATERS=$(cd "$APPSPATH"/$2 2>/dev/null && find . -name "*update*" -print 2>/dev/null) + if [ -n "$UPDATERS" ]; then + echo ' This program probably includes its own update system!' + fi + exit + fi + esac + done + shift +} + +function _use_force_latest() { + case $2 in + '') + echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit + ;; + *) + if ! test -d "$APPSPATH"/$2; then + echo ' ERROR: "'$2'" is not installed, see "-f"' + elif ! test -f "$APPSPATH"/$2/AM-updater; then + 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 + echo ' ERROR: "'$2'" does not redirect to a generic "releases"' + else + sed -i 's#/releases | jq #/releases/latest | jq #g' "$APPSPATH"/$2/AM-updater + $AMCLIPATH -u $2 + fi + ;; + esac +} + ############################################# # FUNCTION TO HANDLE ALL THE EXTERNAL MODULES ############################################# @@ -652,19 +933,22 @@ case "$1" in echo -e "\n USAGE: '$AMCLI [option]'\n '$AMCLI [option] [argument]'\n\n Run the '$AMCLI -h' command to find out more\n" ;; # OPTIONS BASED ON EXTERNAL MODULES - '-a'|'about'|'-l'|'list'|'-q'|'query') + '-a'|'about'|\ + '-l'|'list'|\ + '-q'|'query') MODULE="database.am" _if_appman_mode_enabled _use_module "$@" ;; - '-b'|'backup'|'-o'|'overwrite'|'lock'|'unlock') - MODULE="no-updates.am" + '-b'|'backup'|\ + '-o'|'overwrite'|\ + '-R'|'-r'|'remove'|\ + '--rollback'|\ + 'lock'|'unlock'|\ + 'nolibfuse') + MODULE="management.am" _use_module "$@" ;; - '-c'|'clean') - MODULE="clean.am" - _use_module - ;; '-d'|'download') MODULE="download.am" _online_check @@ -681,7 +965,8 @@ case "$1" in _if_appman_mode_enabled _use_module "$@" ;; - '-H'|'--home'|'--firejail'|'--sandbox') + '-H'|'--home'|\ + '--firejail'|'--sandbox') MODULE="sandboxes.am" _use_module "$@" ;; @@ -693,46 +978,22 @@ case "$1" in _portable_dependences_setup _use_module "$@" ;; - '-R'|'-r'|'remove') - MODULE="remove.am" - _use_module "$@" - ;; - '-s'|'sync') - MODULE="sync.am" - _online_check - _betatester_message_on - _use_module "$@" - ;; '-t'|'template') MODULE="template.am" _online_check _use_module "$@" ;; - '-u'|'-U'|'update'|'--force-latest') - MODULE="update.am" - _online_check - _portable_dependences_setup - _use_module "$@" - ;; '--launcher') MODULE="launcher.am" _use_module "$@" ;; - '--rollback') - MODULE="rollback.am" - _online_check - _use_module "$@" - ;; - 'neodb'|'apikey'|'newrepo') + 'neodb'|\ + 'apikey'|\ + 'newrepo') MODULE="devtools.am" _online_check _use_module "$@" ;; - 'nolibfuse') - MODULE="nolibfuse.am" - _online_check - _use_module "$@" - ;; # INBUILT OPTIONS '--devmode-disable') _use_betatester_off @@ -747,12 +1008,30 @@ case "$1" in '--enable-completion') _use_enable_completion ;; + '--force-latest') + _online_check + _portable_dependences_setup + _use_force_latest "$@" + ;; '--system') _back_to_am ;; '--user'|'appman') _use_appman ;; + 'clean'|'-c') + _use_clean + ;; + 'sync'|'-s') + _online_check + _betatester_message_on + _use_sync + ;; + 'update'|'-u'|'-U') + _online_check + _portable_dependences_setup + _use_update "$@" + ;; 'version'|'-v'|'--version') echo "$AMVERSION" ;; diff --git a/INSTALL b/INSTALL index 11da05d6e..b41f11c61 100755 --- a/INSTALL +++ b/INSTALL @@ -46,7 +46,7 @@ ln -s /opt/am/APP-MANAGER /usr/local/bin/am || echo "WARNING: Something went wro web_get "https://raw.githubusercontent.com/ivan-hc/AM/main/programs/$arch-apps" || exit 1 # DOWNLOAD MODULES -MODULES=$(curl -Ls https://api.github.com/repos/ivan-hc/AM/contents/modules | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*raw.*modules.*am$') +MODULES=$(curl -Ls https://api.github.com/repos/ivan-hc/AM/contents/modules | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*raw.*modules.*am$' | grep -v "sync\|update") for module in $MODULES; do for v in $module; do cd /opt/am/modules || exit diff --git a/modules/clean.am b/modules/clean.am deleted file mode 100644 index fbb65c221..000000000 --- a/modules/clean.am +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -function _clean_launchers() { - for var in "$DATADIR"/applications/AppImages/*.desktop; do - APPIMAGENAME=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/\s.*$//') - MOUNTPOINTS=$(echo "$APPIMAGENAME" | cut -d'/' -f1-4) - if ! test -f "$APPIMAGENAME" 2> /dev/null; then - if ! test -d "$(echo "$MOUNTPOINTS")" 2> /dev/null; then - if echo "$MOUNTPOINTS" | grep -q "/media/"; then - echo -e "\n πŸ’€ERROR: cannot remove $(basename "$var")\n related AppImage is located in an unmounted path of /media\n" - elif echo "$MOUNTPOINTS" | grep -q "/mnt/"; then - echo -e "\n πŸ’€ERROR: cannot remove $(basename "$var")\n related AppImage is located in an unmounted path of /mnt\n" - fi - else - rm -f "$var" - rm -f "$HOME"/.local/bin/"$(basename -- "$(echo "$APPIMAGENAME" | tr A-Z a-z)")"* - cd "$HOME"/.local/bin && find . -xtype l -delete - fi - fi - done -} - -function _clean_old_modules() { - if [ $AMCLI == am ] 2>/dev/null; then - MODULES=$(cat /opt/am/APP-MANAGER | grep -Eo '\S*.am\S*' | sed 's@.*/@@' | grep -v ";" | grep ".am" | uniq | sort) - else - MODULES=$(cat "$AMCLIPATH" | grep -Eo '\S*.am\S*' | sed 's@.*/@@' | grep -v ";" | grep ".am" | uniq | sort) - fi - for m in "$APPSPATH"/"$AMCLI"/modules/*; do - if [[ "${MODULES}" != *"$(basename -- "$m")"* ]];then - rm -f "$m" - fi - done -} - -function _clean_all() { - echo -e "\n Cleaning of temporary files and folders in progress...\n" && sleep 0.1 && - for i in {1000..0000}; do - echo -ne " $i\r" && sleep 0.0001 - done - rm -R -f "$AMPATH"/.cache/* && echo " β—† Cleaning up the content of $AMPATH/.cache" - rm -R -f "$APPSPATH"/*/tmp && echo ' β—† Removed all '"$APPSPATH"'/*/tmp directories' - if test -f "$DATADIR"/applications/AppImages/*.desktop 2> /dev/null; then - _clean_launchers && echo ' β—† Removed orphaned launchers produced with the "--launcher" option' - fi - _clean_old_modules && echo ' β—† Removed obsolete modules' - echo -e "\n DONE!\n" -} - -_clean_all diff --git a/modules/database.am b/modules/database.am index 69ca81503..2bcb972b9 100644 --- a/modules/database.am +++ b/modules/database.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +############################################################################################ +# THIS MODULE INCLUDES ALL THE ACTIONS INTENDED FOR THE MANAGEMENT OF LISTS AND SINGLE PAGES +############################################################################################ + function _clean_lists_and_queries() { # Remove references to URLs, "-a" elements and limit message length to a maximum of 80 characters in "-l" and "-q" cut -c -81 | sed 's#http://[^ ]*##g' | sed 's#https://[^ ]*##g' | sed 's#ftp://[^ ]*##g' | sed 's/SITE://g' | sed 's/SOURCE://g' diff --git a/modules/devtools.am b/modules/devtools.am index 78c763e04..8a29f66e5 100644 --- a/modules/devtools.am +++ b/modules/devtools.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +##################################################################################### +# THIS MODULE INCLUDES ALL ACTIONS INTENDED TO BE USED BY DEVELOPERS AND EXPERT USERS +##################################################################################### + case "$1" in 'neodb') while [ -n "$1" ]; do diff --git a/modules/download.am b/modules/download.am index a386c54ee..1ed914ee6 100644 --- a/modules/download.am +++ b/modules/download.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +##################################################################################### +# THIS MODULE ALLOWS YOU TO DOWNLOAD THE INSTALLATION SCRIPTS WITHOUT INSTALLING THEM +##################################################################################### + function _convert_to_appman_compatible_script() { if grep -q -- "--convert" "$AMPATH"/.cache/download-args; then if test -f "$APPMANCONFIG"/appman-config; then diff --git a/modules/files.am b/modules/files.am index ee85c8c4c..c4cf3ed96 100644 --- a/modules/files.am +++ b/modules/files.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +########################################################################## +# THIS MODULE ALLOWS YOU TO SEE THE MAIN INFORMATION ON THE INSTALLED APPS +########################################################################## + function _files_header() { echo "" echo $(echo "YOU HAVE INSTALLED " diff --git a/modules/help.am b/modules/help.am index 58263a890..5a221ac48 100644 --- a/modules/help.am +++ b/modules/help.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +######################################### +# THIS MODULE ONLY SHOWS THE HELP MESSAGE +######################################### + function _help_head() { printf ' _____ _____ diff --git a/modules/install.am b/modules/install.am index 4be94ac9f..edf75343e 100644 --- a/modules/install.am +++ b/modules/install.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +############################################################################# +# THIS MODULE IS USED TO INSTALL APPS FROM THE DATABASE OR FROM LOCAL SCRIPTS +############################################################################# + # Check if the installation script is a metapackage (example one of the 40+ kdegames scripts) function _if_metapackage() { for metapackage in $(echo "$METAPACKAGES"); do diff --git a/modules/launcher.am b/modules/launcher.am index a474bbdff..16cafb26f 100644 --- a/modules/launcher.am +++ b/modules/launcher.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +######################################################################################################################### +# THIS MODULE HELPS YOU INTEGRATE LOCAL APPIMAGES BY DRAG/DROP THEM INTO THE TERMINAL, LIKE ANY COMMON APPIMAGE ASSISTANT +######################################################################################################################### + function _launcher_appimage_extract() { "$arg" --appimage-extract share/icons/*/*/* 1>/dev/null "$arg" --appimage-extract usr/share/icons/*/*/* 1>/dev/null diff --git a/modules/management.am b/modules/management.am new file mode 100644 index 000000000..7af1e092a --- /dev/null +++ b/modules/management.am @@ -0,0 +1,432 @@ +#!/usr/bin/env bash + +############################################################################################## +# THIS MODULE INCLUDES ALL THE ACTIONS INTENDED TO MANAGE THE APPS INSTALLED FROM THE DATABASE +############################################################################################## + +case $2 in + '') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit;; +esac + +######################################## +# FUNCTIONS RELATED TO THE APP'S REMOVAL +######################################## + +function _remove_check_removals() { + if test -f "$AMPATH"/.cache/unavailable-args; then + echo -e "-----------------------------------------------------------------------\n" + if [ "$AMCLI" == am ] 2>/dev/null; then + echo -e " πŸ’€ ERROR, the following programs you want to remove are NOT in $APPSPATH :\n\n$(cat "$AMPATH"/.cache/unavailable-args | sort)" + else + echo -e " πŸ’€ ERROR, the following programs you want to remove are NOT in\n $APPSPATH :\n\n$(cat "$AMPATH"/.cache/unavailable-args | sort)" + fi + echo -e '\n INVALID "APPNAME"!' + echo -e "\n-----------------------------------------------------------------------\n" + echo ' β—† INSTALLED PROGRAMS/VALID ARGUMENTS (SEE THE "APPNAME" COLUMN):' + $AMCLIPATH -f | grep -v "STANDALONE PROGRAMS MANAGED"; rm "$AMPATH"/.cache/unavailable-args + echo -e "-----------------------------------------------------------------------" + exit + else + exit + fi +} + +function _REMOVE() { + if ls "$APPSPATH"/$arg > /dev/null 2>&1; then + $SUDOCOMMAND "$APPSPATH"/$arg/remove && sleep 0.5 && echo ' β—† "'"$(echo $arg | tr a-z A-Z)"'" HAS BEEN SUCCESSFULLY REMOVED!' + else + echo " - $arg" >> "$AMPATH"/.cache/unavailable-args + fi +} + +function _remove() { + if ls "$APPSPATH"/$arg > /dev/null 2>&1; then + case $arg in + *) + $SUDOCOMMAND echo "" > /dev/null; read -p ' β—† DO YOU WISH TO REMOVE "'"$(echo $arg | tr a-z A-Z)"'" (Y,n)?' yn + case $yn in + [Nn]* ) + echo ' - "'"$(echo $arg | tr a-z A-Z)"'" HAS NOT BEEN REMOVED!'; echo "";; + [Yy]*|* ) + $SUDOCOMMAND "$APPSPATH"/$arg/remove && sleep 0.5 && echo ' β—† "'"$(echo $arg | tr a-z A-Z)"'" HAS BEEN SUCCESSFULLY REMOVED!';; + esac + esac + else + echo " - $arg" >> "$AMPATH"/.cache/unavailable-args + fi +} + +###################################### +# FUNCTION TO DOWNGRADE INSTALLED APPS +###################################### + +function _do_rollback() { + if test -f "$APPSPATH"/$2/AM-updater; then + if test -f "$APPSPATH"/$2/$2-rollback; then + cd "$APPSPATH"/$2 || return + ./$2-rollback + exit + elif test -f "$APPSPATH"/$2/*.zsync; then + echo " AppImage packages updatable with zsync have not previous versions."; exit + elif test -f "$APPSPATH"/$2/updater; then + echo ' When an executable called "updater" is available, the app is only updateable.'; exit + else + if grep -q "api.github.com" "$APPSPATH"/$2/AM-updater; then + rm -f "$AMPATH/.cache/rollback-args"; + extension=$(cat "$APPSPATH"/$2/version | tr '.' '\n' | tail -1) + REPO=$(grep -i "REPO=" "$APPSPATH"/$2/AM-updater | grep -o -P '(?<=").*(?=")') + printf "%s\n" "$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/$REPO/releases?per_page=100 \ + | grep browser_download_url | cut -d '"' -f 4)" | tr ' ' '\n' | grep -i "$extension$" >> "$AMPATH/.cache/rollback-args" + if ! grep -q "[0-9]" "$AMPATH"/.cache/rollback-args; then + echo " ERROR: No valid links found, sorry!" + exit + else + echo "-----------------------------------------------------------------------" + echo "You have chosen to roll back $2." + echo "Rollback will be done from https://github.com/$REPO" + echo "-----------------------------------------------------------------------" + printf "Select a URL from this menu (read carefully) or press CTRL+C to abort:\n-----------------------------------------------------------------------\n"; sleep 1; + select d in $(cat "$AMPATH/.cache/rollback-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done + cp "$APPSPATH"/$2/AM-updater "$APPSPATH"/$2/AM-rollback + sed -i 's/version0/#version0/g' "$APPSPATH"/$2/AM-rollback + sed -i '/show-progress/c\wget -q --show-progress '$d'' "$APPSPATH"/$2/AM-rollback + if test -f ./AM-rollback; then + if grep -q '/$APP/*.zsync' ./AM-rollback; then + mv "$APPSPATH"/$2/AM-rollback "$APPSPATH"/$2/AM-rollback.old + sed -n '1,6p' "$APPSPATH"/$2/AM-rollback.old >> "$APPSPATH"/$2/AM-rollback + sed -n '17,36p' "$APPSPATH"/$2/AM-rollback.old >> "$APPSPATH"/$2/AM-rollback + rm -f "$APPSPATH"/$2/AM-rollback.old + sed -i 's/ //g' "$APPSPATH"/$2/AM-rollback + chmod a+x "$APPSPATH"/$2/AM-rollback + fi + fi + "$APPSPATH"/$2/AM-rollback + rm -f "$APPSPATH"/$2/AM-rollback + rm -f "$APPSPATH"/$2/version + echo $d >> "$APPSPATH"/$2/version + rm -R -f "$AMPATH"/.cache/* + _list_updatable_apps + echo -e "\nROLLBACK SUCCESSFUL!" + exit + fi + else + echo " The option '$1' only works for https://github.com"; exit + fi + fi + else + echo ' No AM-updater available for '$2', cannot detect any URL!'; exit + fi +} + +############################################# +# FUNCTIONS TO PREVENT THE APPS TO BE UPDATED +############################################# + +function _do_lock() { + while [ -n "$1" ]; do + if test -f "$APPSPATH"/$2/AM-updater; then + case $2 in + *) + read -p " Do you wish to keep $2 at the current version (y,N)?" yn + case $yn in + [Yy]* ) + mv "$APPSPATH"/$2/AM-updater "$APPSPATH"/$2/AM-LOCK 1>/dev/null && + echo " $2 has been locked at current version!" + exit + ;; + [Nn]*|* ) + echo " Operation aborted!" + exit + ;; + esac + ;; + esac + else + echo -e '\n '"$(echo $AMCLI | tr a-z A-Z)"' cannot manage updates for '$2', "AM-updater" file not found!\n'; exit + exit + fi + done +} + +function _do_unlock() { + while [ -n "$1" ]; do + if test -f "$APPSPATH"/$2/AM-LOCK; then + case $2 in + *) + read -p " Do you wish to unlock updates for $2 (Y,n)?" yn + case $yn in + [Nn]* ) + echo " $2 is still locked at current version!" + exit + ;; + [Yy]*|* ) + mv "$APPSPATH"/$2/AM-LOCK "$APPSPATH"/$2/AM-updater 1>/dev/null + echo ' '$2' can now receive updates!' + exit + ;; + esac + ;; + esac + else + echo ' '$2' cannot be unlocked, "AM-LOCK" file not found!'; exit + fi + done +} + +################################################################ +# FUNCTIONS TO BACKUP/RESTORE THE INSTALLED APPS USING SNAPSHOTS +################################################################ + +function _backup() { + case $arg in + '') + echo " Specify the name of a program to back up"; echo ""; exit;; + *) + if test -f "$APPSPATH"/$arg/remove; then + echo ""; read -p " Do you wish to backup the current version of $arg (y,N)?" yn + case $yn in + [Yy]* ) + mkdir -p "$HOME/.am-snapshots/$arg" + cp -r "$APPSPATH"/$arg "$HOME/.am-snapshots/$arg/$(date +%F-%X | sed 's/://g' | sed 's/-//g')" + echo -e "\n SAVED in $HOME/.am-snapshots/$arg\n";; + [Nn]*|* ) + echo ""; echo " OPERATION ABORTED!"; echo "";; + esac + else + echo -e "\n '$arg' is not a valid argument or is not installed.\n" + fi + esac +} + +function _do_backup() { + while [ -n "$1" ]; do + rm -f $AMPATH/.cache/backup-args; + echo "$@" | tr ' ' '\n' >> $AMPATH/.cache/backup-args && echo STOP >> $AMPATH/.cache/backup-args; + ARGS=$(tail -n +2 $AMPATH/.cache/backup-args) + for arg in $ARGS; do + if [ $arg == STOP ]; then + exit + else + _backup + fi + done + done +} + +function _overwrite() { + case $arg in + '') + echo " Specify the name of a program to overwrite"; echo "";; + *) + if test -f "$APPSPATH"/$arg/remove; then + echo ""; read -p " Do you wish to overwrite this version of $arg with an old one (y,N)?" yn + case $yn in + [Yy]* ) + printf "\n Please, select a snapshot or press CTRL+C to abort:\n\n"; sleep 1; + select d in $HOME/.am-snapshots/$arg/*; do test -n "$d" && break; echo ">>> Invalid Selection"; done + cp -r --backup=t $d/* "$APPSPATH"/$arg/ + rm -R -f ./tmp "$APPSPATH"/$arg/*~ + echo -e "\n RESTORE COMPLETED SUCCESSFULLY!\n";; + [Nn]*|* ) + echo ""; echo " OPERATION ABORTED!"; echo "";; + esac + else + echo ""; echo " '$arg' is not a valid argument or is not installed."; echo "" + fi + esac +} + +function _do_overwrite() { + while [ -n "$1" ]; do + rm -f "$AMPATH"/.cache/overwrite-args + echo "$@" | tr ' ' '\n' >> "$AMPATH"/.cache/overwrite-args && echo STOP >> "$AMPATH"/.cache/overwrite-args + ARGS=$(tail -n +2 $AMPATH/.cache/overwrite-args) + for arg in $ARGS; do + if [ $arg == STOP ]; then + exit + else + _overwrite + fi + done + done +} + +############################################## +# FUNCTION TO CONVERT TYPE2 APPIMAGES TO TYPE3 +############################################## + +function _do_nolibfuse() { + cd "$APPSPATH" || exit 1 + if test -f ./$2/$2 2>/dev/null; then + cd ./$2 || return + if [ -z "$(strings -d "./$2" 2>/dev/null | grep -F 'if you run it with the --appimage-extract option')" ] 2>/dev/null; then + echo " ⚠️ Error: $(echo "${2}" | tr a-z A-Z) is NOT an AppImage." + exit + else + if [ -z "$(strings -d "./$2" 2>/dev/null | grep -F 'AppImages require FUSE to run')" ] 2>/dev/null; then + echo " β—† $(echo "${2}" | tr a-z A-Z) is already a Type3 AppImage." + exit + else + wget -q "$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/probonopd/go-appimage/releases | grep -v zsync | grep -i continuous | grep -i appimagetool | grep -i "$(uname -m)" | grep browser_download_url | cut -d '"' -f 4 | head -1)" -O appimagetool + chmod a+x ./appimagetool + echo -ne " ...extracting the AppImage\r" + ./$2 --appimage-extract 2> /dev/null | grep -v "squashfs-root" + echo -ne " ...trying to convert in Type3 AppImage\r" + chmod 0755 ./squashfs-root + ARCH="$(uname -m)" VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./squashfs-root > /dev/null 2> /dev/null + if test -f ./*.AppImage; then + _remove_info_files + mv ./"$2" ./"$2".old + mv ./*.AppImage ./"$2" + echo " β—† $(echo $2 | tr a-z A-Z) has been converted to Type3 AppImage." + rm -R -f ./appimagetool ./squashfs-root + if ! test -f ./*.zsync; then + echo " Note, your installed Appimage have not a .zsync file." + if test -f ./AM-updater; then + if ! grep -q 'nolibfuse' ./AM-updater; then + echo -e '\necho y | '$AMCLIPATH' nolibfuse $APP' >> ./AM-updater + echo " The next update may replace this AppImage with a Type2 one..." + echo ' ...so I added this command to the bottom of the "AM-updater" script!' + fi + fi + fi + echo -e " Contact the upstream developers to make them officially switch to Type3!\n" + read -p " Do you wish to remove the old Type2 AppImage (Y,n)?" yn + case $yn in + [Nn]* ) + exit + ;; + [Yy]*|* ) + rm -R -f ./$2.old + exit + ;; + esac + else + metainfodir=$(find ./squashfs-root -type d -name metainfo | grep "share/metainfo" | head -1) + if [ -z "$metainfodir" ]; then + echo " πŸ’€Errors while trying to export $(echo "${2}" | tr a-z A-Z) from Type2 AppImage. Aborted." + rm -R -f ./appimagetool ./squashfs-root + exit + else + cd "$metainfodir" || return + rm -R -f ./*.xml + cd - > /dev/null || return + fi + echo -ne " ...found Appstream errors, I'm trying to fix them...\r" + ARCH="$(uname -m)" VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./squashfs-root > /dev/null 2> /dev/null + if test -f ./*.AppImage; then + _remove_info_files + mv ./"$2" ./"$2".old + mv ./*.AppImage ./"$2" + echo " β—† $(echo $2 | tr a-z A-Z) has been converted to Type3 AppImage." + if test -f ./*.zsync; then + echo 'However, when trying again I had to remove some files to update with "zsync".' + else + if test -f ./AM-updater; then + if ! grep -q 'nolibfuse' ./AM-updater; then + echo -e '\necho y | '$AMCLIPATH' nolibfuse $APP' >> ./AM-updater + echo " The next update may replace this AppImage with a Type2 one..." + echo ' ...so I added this command to the bottom of the "AM-updater" script!' + fi + fi + fi + echo -e " Contact the upstream developers to make them officially switch to Type3!\n" + rm -R -f ./appimagetool ./squashfs-root + read -p " Do you wish to remove the old one (Y,n)?" yn + case $yn in + [Nn]* ) + exit + ;; + [Yy]*|* ) + rm -R -f ./$2.old + exit + ;; + esac + else + echo " πŸ’€Errors while trying to export $(echo $2 | tr a-z A-Z) from Type2 AppImage. Aborted." + rm -R -f ./appimagetool ./squashfs-root; exit + fi + fi + fi + fi + else + echo " ⚠️ Error: \"$(echo "${2}" | tr a-z A-Z)\" is NOT installed." + exit + fi +} + +################################## +# OPTIONS AVAILABLE IN THIS MODULE +################################## + +case "$1" in + '-b'|'backup') # DO A BACKUP OF AN INSTALLED APPLICATION + _do_backup "${@}" + shift + ;; + + '-o'|'overwrite') # OVERWRITE A NEW VERSION WITH THE PREVIOUS ONE FROM A BACKUP DONE WITH THE PREVIOUS OPTION + _do_overwrite "${@}" + shift + ;; + + '-R') # THIS OPTION REMOVES PROGRAMS WITHOUT ASKING + while [ -n "$1" ]; do + rm -f "$AMPATH"/.cache/remove-args + echo "$@" | tr ' ' '\n' >> "$AMPATH"/.cache/remove-args && echo STOP >> "$AMPATH"/.cache/remove-args + ARGS=$(tail -n +2 "$AMPATH"/.cache/remove-args) + for arg in $ARGS; do + if [ $arg == STOP ]; then + _remove_check_removals + else + _REMOVE + _remove_info_files + fi + done + done + shift + ;; + + '-r'|'remove') # THIS OPTION ALLOWS YOU TO CHOOSE WHETHER TO REMOVE PROGRAMS OR NOT + while [ -n "$1" ]; do + rm -f "$AMPATH"/.cache/remove-args + echo "$@" | tr ' ' '\n' >> "$AMPATH"/.cache/remove-args && echo STOP >> "$AMPATH"/.cache/remove-args + ARGS=$(tail -n +2 "$AMPATH"/.cache/remove-args) + for arg in $ARGS; do + if [ $arg == STOP ]; then + _remove_check_removals + else + _remove + _remove_info_files + fi + done + done + shift + ;; + + '--rollback') # THIS OPTION ALLOWS YOU TO DOWNGRADE THE INSTALLED APP TO A PREVIOUS VERSION, IF EXISTS + _online_check + while [ -n "$1" ]; do + _do_rollback "${@}" + done + shift + ;; + + 'lock') # LOCK THE INSTALLED VERSION + _do_lock "${@}" + shift + ;; + + 'nolibfuse') # CONVERT TYPE2 APPIMAGES TO TYPE2 + _online_check + while [ -n "$1" ]; do + _do_nolibfuse "${@}" + done + shift + ;; + + 'unlock') # REVERT THE OPTION "lock" ABOVE + _do_unlock "${@}" + shift + ;; +esac diff --git a/modules/no-updates.am b/modules/no-updates.am deleted file mode 100644 index 3ffd4b0e4..000000000 --- a/modules/no-updates.am +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env bash -# shellcheck disable=SC2086 -# THIS MODULE BRINGS WITH IT ALL THOSE OPTIONS THAT ALLOWS YOU TO LOCK/UNLOCK/BACKUP/RESTORE THE VERSION OF A PROGRAM - -function _do_lock() { - while [ -n "$1" ]; do - if test -f $APPSPATH/$2/AM-updater; then - case $2 in - *) - read -p " Do you wish to keep $2 at the current version (y,N)?" yn - case $yn in - [Yy]* ) - mv $APPSPATH/$2/AM-updater $APPSPATH/$2/AM-LOCK 1>/dev/null && - echo " $2 has been locked at current version!" - exit - ;; - [Nn]*|* ) - echo " Operation aborted!" - exit - ;; - esac - ;; - esac - else - echo -e '\n '"$(echo $AMCLI | tr a-z A-Z)"' cannot manage updates for '$2', "AM-updater" file not found!\n'; exit - exit - fi - done -} - -function _do_unlock() { - while [ -n "$1" ]; do - if test -f $APPSPATH/$2/AM-LOCK; then - case $2 in - *) - read -p " Do you wish to unlock updates for $2 (Y,n)?" yn - case $yn in - [Nn]* ) - echo " $2 is still locked at current version!" - exit - ;; - [Yy]*|* ) - mv $APPSPATH/$2/AM-LOCK $APPSPATH/$2/AM-updater 1>/dev/null - echo ' '$2' can now receive updates!' - exit - ;; - esac - ;; - esac - else - echo ' '$2' cannot be unlocked, "AM-LOCK" file not found!'; exit - fi - done -} - - - -function _backup() { - case $arg in - '') - echo " Specify the name of a program to back up"; echo ""; exit;; - *) - if test -f $APPSPATH/$arg/remove; then - echo ""; read -p " Do you wish to backup the current version of $arg (y,N)?" yn - case $yn in - [Yy]* ) - mkdir -p "$HOME/.am-snapshots/$arg" - cp -r $APPSPATH/$arg "$HOME/.am-snapshots/$arg/$(date +%F-%X | sed 's/://g' | sed 's/-//g')" - echo -e "\n SAVED in $HOME/.am-snapshots/$arg\n";; - [Nn]*|* ) - echo ""; echo " OPERATION ABORTED!"; echo "";; - esac - else - echo -e "\n '$arg' is not a valid argument or is not installed.\n" - fi - esac -} - -function _do_backup() { - while [ -n "$1" ]; do - rm -f $AMPATH/.cache/backup-args; - echo "$@" | tr ' ' '\n' >> $AMPATH/.cache/backup-args && echo STOP >> $AMPATH/.cache/backup-args; - ARGS=$(tail -n +2 $AMPATH/.cache/backup-args) - for arg in $ARGS; do - if [ $arg == STOP ]; then - exit - else - _backup - fi - done - done -} - -function _overwrite() { - case $arg in - '') - echo " Specify the name of a program to overwrite"; echo "";; - *) - if test -f $APPSPATH/$arg/remove; then - echo ""; read -p " Do you wish to overwrite this version of $arg with an old one (y,N)?" yn - case $yn in - [Yy]* ) - printf "\n Please, select a snapshot or press CTRL+C to abort:\n\n"; sleep 1; - select d in $HOME/.am-snapshots/$arg/*; do test -n "$d" && break; echo ">>> Invalid Selection"; done - cp -r --backup=t $d/* $APPSPATH/$arg/ - rm -R -f ./tmp $APPSPATH/$arg/*~ - echo -e "\n RESTORE COMPLETED SUCCESSFULLY!\n";; - [Nn]*|* ) - echo ""; echo " OPERATION ABORTED!"; echo "";; - esac - else - echo ""; echo " '$arg' is not a valid argument or is not installed."; echo "" - fi - esac -} - -function _do_overwrite() { - while [ -n "$1" ]; do - rm -f $AMPATH/.cache/overwrite-args - echo "$@" | tr ' ' '\n' >> $AMPATH/.cache/overwrite-args && echo STOP >> $AMPATH/.cache/overwrite-args - ARGS=$(tail -n +2 $AMPATH/.cache/overwrite-args) - for arg in $ARGS; do - if [ $arg == STOP ]; then - exit - else - _overwrite - fi - done - done -} - -case $2 in - '') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit;; -esac - -case "$1" in - 'lock') # LOCK THE INSTALLED VERSION - _do_lock "${@}" - shift - ;; - 'unlock') # REVERT THE OPTION "lock" ABOVE - _do_unlock "${@}" - shift - ;; - '-b'|'backup') # DO A BACKUP OF AN INSTALLED APPLICATION - _do_backup "${@}" - shift - ;; - '-o'|'overwrite') # OVERWRITE A NEW VERSION WITH THE PREVIOUS ONE FROM A BACKUP DONE WITH THE PREVIOUS OPTION - _do_overwrite "${@}" - shift - ;; -esac diff --git a/modules/nolibfuse.am b/modules/nolibfuse.am deleted file mode 100644 index 19e7803dd..000000000 --- a/modules/nolibfuse.am +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash -# shellcheck disable=SC2086 - -function _echo_lower() { - echo "${2}" | tr a-z A-Z -} - -while [ -n "$1" ]; do - case "${2}" in - '') - echo " USAGE: $AMCLI $1 [PROGRAM]"; exit - ;; - *) - cd "$APPSPATH" || exit 1 - if test -f ./$2/$2 2>/dev/null; then - cd ./$2 || return - if [ -z "$(strings -d "./$2" 2>/dev/null | grep -F 'if you run it with the --appimage-extract option')" ] 2>/dev/null; then - echo " ⚠️ Error: $(_echo_lower) is NOT an AppImage." - exit - else - if [ -z "$(strings -d "./$2" 2>/dev/null | grep -F 'AppImages require FUSE to run')" ] 2>/dev/null; then - echo " β—† $(_echo_lower) is already a Type3 AppImage." - exit - else - wget -q "$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/probonopd/go-appimage/releases | grep -v zsync | grep -i continuous | grep -i appimagetool | grep -i "$(uname -m)" | grep browser_download_url | cut -d '"' -f 4 | head -1)" -O appimagetool - chmod a+x ./appimagetool - echo -ne " ...extracting the AppImage\r" - ./$2 --appimage-extract 2> /dev/null | grep -v "squashfs-root" - echo -ne " ...trying to convert in Type3 AppImage\r" - chmod 0755 ./squashfs-root - ARCH="$(uname -m)" VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./squashfs-root > /dev/null 2> /dev/null - if test -f ./*.AppImage; then - _remove_info_files - mv ./"$2" ./"$2".old - mv ./*.AppImage ./"$2" - echo " β—† $(echo $2 | tr a-z A-Z) has been converted to Type3 AppImage." - rm -R -f ./appimagetool ./squashfs-root - if ! test -f ./*.zsync; then - echo " Note, your installed Appimage have not a .zsync file." - if test -f ./AM-updater; then - if ! grep -q 'nolibfuse' ./AM-updater; then - echo -e '\necho y | '$AMCLIPATH' nolibfuse $APP' >> ./AM-updater - echo " The next update may replace this AppImage with a Type2 one..." - echo ' ...so I added this command to the bottom of the "AM-updater" script!' - fi - fi - fi - echo -e " Contact the upstream developers to make them officially switch to Type3!\n" - read -p " Do you wish to remove the old Type2 AppImage (Y,n)?" yn - case $yn in - [Nn]* ) - exit - ;; - [Yy]*|* ) - rm -R -f ./$2.old - exit - ;; - esac - else - metainfodir=$(find ./squashfs-root -type d -name metainfo | grep "share/metainfo" | head -1) - if [ -z "$metainfodir" ]; then - echo " πŸ’€Errors while trying to export $(_echo_lower) from Type2 AppImage. Aborted." - rm -R -f ./appimagetool ./squashfs-root - exit - else - cd "$metainfodir" || return - rm -R -f ./*.xml - cd - > /dev/null || return - fi - echo -ne " ...found Appstream errors, I'm trying to fix them...\r" - ARCH="$(uname -m)" VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./squashfs-root > /dev/null 2> /dev/null - if test -f ./*.AppImage; then - _remove_info_files - mv ./"$2" ./"$2".old - mv ./*.AppImage ./"$2" - echo " β—† $(echo $2 | tr a-z A-Z) has been converted to Type3 AppImage." - if test -f ./*.zsync; then - echo 'However, when trying again I had to remove some files to update with "zsync".' - else - if test -f ./AM-updater; then - if ! grep -q 'nolibfuse' ./AM-updater; then - echo -e '\necho y | '$AMCLIPATH' nolibfuse $APP' >> ./AM-updater - echo " The next update may replace this AppImage with a Type2 one..." - echo ' ...so I added this command to the bottom of the "AM-updater" script!' - fi - fi - fi - echo -e " Contact the upstream developers to make them officially switch to Type3!\n" - rm -R -f ./appimagetool ./squashfs-root - read -p " Do you wish to remove the old one (Y,n)?" yn - case $yn in - [Nn]* ) - exit - ;; - [Yy]*|* ) - rm -R -f ./$2.old - exit - ;; - esac - else - echo " πŸ’€Errors while trying to export $(echo $2 | tr a-z A-Z) from Type2 AppImage. Aborted." - rm -R -f ./appimagetool ./squashfs-root; exit - fi - fi - fi - fi - else - echo " ⚠️ Error: "$(_echo_lower)" is NOT installed." - exit - fi - ;; - esac -done - -shift diff --git a/modules/remove.am b/modules/remove.am deleted file mode 100644 index c3040d8e0..000000000 --- a/modules/remove.am +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash - -case $2 in - '') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit;; -esac - -function _remove_check_removals() { - if test -f "$AMPATH"/.cache/unavailable-args; then - echo -e "-----------------------------------------------------------------------\n" - if [ $AMCLI == am ] 2>/dev/null; then - echo -e " πŸ’€ ERROR, the following programs you want to remove are NOT in $APPSPATH :\n\n$(cat "$AMPATH"/.cache/unavailable-args | sort)" - else - echo -e " πŸ’€ ERROR, the following programs you want to remove are NOT in\n $APPSPATH :\n\n$(cat "$AMPATH"/.cache/unavailable-args | sort)" - fi - echo -e '\n INVALID "APPNAME"!' - echo -e "\n-----------------------------------------------------------------------\n" - echo ' β—† INSTALLED PROGRAMS/VALID ARGUMENTS (SEE THE "APPNAME" COLUMN):' - $AMCLIPATH -f | grep -v "STANDALONE PROGRAMS MANAGED"; rm "$AMPATH"/.cache/unavailable-args - echo -e "-----------------------------------------------------------------------" - exit - else - exit - fi -} - -function _REMOVE() { - if ls $APPSPATH/$arg > /dev/null 2>&1; then - $SUDOCOMMAND $APPSPATH/$arg/remove && sleep 0.5 && echo ' β—† "'"$(echo $arg | tr a-z A-Z)"'" HAS BEEN SUCCESSFULLY REMOVED!' - else - echo " - $arg" >> "$AMPATH"/.cache/unavailable-args - fi -} - -function _remove() { - if ls $APPSPATH/$arg > /dev/null 2>&1; then - case $arg in - *) - $SUDOCOMMAND echo "" > /dev/null; read -p ' β—† DO YOU WISH TO REMOVE "'"$(echo $arg | tr a-z A-Z)"'" (Y,n)?' yn - case $yn in - [Nn]* ) - echo ' - "'"$(echo $arg | tr a-z A-Z)"'" HAS NOT BEEN REMOVED!'; echo "";; - [Yy]*|* ) - $SUDOCOMMAND $APPSPATH/$arg/remove && sleep 0.5 && echo ' β—† "'"$(echo $arg | tr a-z A-Z)"'" HAS BEEN SUCCESSFULLY REMOVED!';; - esac - esac - else - echo " - $arg" >> "$AMPATH"/.cache/unavailable-args - fi -} - -case "$1" in - - '-R') # THIS OPTION REMOVES PROGRAMS WITHOUT ASKING - while [ -n "$1" ]; do - rm -f "$AMPATH"/.cache/remove-args - echo "$@" | tr ' ' '\n' >> "$AMPATH"/.cache/remove-args && echo STOP >> "$AMPATH"/.cache/remove-args - ARGS=$(tail -n +2 "$AMPATH"/.cache/remove-args) - - for arg in $ARGS; do - - if [ $arg == STOP ]; then - _remove_check_removals - else - _REMOVE - _remove_info_files - fi - done - done - - shift - ;; - - '-r'|'remove') # THIS OPTION ALLOWS YOU TO CHOOSE WHETHER TO REMOVE PROGRAMS OR NOT - while [ -n "$1" ]; do - rm -f "$AMPATH"/.cache/remove-args - echo "$@" | tr ' ' '\n' >> "$AMPATH"/.cache/remove-args && echo STOP >> "$AMPATH"/.cache/remove-args - ARGS=$(tail -n +2 "$AMPATH"/.cache/remove-args) - - for arg in $ARGS; do - - if [ $arg == STOP ]; then - _remove_check_removals - else - _remove - _remove_info_files - fi - done - done - - shift - ;; -esac diff --git a/modules/rollback.am b/modules/rollback.am deleted file mode 100644 index 108af6513..000000000 --- a/modules/rollback.am +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -case $2 in -'') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit;; -esac - -while [ -n "$1" ]; do - if test -f $APPSPATH/$2/AM-updater; then - if test -f $APPSPATH/$2/$2-rollback; then - cd $APPSPATH/$2 || return - ./$2-rollback - exit - elif test -f $APPSPATH/$2/*.zsync; then - echo " AppImage packages updatable with zsync have not previous versions."; exit - elif test -f $APPSPATH/$2/updater; then - echo ' When an executable called "updater" is available, the app is only updateable.'; exit - else - if grep -q "api.github.com" $APPSPATH/$2/AM-updater; then - rm -f "$AMPATH/.cache/rollback-args"; - extension=$(cat $APPSPATH/$2/version | tr '.' '\n' | tail -1) - REPO=$(grep -i "REPO=" $APPSPATH/$2/AM-updater | grep -o -P '(?<=").*(?=")') - printf "%s\n" "$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/$REPO/releases?per_page=100 \ - | grep browser_download_url | cut -d '"' -f 4)" | tr ' ' '\n' | grep -i "$extension$" >> "$AMPATH/.cache/rollback-args" - if ! grep -q "[0-9]" $AMPATH/.cache/rollback-args; then - echo " ERROR: No valid links found, sorry!" - exit - else - echo "-----------------------------------------------------------------------" - echo "You have chosen to roll back $2." - echo "Rollback will be done from https://github.com/$REPO" - echo "-----------------------------------------------------------------------" - printf "Select a URL from this menu (read carefully) or press CTRL+C to abort:\n-----------------------------------------------------------------------\n"; sleep 1; - select d in $(cat "$AMPATH/.cache/rollback-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done - cp $APPSPATH/$2/AM-updater $APPSPATH/$2/AM-rollback - sed -i 's/version0/#version0/g' $APPSPATH/$2/AM-rollback - sed -i '/show-progress/c\wget -q --show-progress '$d'' $APPSPATH/$2/AM-rollback - if grep -q '/$APP/*.zsync' ./AM-rollback; then - mv $APPSPATH/$2/AM-rollback $APPSPATH/$2/AM-rollback.old - sed -n '1,6p' $APPSPATH/$2/AM-rollback.old >> $APPSPATH/$2/AM-rollback - sed -n '17,36p' $APPSPATH/$2/AM-rollback.old >> $APPSPATH/$2/AM-rollback - rm -f $APPSPATH/$2/AM-rollback.old - sed -i 's/ //g' $APPSPATH/$2/AM-rollback - chmod a+x $APPSPATH/$2/AM-rollback - fi - $APPSPATH/$2/AM-rollback - rm -f $APPSPATH/$2/AM-rollback - rm -f $APPSPATH/$2/version - echo $d >> $APPSPATH/$2/version - echo -e "\nROLLBACK SUCCESSFUL!" - exit - fi - else - echo " The option '$1' only works for https://github.com"; exit - fi - fi - else - echo ' No AM-updater available for '$2', cannot detect any URL!'; exit - fi -done - -shift diff --git a/modules/sandboxes.am b/modules/sandboxes.am index 109c426a7..bebfc2a58 100644 --- a/modules/sandboxes.am +++ b/modules/sandboxes.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +############################################################################################## +# THIS MODULE INCLUDES ALL ACTIONS INTENDED TO ISOLATE DOTFILES OR CONTAINERIZE INSTALLED APPS +############################################################################################## + # Set a dedicated .home directory for a selected AppImage function _home() { cd $APPSPATH || return diff --git a/modules/template.am b/modules/template.am index 757ae6c28..9abc1d084 100644 --- a/modules/template.am +++ b/modules/template.am @@ -1,5 +1,9 @@ #!/usr/bin/env bash +########################################################################## +# THIS MODULE IS USED TO CREATE INSTALLATION SCRIPS TO ADD TO THE DATABASE +########################################################################## + case $2 in '') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit;; esac