Skip to content

Commit

Permalink
Merge pull request ivan-hc#348 from ivan-hc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ivan-hc authored Apr 4, 2024
2 parents f2ce127 + cb9dcf6 commit 8d817e9
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 243 deletions.
28 changes: 11 additions & 17 deletions APP-MANAGER
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ function _online_check(){
}

# Determine catalogue in use
export AMCATALOGUE="https://PORTABLE-LINUX-APPS.GITHUB.IO"
export AMCATALOGUEMARKDOWNS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/apps"
export AMCATALOGUEICONS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/icons"

Expand All @@ -141,20 +140,16 @@ fi

# To implement future application database changes
if [ -f "$AMPATH/neodb" ]; then
source "$AMPATH/neodb"
if grep -q "#NEODBFLAG=nowarn" "$AMPATH/neodb"; then
case "$1" in
'-a'|'about')
echo '--------------------------------------------------------------------------'
echo " Source: $AMCATALOGUE"
echo '--------------------------------------------------------------------------'
;;
'-d'|'download'|'-i'|'install'|'-l'|'list'|'-q'|'query')
echo '--------------------------------------------------------------------------'
echo " Source: $APPSDB"
echo '--------------------------------------------------------------------------'
;;
esac
if grep -q "://" "$AMPATH/neodb"; then
if grep -q "#STATUS=quiet" "$AMPATH/neodb"; then
case "$1" in
'-a'|'about'|'-d'|'download'|'-i'|'install'|'-l'|'list'|'-q'|'query')
echo '--------------------------------------------------------------------------'
echo " Source: Third party repositories are enabled"
echo '--------------------------------------------------------------------------'
;;
esac
fi
fi
fi

Expand Down Expand Up @@ -264,7 +259,6 @@ case "$1" in
'-a'|'about'|'-l'|'list'|'-q'|'query')

_no_sudo
_online_check

[[ -f "$AMPATH"/modules/database.am ]] || {
wget -q "$AMREPO"/modules/database.am -O "$AMPATH"/modules/database.am
Expand Down Expand Up @@ -502,7 +496,7 @@ case "$1" in

'version'|'-v'|'--version')

echo "6.3";;
echo "6.4";;

*) exec "$AMCLIPATH" ;;

Expand Down
74 changes: 2 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,79 +779,9 @@ To install and test your own script, use the command `am -i /path/to/your-script
<details>
<summary></summary>

From version 6.3 you can decide to use your personal online database or a third-party one by adding a script called "neodb" in the installation folder of your CLI.
From version 6.4, "AM"/"AppMan" can be extended by adding new application databases using a configuration file named "neodb".

A template is available at https://github.com/ivan-hc/AM/blob/main/templates/neodb

This script is an example of how you can use third-party databases instead of the default one used in AM/AppMan (without having to change the CLI repository with the `newrepo` option).

It should be placed in $AMPATH (for "AM" it is always /opt/am, while for "AppMan" is the "appman" folder located in the path chosen to install the applications).
The purpose of each assigned value is explained on each of the five (5) variables available.

### Content
In brief, the a "neodb" BASH script must contain as follows:
```
#!/usr/bin/env bash
APPSDB="https://raw.githubusercontent.com/IVAN-HC/AM/main/programs/$arch"
APPSLISTDB="https://raw.githubusercontent.com/IVAN-HC/AM/main/programs/$arch-apps"
AMCATALOGUE="https://PORTABLE-LINUX-APPS.GITHUB.IO"
AMCATALOGUEMARKDOWNS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/apps"
#NEODBFLAG=nowarn
```
In the example, I used the default values used by "AM"/"AppMan".

Below is the meaning of each of the 5 variables listed.

### Variables
1. "$APPSDB" is a url that must point to an online directory containing the installation scripts (for the -i and -d options)
```
SYNTAX: https://yoursite.org/path/to/directory
EXAMPLE: APPSDB="https://yoursite.org/path/to/directory"
```
each file managed in the modules is called "$arg"

2. "$APPSLISTDB" is the url that must point to an online $arch-apps file (for example "x86_64-apps", "$arch" is the architecture name).
This file is the list of all available programs (for the -l, -q and -s options)
```
SYNTAX: https://yoursite.org/path/to/file/named/x86_64-apps
EXAMPLE: APPSLISTDB="https://yoursite.org/path/to/file/named/x86_64-apps"
```

3. "$AMCATALOGUE" is the url of the main page of the catalog you want to use
```
SYNTAX: https://yoursite.org
EXAMPLE: AMCATALOGUE="https://PORTABLE-LINUX-APPS.GITHUB.IO"
```

4. "$AMCATALOGUEMARKDOWNS" is a url that points to an online directory containing .md (Markdown) files containing the application description (for the -a option)
```
SYNTAX: https://yoursite.org/path/to/markdown/files/#
EXAMPLE: AMCATALOGUEMARKDOWNS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/apps"
```
each file managed in the [database.am](https://github.com/ivan-hc/AM/blob/main/modules/database.am) module is called $arg.md

5. "$NEODBFLAG" is of no use, if not to silence the "Source: ..." message about using a third-party repository, just uncomment it to disable the messages
```
#NEODBFLAG=nowarn
```

## Motivation
Having reached version 6.3, I still don't know where the project will go and how far I can continue to support it. I opened too many projects at once, to the point of monopolizing the use of this CLI, and that wasn't what I wanted.

Everyone should be free to add as many applications as they want and maintain their own app database.

I hope that this version can help build a much more modern community database managed by many more people, to bring AppImages and portable apps in general to grow and compete with Flatpak and Snap.

I could disappear at any moment, and I don't want this database to end up in the cemetery of forgotten projects on github.

I wanted to build something long-lasting, and the application database must be too, and if managing it is a person who can suddenly disappear, then this project will be another of the many lost forever.

# See the full guide at https://github.com/ivan-hc/neodb
### For more details, see the full guide at https://github.com/ivan-hc/neodb

</details>

Expand Down
204 changes: 108 additions & 96 deletions modules/database.am
Original file line number Diff line number Diff line change
@@ -1,72 +1,23 @@
#!/usr/bin/env bash

# Define functions
function usage() {
echo " USAGE: $AMCLI $1 [ARGUMENT]";
}

function download_markdown() {
local markdown_url="$AMCATALOGUEMARKDOWNS/${1}.md"
local cache_dir="$AMPATH/.cache/about"
local app_status=" STATUS: NOT INSTALLED"
local package_name=${1^^}

if curl -o /dev/null -sIf "$markdown_url"; then
mkdir -p "$cache_dir" && wget -q "$markdown_url" -P "$cache_dir"
sed -i '1,${ /^\s*#/ d; /^\s*!/ d; /\[Applications]/d; /\ --- /d; }' "$cache_dir/$1.md"
sed -i '$!N;s/^\s*\n\s*$//;P;D' "$cache_dir/$1.md"

printf " PACKAGE: %s\n" "$package_name"

if [ -f "$APPSPATH/$1/remove" ]; then
local disk_usage=$(du -sm "$APPSPATH/$1" | cut -f1)
app_status=" STATUS: INSTALLED, ABOUT $disk_usage MB OF DISK SPACE IN USE"
fi

printf "%s\n" "$app_status"
cat -s "$cache_dir/$1.md" && printf "%s\n" "-----------------------------------------------------------------------"
rm -R -f "$cache_dir"
else
printf " \"%s\" IS NOT A VALID ARGUMENT\n" "$package_name"
fi
}

function download_lib() {
local lib_name_upper=${1^^}
printf "%s\n" " LIBRARY: $lib_name_upper"

if [[ -f "$APPSPATH/$1/remove" ]]; then
local lib_path=$(grep "usr/local/lib" "$APPSPATH/$1/remove" | head -1)
local disk_usage=$(du -sm "$lib_path" | cut -f1)

if [[ "$disk_usage" -eq 0 ]]; then
printf "%s\n" " STATUS: INSTALLED, LESS THAN 1 MB OF DISK SPACE IN USE"
else
printf "%s\n" " STATUS: INSTALLED, ABOUT $disk_usage MB OF DISK SPACE IN USE"
fi
else
printf "%s\n" " STATUS: NOT INSTALLED"
fi

echo ""
grep "$1 : " "$AMPATH/libs-list" | sed 's#.*:##' | sed 's/(/\n (/g'
echo "" && echo " SITE/SOURCES:" && echo ""

local site_source=$(wget -qO- "$APPSDB/$1" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | head -1)
echo " $site_source"
echo ""
printf "%s\n" "-----------------------------------------------------------------------"
}

function _completion_lists(){
# Remove existing lists and download new ones
rm -Rf $AMPATH/{$arch-apps,list,libs-list} &&
wget -q $APPSLISTDB -P $AMPATH &&
if [ -f "$AMPATH/neodb" ]; then
rm -f "$AMPATH/libs-list"
touch "$AMPATH/libs-list"
else
wget -q $LIBSLISTDB -P $AMPATH
wget -q $LIBSLISTDB -P $AMPATH

# THIRD PARTY APPS
if test -f "$AMPATH/neodb"; then
rm -R -f "$AMPATH/.cache/multirepo-args"
MULTIREPO=$(cat "$AMPATH/neodb" | grep "List=" | grep -E "$arch-apps" | cut -c 6-)
for anyrepo in $MULTIREPO; do
if curl --output /dev/null --silent --head --fail $anyrepo 1>/dev/null; then
wget -q "$anyrepo" -O - | grep "" >> $AMPATH/$arch-apps
fi
done
cat $AMPATH/$arch-apps | sort | uniq > $AMPATH/$arch-apps-backup
rm -R -f $AMPATH/$arch-apps
mv $AMPATH/$arch-apps-backup $AMPATH/$arch-apps
fi

# Extract and append program and library names to the list
Expand All @@ -78,41 +29,75 @@ function _completion_lists(){
cat $AMPATH/options >> $AMPATH/list
}

function _list_apps(){
wget -q --tries=10 --timeout=20 --spider https://github.com
if [[ $? -eq 0 ]]; then
_completion_lists
fi
LIBNUMBER=$(cat $APPSPATH/*/remove 2> /dev/null | grep "usr/local/lib" | wc -l)
ITEMSNUMBER=$(cd $APPSPATH && find -name 'remove' -printf "%h\n" 2>/dev/null | sort -u | wc -l)
APPSNUMBER=$(echo "$(($ITEMSNUMBER - $LIBNUMBER))")
MESSAGE=$(echo " YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $(grep -e "$" -c $AMPATH/$arch-apps) AVAILABLE")
echo -e "\n$MESSAGE\n\n LIST OF THE $(grep -e "$" -c $AMPATH/$arch-apps) APPLICATIONS AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(cat $AMPATH/$arch-apps)\n" | less -I
echo -e "\n $MESSAGE\n"
}

function _list_libs(){
wget -q --tries=10 --timeout=20 --spider https://github.com
if [[ $? -eq 0 ]]; then
_completion_lists
fi
LIBNUMBER=$(cat $APPSPATH/*/remove 2> /dev/null | grep "usr/local/lib" | wc -l)
MESSAGE=$(echo " YOU HAVE INSTALLED $LIBNUMBER LIBRARIES OUT OF $(grep -e "$" -c $AMPATH/libs-list) AVAILABLE")
echo -e "\n$MESSAGE\n\n LIST OF THE $(grep -e "$" -c $AMPATH/libs-list) LIBRARIES AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(cat $AMPATH/libs-list)\n" | less -I
echo -e "\n $MESSAGE\n"
}

case "$1" in

'-a'|'about')
case $2 in
'') echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit;;
esac

# Define functions
function usage() {
echo " USAGE: $AMCLI $1 [ARGUMENT]";
}

function download_markdown() {
local markdown_url="$AMCATALOGUEMARKDOWNS/${1}.md"
local cache_dir="$AMPATH/.cache/about"
local app_status=" STATUS: NOT INSTALLED"
local package_name=${1^^}

if curl -o /dev/null -sIf "$markdown_url"; then
mkdir -p "$cache_dir" && wget -q "$markdown_url" -P "$cache_dir"
sed -i '1,${ /^\s*#/ d; /^\s*!/ d; /\[Applications]/d; /\ --- /d; }' "$cache_dir/$1.md"
sed -i '$!N;s/^\s*\n\s*$//;P;D' "$cache_dir/$1.md"

printf " PACKAGE: %s\n" "$package_name"

if [ -f "$APPSPATH/$1/remove" ]; then
local disk_usage=$(du -sm "$APPSPATH/$1" | cut -f1)
app_status=" STATUS: INSTALLED, ABOUT $disk_usage MB OF DISK SPACE IN USE"
fi

printf "%s\n" "$app_status"
cat -s "$cache_dir/$1.md" && printf "%s\n" "-----------------------------------------------------------------------"
rm -R -f "$cache_dir"
else
printf " \"%s\" IS NOT A VALID ARGUMENT\n" "$package_name"
fi
}

function download_lib() {
local lib_name_upper=${1^^}
printf "%s\n" " LIBRARY: $lib_name_upper"

if [[ -f "$APPSPATH/$1/remove" ]]; then
local lib_path=$(grep "usr/local/lib" "$APPSPATH/$1/remove" | head -1)
local disk_usage=$(du -sm "$lib_path" | cut -f1)

if [[ "$disk_usage" -eq 0 ]]; then
printf "%s\n" " STATUS: INSTALLED, LESS THAN 1 MB OF DISK SPACE IN USE"
else
printf "%s\n" " STATUS: INSTALLED, ABOUT $disk_usage MB OF DISK SPACE IN USE"
fi
else
printf "%s\n" " STATUS: NOT INSTALLED"
fi

echo ""
grep "$1 : " "$AMPATH/libs-list" | sed 's#.*:##' | sed 's/(/\n (/g'
echo "" && echo " SITE/SOURCES:" && echo ""

local site_source=$(wget -qO- "$APPSDB/$1" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | head -1)
echo " $site_source"
echo ""
printf "%s\n" "-----------------------------------------------------------------------"
}

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

# Skip the first argument which is not part of ARGS
for arg in "${@:2}"; do
Expand All @@ -127,10 +112,37 @@ case "$1" in
;;

'-l'|'list')
case $2 in
'--libs') _list_libs;;
''|*) _list_apps;;
esac
function _list(){
LIBNUMBER=$(cat $APPSPATH/*/remove 2> /dev/null | grep "usr/local/lib" | wc -l)
ITEMSNUMBER=$(cd $APPSPATH && find -name 'remove' -printf "%h\n" 2>/dev/null | sort -u | wc -l)
APPSNUMBER=$(echo "$(($ITEMSNUMBER - $LIBNUMBER))")

function _list_apps(){
wget -q --tries=10 --timeout=20 --spider https://github.com
if [[ $? -eq 0 ]]; then
_completion_lists
fi
MESSAGE=$(echo " YOU HAVE INSTALLED $APPSNUMBER APPLICATIONS OUT OF $(grep -e "$" -c $AMPATH/$arch-apps) AVAILABLE")
echo -e "\n$MESSAGE\n\n LIST OF THE $(grep -e "$" -c $AMPATH/$arch-apps) APPLICATIONS AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(cat $AMPATH/$arch-apps)\n" | less -I
echo -e "\n $MESSAGE\n"
}

function _list_libs(){
wget -q --tries=10 --timeout=20 --spider https://github.com
if [[ $? -eq 0 ]]; then
_completion_lists
fi
MESSAGE=$(echo " YOU HAVE INSTALLED $LIBNUMBER LIBRARIES OUT OF $(grep -e "$" -c $AMPATH/libs-list) AVAILABLE")
echo -e "\n$MESSAGE\n\n LIST OF THE $(grep -e "$" -c $AMPATH/libs-list) LIBRARIES AVAILABLE IN THE 'AM' REPOSITORY:\n\n$(cat $AMPATH/libs-list)\n" | less -I
echo -e "\n $MESSAGE\n"
}

case $2 in
'--libs') _list_libs;;
''|*) _list_apps;;
esac
}
_list
;;

'-q'|'query')
Expand All @@ -151,4 +163,4 @@ case "$1" in
echo ""
exit
;;
esac
esac
Loading

0 comments on commit 8d817e9

Please sign in to comment.