Skip to content

Commit

Permalink
Merge pull request #842 from ivan-hc/dev
Browse files Browse the repository at this point in the history
"AM" 7.6.1: lists improvements
  • Loading branch information
ivan-hc authored Aug 13, 2024
2 parents dd5cac6 + 66ea254 commit d623ca5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 88 deletions.
2 changes: 1 addition & 1 deletion APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="7.6"
AMVERSION="7.6.1"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,15 +889,21 @@ appman -f --less

__________________________________________________________________________
### List and query all the applications available on the database
Options `-l` or `list` shows the whole list of apps available in this repository.
Option `-l` or `list` shows the whole list of apps available in this repository.

This option uses `less` to show the list, so to exit its enough to press "**Q**".

If the option `-l` is followed by `--appimages`, you will be able to see only the available AppImages.

https://github.com/user-attachments/assets/fddc1a95-88ea-4b03-9fe8-1a69ed11e6eb

Option `-q` or `query` shows search results from the list above.

https://github.com/ivan-hc/AM/assets/88724353/2ac875df-5210-4d77-91d7-24c45eceaa2b
If followed by `--appimages`, the search results will be only for the available AppImages.

From version 7.5 it is possible to add the `--appimages` option to list only the AppImages.
If followed by `--pkg`, all keywords will be listed also if not on the same line. This is good if you are looking for multiple packages.

https://github.com/user-attachments/assets/864e95dd-0f69-4b8b-b6b3-289af3610aac
https://github.com/user-attachments/assets/2586fbae-4b40-4882-b15b-cf5f29a7b0d7

------------------------------------------------------------------------

Expand Down
173 changes: 90 additions & 83 deletions modules/database.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
# THIS MODULE INCLUDES ALL THE ACTIONS INTENDED FOR THE MANAGEMENT OF LISTS AND SINGLE PAGES
############################################################################################

_clean_lists_and_queries() {
# Remove references to URLs, "-a" elements in "-l" and "-q"
sed -E 's#(http|https|ftp)://[^ ]*##g; s#(SITE|SOURCE):##g'
}
# FUNCTIONS RELATED TO "ABOUT"

_download_markdown() {
_about_download_markdown() {
disk_usage=""
app_version=""
markdown_url="$AMCATALOGUEMARKDOWNS/${1}.md"
Expand All @@ -23,22 +20,18 @@ _download_markdown() {
printf ' PACKAGE: %s\n' "$package_name" | tr '[:lower:]' '[:upper:]'
if [ -f "$APPSPATH/$1/remove" ]; then
disk_usage=$(du -sm "$APPSPATH/$1" | cut -f1)
app_version=$(cat "$AMCACHEDIR"/version-args 2>/dev/null | grep -w "$1 |" | sed 's:.*| ::')
app_version=$(grep -w "$1 |" "$AMCACHEDIR"/version-args 2>/dev/null | sed 's:.*| ::')
app_status=$(printf " STATUS: INSTALLED, ABOUT $disk_usage MB OF DISK SPACE IN USE\n VERSION: $app_version")
fi
printf '%s\n' "$app_status"
cat -s "$cache_dir/$1.md"
if [ -z "$cache_dir" ]; then
exit 1
fi
rm -R -f "$cache_dir"

[ -n "$cache_dir" ] && rm -R -f "$cache_dir"
else
printf ' "%s" IS NOT A VALID ARGUMENT\n' "$package_name"
fi
}

_generate_3rd_party() {
_about_generate_3rd_party() {
disk_usage=""
app_version=""
app_status=" STATUS: NOT INSTALLED"
Expand All @@ -47,7 +40,7 @@ _generate_3rd_party() {
printf ' PACKAGE: %s\n' "$arg" | tr '[:lower:]' '[:upper:]'
if [ -f "$APPSPATH/$1/remove" ]; then
disk_usage=$(du -sm "$APPSPATH/$1" | cut -f1)
app_version=$(cat "$AMCACHEDIR"/version-args 2>/dev/null | grep -w "$1 |" | sed 's:.*| ::')
app_version=$(grep -w "$1 |" "$AMCACHEDIR"/version-args 2>/dev/null | sed 's:.*| ::')
app_status=$(printf " STATUS: INSTALLED, ABOUT $disk_usage MB OF DISK SPACE IN USE\n VERSION: $app_version")
fi
printf '%s\n' "$app_status"
Expand All @@ -57,7 +50,7 @@ _generate_3rd_party() {
fi
}

_download_lib() {
_about_download_lib() {
printf "%s\n" " LIBRARY: $1" | tr '[:lower:]' '[:upper:]'
if [ -f "$APPSPATH/$1/remove" ]; then
disk_usage=$(find /usr/local/lib -type f -name "$(echo "$1" | sed -e "s/[0-9]//")*" -exec du -sm {} + | tr ' ' '\n' | head -1)
Expand All @@ -66,130 +59,144 @@ _download_lib() {
printf "%s\n" " STATUS: NOT INSTALLED"
fi
echo ""
grep "$1 : " "$AMPATH/libs-list" | sed 's#.*:##' | sed 's/(/\n (/g'
echo "" && echo " SITE/SOURCES:" && echo ""
grep "$1 : " "$AMPATH/libs-list" | sed 's#.*:##; s/(/\n (/g'
printf '\n%s\n\n' " SITE/SOURCES:"
site_source=$(wget -qO- "$APPSDB/$1" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | head -1)
echo " $site_source"
echo ""
}

#--------------------------------------------------------------------------
# FUNCTIONS RELATED TO "LIST" AND "QUERY"

_pretty_list() {
# Remove references to URLs, "-a" elements in "-l" and "-q"
sed -E 's#(http|https|ftp)://[^ ]*##g; s#(SITE|SOURCE):##g; s/^/\n/g' \
| _colors | fold -sw 79 | sed 's/^/ /g; s/ ◆ /◆ /g; s/ */ /g'
}

_pretty_list_compat() {
# Remove references to URLs, "-a" elements in "-l" and "-q"
sed -E 's#(http|https|ftp)://[^ ]*##g; s#(SITE|SOURCE):##g' \
| _colors | fold -sw 79 | sed 's/^/ /g; s/ ◆ /◆ /g; s/ */ /g'
}

_colors() {
awk '{
printf "%s \033[32m%s\033[0m", $1, $2
{$1 = ""; $2 = ""; print $0;}
}'
}

_list() {
LIBNUMBER=$(cat "$APPSPATH/*/remove" 2> /dev/null | grep "usr/local/lib" | wc -l)
# Check the number of installed apps and libraries
LIBNUMBER=$(grep "usr/local/lib" "$APPSPATH"/*/remove 2> /dev/null | wc -l)
ITEMSNUMBER=$(cd "$APPSPATH" && find -name 'remove' -printf "%h\n" 2>/dev/null | sort -u | wc -l)
if [ "$AMCLI" = am ]; then
ITEMSNUMBER=$(("$ITEMSNUMBER"-1))
if test -f /opt/am/remove; then
ITEMSNUMBER=$(("$ITEMSNUMBER"-1))
fi
fi
APPSNUMBER=$(echo "$(("$ITEMSNUMBER" - "$LIBNUMBER"))")
APPSNUMBER=$(("$ITEMSNUMBER" - "$LIBNUMBER"))
# Determine the number of available apps from the list
AVAILABLE_APPS_NUMBER=$(grep -e "$" -c "$AMPATH/$arch-apps")
# Generate a list of the installed apps with version
if test -f "$AMCACHEDIR"/version-args; then
INSTALLED=$(cat "$AMCACHEDIR"/version-args 2>/dev/null | sort | sed 's/ | / /g' | grep -v "◆ am ")
INSTALLED=$(sort "$AMCACHEDIR"/version-args 2>/dev/null | sed 's/ | / /g' | grep -v "◆ am ")
MESSAGE2="\n$INSTALLED\n"
else
_check_version
INSTALLED=$(cat "$AMCACHEDIR"/version-args 2>/dev/null | sort | sed 's/ | / /g' | grep -v "◆ am ")
INSTALLED=$(sort "$AMCACHEDIR"/version-args 2>/dev/null | sed 's/ | / /g' | grep -v "◆ am ")
MESSAGE2="\n$INSTALLED\n"
fi

# Check if github.com is online, if not, the function will read the offline list
wget -q --tries=10 --timeout=20 --spider https://github.com && _completion_lists
if cat "$APPSPATH/*/remove" 2> /dev/null | grep -q "usr/local/lib"; then
# Check if among the installed apps are available libraries
if [ "$LIBNUMBER" != 0 ]; then
# Check if the installed libraries are more than one
if [ "$LIBNUMBER" = 1 ]; then
MESSAGE=$(echo " YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $(grep -e "$" -c $AMPATH/$arch-apps) AVAILABLE, AND $LIBNUMBER LIBRARY")
MESSAGE=" YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $AVAILABLE_APPS_NUMBER AVAILABLE, AND $LIBNUMBER LIBRARY"
else
MESSAGE=$(echo " YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $(grep -e "$" -c $AMPATH/$arch-apps) AVAILABLE, AND $LIBNUMBER LIBRARIES")
MESSAGE=" YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $AVAILABLE_APPS_NUMBER AVAILABLE, AND $LIBNUMBER LIBRARIES"
fi
else
MESSAGE=$(echo " YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $(grep -e "$" -c $AMPATH/$arch-apps) AVAILABLE")
MESSAGE=" YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $AVAILABLE_APPS_NUMBER AVAILABLE"
fi
}

# Define functions
usage() {
echo " USAGE: $AMCLI $1 [ARGUMENT]"
_list_appimages() {
# Determine the number of available apps
if ! test -f "$AMCACHEDIR/$arch-appimages"; then
_online_check && curl -Ls "$AMREPO/programs/$arch-appimages" > "$AMCACHEDIR/$arch-appimages"
fi
AVAILABLE_APPIMAGES_NUMBER=$(grep -e "$" -c "$AMCACHEDIR/$arch-appimages")
}

#--------------------------------------------------------------------------
# OPTIONS

case "$1" in
'-a'|'about')
[ -z "$2" ] && echo " USAGE: $AMCLI $1 [ARGUMENT]" && exit 1
_online_check
case $2 in
'')
echo " USAGE: $AMCLI $1 [ARGUMENT]"
exit
;;
esac
if ! test -f "$AMCACHEDIR"/version-args; then
_check_version
fi

# Main logic
if [ ! -f "$AMPATH/libs-list" ]; then
wget -q "$LIBSLISTDB" -P "$AMPATH"
fi

# Skip the first argument which is not part of ARGS
for arg in "${@:2}"; do
[ ! -f "$AMCACHEDIR"/version-args ] && _check_version
[ ! -f "$AMPATH/libs-list" ] && wget -q "$LIBSLISTDB" -P "$AMPATH"
ARGS="$(echo "$@" | cut -f2- -d ' ')" # Removes first argument
for arg in $ARGS; do
if curl -o /dev/null -sIf "$AMCATALOGUEMARKDOWNS/${arg}.md" 1>/dev/null; then
_download_markdown "$arg"
_about_download_markdown "$arg"
elif grep -q "$arg : " "$AMPATH/$arch-apps"; then
_generate_3rd_party
_about_generate_3rd_party "$arg"
elif grep -q "$arg : " "$AMPATH/libs-list"; then
_download_lib "$arg"
_about_download_lib "$arg"
else
printf '%s is not a valid argument\n' " $arg" | tr '[:lower:]' '[:upper:]'
fi
printf "%s\n" "-----------------------------------------------------------------------"
printf "%s\n\n" "-----------------------------------------------------------------------"
done
;;

'-l'|'list')
_list
if [ "$2" = --appimages ]; then
if test -f "$AMCACHEDIR/$arch-appimages"; then
printf "\n$MESSAGE\n$MESSAGE2\n LIST OF THE $(grep -e "$" -c "$AMCACHEDIR/$arch-appimages") APPIMAGES AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(fold -sw 81 "$AMCACHEDIR/$arch-appimages" | _clean_lists_and_queries)\n" | less -I
printf "\n$MESSAGE\n$MESSAGE2\n"
else
_online_check
curl -Ls "$AMREPO/programs/$arch-appimages" > "$AMCACHEDIR/$arch-appimages"
printf "\n$MESSAGE\n$MESSAGE2\n LIST OF THE $(grep -e "$" -c "$AMCACHEDIR/$arch-appimages") APPIMAGES AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(fold -sw 81 "$AMCACHEDIR/$arch-appimages" | _clean_lists_and_queries)\n" | less -I
printf "\n$MESSAGE\n$MESSAGE2\n"
fi
_list_appimages
LIST=$(sort "$AMCACHEDIR/$arch-appimages" | _pretty_list)
printf "\n$MESSAGE\n$MESSAGE2\n LIST OF THE $AVAILABLE_APPIMAGES_NUMBER APPIMAGES AVAILABLE IN THE 'AM' REPOSITORY:\n$LIST\n" | less -Ir
else
printf "\n$MESSAGE\n$MESSAGE2\n LIST OF THE $(grep -e "$" -c "$AMPATH/$arch-apps") APPLICATIONS AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(fold -sw 81 "$AMPATH/$arch-apps" | _clean_lists_and_queries)\n" | less -I
printf "\n$MESSAGE\n$MESSAGE2\n"
LIST=$(sort "$AMPATH/$arch-apps" | _pretty_list)
printf "\n$MESSAGE\n$MESSAGE2\n LIST OF THE $AVAILABLE_APPS_NUMBER APPLICATIONS AVAILABLE IN THE 'AM' REPOSITORY:\n$LIST\n" | less -Ir
fi
#printf "\n$MESSAGE\n$MESSAGE2\n"
;;

'-q'|'query')
case $2 in
'')
echo " USAGE: $AMCLI $1 [ARGUMENT]"
exit
;;
esac
if [ -z "$2" ]; then
echo " USAGE: $AMCLI $1 [ARGUMENT]"
echo " $AMCLI $1 --appimages [ARGUMENT]"
echo " $AMCLI $1 --pkg [ARGUMENT]"; exit 1
fi
wget -q --tries=10 --timeout=20 --spider https://github.com && _completion_lists
if [ "$2" = --pkg ]; then
ARGS=$(echo "$@" | cut -f3- -d ' ' | sed 's/ /, /g')
ARGS="$(echo "$@" | cut -f3- -d ' ' | tr -s ' ' '|')"
printf "\n Search results for packages: $ARGS\n\n" | tr '[:lower:]' '[:upper:]'
grep -i -E "$(echo "$@" | cut -f3- -d ' ' | tr -s ' ' '|')" "$AMPATH/$arch-apps" --color=always | _clean_lists_and_queries | fold -sw 81
grep -i -E "$(echo "$@" | cut -f3- -d ' ' | tr -s ' ' '|')" "$AMPATH/libs-list" --color=always | _clean_lists_and_queries | fold -sw 81
echo ""
exit 0
fi
if [ "$2" = --appimages ]; then
ARGS=$(echo "$@" | cut -f3- -d ' ')
grep -iE "$ARGS" "$AMPATH/$arch-apps" --color=always | _pretty_list_compat
grep -iE "$ARGS" "$AMPATH/libs-list" --color=always | _pretty_list_compat
elif [ "$2" = --appimages ]; then
ARGS="$(echo "$@" | cut -f3- -d ' ')"
printf "\n Search results for \"$ARGS\":\n\n" | tr '[:lower:]' '[:upper:]'
PATTERN="$(echo "$@" | cut -f3- -d ' ' | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
PATTERN="$(echo "$ARGS" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
if ! test -f "$AMCACHEDIR/$arch-appimages"; then
_online_check
curl -Ls "$AMREPO/programs/$arch-appimages" > "$AMCACHEDIR/$arch-appimages"
fi
grep -P -i "$PATTERN" "$AMCACHEDIR/$arch-appimages" | _clean_lists_and_queries | fold -sw 81
grep -Pi "$PATTERN" "$AMCACHEDIR/$arch-appimages" | _pretty_list_compat
else
ARGS=$(echo "$@" | cut -f2- -d ' ')
ARGS="$(echo "$@" | cut -f2- -d ' ')"
printf "\n Search results for \"$ARGS\":\n\n" | tr '[:lower:]' '[:upper:]'
PATTERN="$(echo "$@" | cut -f2- -d ' ' | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
grep -P -i "$PATTERN" "$AMPATH/$arch-apps" | _clean_lists_and_queries | fold -sw 81
grep -P -i "$PATTERN" "$AMPATH/libs-list" | _clean_lists_and_queries | fold -sw 81
PATTERN="$(echo "$ARGS" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
grep -Pi "$PATTERN" "$AMPATH/$arch-apps" | _pretty_list_compat
grep -Pi "$PATTERN" "$AMPATH/libs-list" | _pretty_list_compat
fi
echo ""
exit 0
printf '\n'
;;
esac

0 comments on commit d623ca5

Please sign in to comment.