database.am 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. #!/bin/sh
  2. ############################################################################################
  3. # THIS MODULE INCLUDES ALL THE ACTIONS INTENDED FOR THE MANAGEMENT OF LISTS AND SINGLE PAGES
  4. ############################################################################################
  5. ################################################################################
  6. # ABOUT
  7. ################################################################################
  8. _about_show_markdown() {
  9. if curl -o /dev/null -sIf "$markdown_url"; then
  10. markdown_page=$(curl -Ls "$markdown_url" \
  11. | sed '1,${ /^\s*#/ d; /^\s*!/ d; /\[Applications]/d; /\ --- /d; /\ | - | /d; /\!\[/d; }' \
  12. | sed '$!N;s/^\s*\n\s*$//;P;D')
  13. echo "$markdown_page" | fold -sw 72 | sed 's/^ //g; s/^/ /g'
  14. elif curl -Ls "$toolpack_readme" | grep -q "^| $arg " || curl -Ls "$toolpack_readme" | grep -q "^| $(echo "$arg" | sed 's/\.toolpack//g') "; then
  15. toolpack_appname=$(echo "$arg" | sed 's/\.toolpack//g')
  16. toolpack_md=$(curl -Ls "$toolpack_readme")
  17. toolpack_arg=$(echo "$toolpack_md" | grep -i "^| $toolpack_appname " | tr '|' '\n' | cut -c 2- | grep .)
  18. toolpack_about_description=$(echo "$toolpack_arg" | awk -F: "NR==$toolpack_description")
  19. toolpack_about_site=$(echo "$toolpack_arg" | awk -F: "NR==$toolpack_site")
  20. printf "\n%b\n\nSOURCE: %b\nDATABASE: https://github.com/Azathothas/Toolpacks\n" "$toolpack_about_description" "$toolpack_about_site" | fold -sw 72 | sed 's/^ //g; s/^/ /g'
  21. else
  22. printf ' "%s" IS NOT A VALID ARGUMENT\n' "$package_name"
  23. fi
  24. }
  25. _about_page() {
  26. _determine_args
  27. package_name="${Green}$1\033[0m"
  28. markdown_url="$AMCATALOGUEMARKDOWNS/${1}.md"
  29. printf " PACKAGE: %b\n" "$package_name"
  30. app_name=$(echo "$1" | sed 's/-appimage//g; s/debian-testing-//g; s/\.toolpack//g; s/\.dwfs.appbundle//g; s/\.appbundle//g')
  31. argpath=$(echo "$ARGPATHS" | grep "/$app_name$")
  32. if [ -f "$argpath/remove" ]; then
  33. app_status="installed\033[0m"
  34. if test -f "$argpath"/.am-installer/*; then
  35. scriptname=$(basename -- "$(find "$argpath"/.am-installer/* | head -1)")
  36. if [ "$app_name" != "$scriptname" ]; then
  37. app_status="installed\033[0m, but replaced by ${Green}$scriptname\033[0m\n\n NOTE: run ${RED}$AMCLI -a $scriptname\033[0m instead"
  38. fi
  39. if test -f "$argpath"/.am-installer/"$arg" && [ "$arg" != "$app_name" ]; then
  40. app_status="installed\033[0m, as ${Green}$app_name\033[0m"
  41. fi
  42. if echo "$arg" | grep -q "\.toolpack$" && ! test -f "$argpath"/.am-installer/"$arg"; then
  43. app_status="not installed"
  44. fi
  45. elif [ "$arg" != "$app_name" ]; then
  46. app_status="not installed"
  47. fi
  48. else
  49. app_status="not installed"
  50. fi
  51. METAPACKAGES="kdegames kdeutils node platform-tools"
  52. for m in $METAPACKAGES; do
  53. metaargpath=$(echo "$ARGPATHS" | grep "/$m$")
  54. if grep -q "◆ $1 : .*\"$m\"" "$AMDATADIR/$ARCH-apps"; then
  55. if test -f "$metaargpath/remove"; then
  56. app_status="installed\033[0m, as part of ${Green}$m\033[0m\n\n NOTE: run ${RED}$AMCLI -a $m\033[0m instead"
  57. app_name="$m"
  58. fi
  59. elif [ "$1" = "$m" ]; then
  60. app_status="installed\033[0m"
  61. fi
  62. done
  63. if echo "$app_status" | grep -q "^installed"; then
  64. printf " STATUS: %b\n" "${LightBlue}$app_status"
  65. disk_usage=$(du -sm "$argpath" | cut -f1)
  66. [ -z "$disk_usage" ] && disk_usage=$(du -sm "$metaargpath" | cut -f1)
  67. app_version=$(grep -w " ◆ $app_name |" "$AMCACHEDIR"/version-args 2>/dev/null | sed 's:.*| ::')
  68. echo ""
  69. echo " Disk usage: $disk_usage MB"
  70. echo " Installed version: $app_version"
  71. else
  72. echo " STATUS: $app_status"
  73. fi
  74. _about_show_markdown
  75. }
  76. ################################################################################
  77. # FILES
  78. ################################################################################
  79. _files_header() {
  80. CHECK_TOOLPACK="$(find "$APPSPATH"/*/* -type f -name '*.toolpack' -print -quit 2>/dev/null)"
  81. echo ""
  82. APPSNUMB=$(find "$APPSPATH" -type f -name 'remove' -exec grep -L 'usr/local/lib' {} \; 2>/dev/null | sed -r 's|/[^/]+$||' | sort | uniq | wc -l)
  83. if [ "$APPSNUMB" = 1 ]; then
  84. APPSMESSAGE="YOU HAVE INSTALLED $APPSNUMB PROGRAM"
  85. else
  86. APPSMESSAGE="YOU HAVE INSTALLED $APPSNUMB PROGRAMS"
  87. fi
  88. if grep -q 'usr/local/lib' "$APPSPATH"/*/remove 2> /dev/null; then
  89. LIBNUMB=$(grep -l "usr/local/lib" "$APPSPATH"/*/remove | wc -l)
  90. if [ "$LIBNUMB" = 1 ]; then
  91. LIBSMESSAGE="AND $LIBNUMB LIBRARY"
  92. else
  93. LIBSMESSAGE="AND $LIBNUMB LIBRARIES"
  94. fi
  95. [ "$APPMAN_ON" = 1 ] && echo "- $APPSMESSAGE $LIBSMESSAGE LOCALLY, AS \"APPMAN\"" || echo "- $APPSMESSAGE $LIBSMESSAGE MANAGED BY \"$AMCLIUPPER\""
  96. else
  97. [ "$APPMAN_ON" = 1 ] && echo "- $APPSMESSAGE LOCALLY, AS \"APPMAN\"" || echo "- $APPSMESSAGE MANAGED BY \"$AMCLIUPPER\""
  98. fi
  99. echo ""
  100. if [ -n "$CHECK_TOOLPACK" ]; then
  101. files_table_header="- APPNAME | DB | VERSION | TYPE | SIZE "
  102. files_table_header_lines="- ------- | -- | ------- | ---- | ----"
  103. else
  104. files_table_header="- APPNAME | VERSION | TYPE | SIZE "
  105. files_table_header_lines="- ------- | ------- | ---- | ----"
  106. fi
  107. }
  108. # Functions to determine file's type
  109. _files_if_binary() {
  110. if file ./"$arg"/* | grep "static" >/dev/null 2>&1; then
  111. echo " ◆ $arg | static-binary" >> "$AMCACHEDIR"/files-type
  112. else
  113. echo " ◆ $arg | dynamic-binary" >> "$AMCACHEDIR"/files-type
  114. fi
  115. }
  116. _files_if_library() {
  117. echo " ◆ $arg | library" >> "$AMCACHEDIR"/files-type
  118. }
  119. _files_if_script() {
  120. if grep "/ffwa" "${LINK:-$FILE}" >/dev/null 2>&1; then
  121. echo " ◆ $arg | launcher" >> "$AMCACHEDIR"/files-type
  122. elif grep '#!.*bash' "${LINK:-$FILE}" >/dev/null 2>&1; then
  123. echo " ◆ $arg | bash-script" >> "$AMCACHEDIR"/files-type
  124. elif grep '#!.*dash' "${LINK:-$FILE}" >/dev/null 2>&1; then
  125. echo " ◆ $arg | dash-script" >> "$AMCACHEDIR"/files-type
  126. elif grep '#!.*bin.*sh' "${LINK:-$FILE}" >/dev/null 2>&1; then
  127. echo " ◆ $arg | posix-script" >> "$AMCACHEDIR"/files-type
  128. elif grep '#!.*awk' "${LINK:-$FILE}" >/dev/null 2>&1; then
  129. echo " ◆ $arg | awk-script" >> "$AMCACHEDIR"/files-type
  130. else
  131. echo " ◆ $arg | script" >> "$AMCACHEDIR"/files-type
  132. fi
  133. }
  134. _files_if_appimage() {
  135. if ! echo "$string" | grep 'AppImages require FUSE to run' >/dev/null 2>&1; then
  136. if grep "SANDBOXDIR" "$FILE" >/dev/null 2>&1; then
  137. echo " ◆ $arg | appimage🔒" >> "$AMCACHEDIR"/files-type
  138. else
  139. echo " ◆ $arg | appimage" >> "$AMCACHEDIR"/files-type
  140. fi
  141. else
  142. if grep "SANDBOXDIR" "$FILE" >/dev/null 2>&1; then
  143. echo " ◆ $arg | appimage🔒*" >> "$AMCACHEDIR"/files-type
  144. else
  145. echo " ◆ $arg | appimage*" >> "$AMCACHEDIR"/files-type
  146. fi
  147. fi
  148. }
  149. _files_type() {
  150. APPVERSION=$(<"$AMCACHEDIR"/version-args grep -w " ◆ $arg |" | sed 's:.*| ::')
  151. string=$(strings -d ./"$arg/$arg" 2>/dev/null)
  152. FILE=$(command -v "$arg" 2>/dev/null)
  153. LINK=$(readlink "$FILE" 2>/dev/null)
  154. if echo "$string" | grep 'github.com/AppImage/AppImageKit/wiki/FUSE' >/dev/null 2>&1; then
  155. _files_if_appimage
  156. elif file ./"$arg"/* | grep -E 'LSB|/bin' >/dev/null 2>&1; then
  157. _files_if_binary
  158. elif grep "#!" "${LINK:-$FILE}" >/dev/null 2>&1; then
  159. _files_if_script
  160. elif grep "usr/local/lib" ./"$arg"/remove >/dev/null 2>&1; then
  161. _files_if_library
  162. else
  163. echo " ◆ $arg | other" >> "$AMCACHEDIR"/files-type
  164. fi
  165. }
  166. # Function to determine file's size
  167. _files_sizes() {
  168. if grep -q "usr/local/lib" ./"$arg"/remove; then
  169. LIBNAME=$(<"$APPSPATH"/"$arg"/remove tr ' ' '\n' | grep "usr/local/lib" | head -1 | sed 's/*//g')
  170. SIZE=$(du -sh "$LIBNAME"* | cut -f1 | sort -rh | head -1)
  171. else
  172. SIZE=$(du -sh -- "$arg" | cut -f1 -d" ")
  173. fi
  174. SIZE=$(echo "$SIZE" | sed 's/.$/ &/; s/$/iB/')
  175. echo " ◆ $arg | $SIZE" >> "$AMCACHEDIR"/files-sizes
  176. }
  177. # Function to determine file's database
  178. _files_db() {
  179. if test -f "$APPSPATH"/"$arg"/.am-installer/*toolpack; then
  180. DB="toolpacks"
  181. elif [ "$arg" = am ]; then
  182. DB="am"
  183. elif test -f "$CACHEDIR"/extra/"$arg" || test -f "$APPSPATH"/"$arg"/.am-installer/"$arg" && ! grep -q "^APP=" "$APPSPATH"/"$arg"/.am-installer/"$arg"; then
  184. DB="none"
  185. elif test -f "$AMDATADIR/$ARCH-apps" && ! grep -q "^◆ $arg :" "$AMDATADIR/$ARCH-apps"; then
  186. DB="unknown"
  187. else
  188. DB="am"
  189. fi
  190. echo " ◆ $arg | $DB" >> "$AMCACHEDIR"/files-db
  191. }
  192. # Functions to create file's table
  193. _files_files() {
  194. cd "$APPSPATH" || exit 1
  195. INSTALLED_APPS=$(find . -name 'remove' -printf "%h\n" 2>/dev/null | du -sh -- * 2> /dev/null | sort -rh | sed 's@.* @@')
  196. if ! test -f "$AMCACHEDIR"/version-args; then
  197. _check_version
  198. fi
  199. if ! test -f "$AMCACHEDIR"/files-type; then
  200. for arg in $INSTALLED_APPS; do
  201. if test -f ./"$arg"/remove 2>/dev/null; then
  202. _files_type
  203. fi
  204. done
  205. fi
  206. rm -f "$AMCACHEDIR"/files-sizes "$AMCACHEDIR"/files-db
  207. for arg in $INSTALLED_APPS; do
  208. if test -f ./"$arg"/remove 2>/dev/null; then
  209. _files_sizes
  210. _files_db
  211. fi
  212. done
  213. }
  214. _files() {
  215. _files_files
  216. rm -f "$AMCACHEDIR"/files-args
  217. INSTALLED_APPS=$(find . -name 'remove' -printf "%h\n" 2>/dev/null | du -sh -- * 2>/dev/null | sort -rh | sed 's@.* @@')
  218. for arg in $INSTALLED_APPS; do
  219. if test -f ./"$arg"/remove 2>/dev/null; then
  220. APPVERSION=$(grep -w " ◆ $arg |" "$AMCACHEDIR"/version-args | tr ' ' '\n' | tail -1)
  221. APPTYPE=$(grep -w " ◆ $arg |" "$AMCACHEDIR"/files-type | tr ' ' '\n' | tail -1)
  222. APPSYZE=$(grep -w " ◆ $arg |" "$AMCACHEDIR"/files-sizes | tr ' ' '\n' | tail -1)
  223. APPDB=$(grep -w " ◆ $arg |" "$AMCACHEDIR"/files-db | tr ' ' '\n' | tail -1)
  224. if [ -n "$CHECK_TOOLPACK" ]; then
  225. echo " ◆ $arg | $APPDB | $APPVERSION | $APPTYPE | $APPSYZE" >> "$AMCACHEDIR"/files-args
  226. else
  227. echo " ◆ $arg | $APPVERSION | $APPTYPE | $APPSYZE" >> "$AMCACHEDIR"/files-args
  228. fi
  229. fi
  230. done
  231. }
  232. _files_number() {
  233. FILES_NUMBER=$(find "$APPSPATH" -type f -name 'remove' 2>/dev/null | uniq | wc -l)
  234. }
  235. _files_appimage_type_notes() {
  236. if grep -qe "appimage\*\|appimage🔒\*" "$AMCACHEDIR"/files*; then
  237. printf " *has dependency to EOL libfuse2 library, please ask the creator to update\n"
  238. printf "\n"
  239. fi
  240. }
  241. _files_total_size() {
  242. printf "\n"
  243. command -v aisap >/dev/null 2>&1 && printf '%s\n\n' " AppImages with 🔒 are sandboxed with aisap"
  244. echo " TOTAL SIZE: $(find . -type f -name 'remove' -printf "%h\n" | du -ch -- */ 2>/dev/null | awk 'END {print $1"iB"}' | sed 's/...$/ &/') of disk space in use"
  245. printf "\n"
  246. }
  247. _files_sort_by_name() {
  248. _files_header
  249. rm -f "$AMCACHEDIR"/files-args-byname
  250. _files
  251. echo "$files_table_header" > "$AMCACHEDIR"/files-args-byname
  252. echo "$files_table_header_lines" >> "$AMCACHEDIR"/files-args-byname
  253. sort "$AMCACHEDIR"/files-args 2>/dev/null >> "$AMCACHEDIR"/files-args-byname
  254. column -t "$AMCACHEDIR"/files-args-byname
  255. _files_total_size
  256. _files_appimage_type_notes
  257. }
  258. _files_sort_by_size() {
  259. _files_header
  260. rm -f "$AMCACHEDIR"/files-args-bysize
  261. _files
  262. echo "$files_table_header" > "$AMCACHEDIR"/files-args-bysize
  263. echo "$files_table_header_lines" >> "$AMCACHEDIR"/files-args-bysize
  264. cat "$AMCACHEDIR"/files-args >> "$AMCACHEDIR"/files-args-bysize 2>/dev/null
  265. column -t "$AMCACHEDIR"/files-args-bysize
  266. _files_total_size
  267. _files_appimage_type_notes
  268. }
  269. ################################################################################
  270. # LIST/QUERY
  271. ################################################################################
  272. _pretty_list() {
  273. # Remove references to URLs, "-a" elements in "-l" and "-q"
  274. sed -E 's#(http|https|ftp)://[^ ]*##g; s#(SITE|SOURCE):##g; s/^/\n/g' | _colors | fold -sw 75 | sed 's/^/ /g; s/ ◆ /◆ /g; s/ :/ :/g'
  275. }
  276. _pretty_list_compat() {
  277. # Remove references to URLs, "-a" elements in "-l" and "-q"
  278. sed -E 's#(http|https|ftp)://[^ ]*##g; s#(SITE|SOURCE):##g' | _colors | fold -sw 75 | sed 's/^/ /g; s/ ◆ /◆ /g; s/ :/ :/g'
  279. }
  280. _colors() {
  281. awk '{
  282. printf "%s \033[32m%s\033[0m", $1, $2
  283. {$1 = ""; $2 = ""; print $0;}
  284. }'
  285. }
  286. _list() {
  287. # Check if github.com is online, if not, the function will read the offline list
  288. wget -q --tries=10 --timeout=20 --spider https://github.com && _completion_lists
  289. # Check the number of installed apps and libraries
  290. LIBNUMBER=$(grep "usr/local/lib" "$APPSPATH"/*/remove 2> /dev/null | wc -l)
  291. ITEMSNUMBER=$(find "$APPSPATH" -name 'remove' -printf "%h\n" 2>/dev/null | sort -u | wc -l)
  292. _detect_appman_apps
  293. if [ "$AMCLI" = am ]; then
  294. if [ -d "$APPMAN_APPSPATH" ]; then
  295. APPMAN_ITEMS=$(find "$APPMAN_APPSPATH" -name 'remove' -printf "%h\n" 2>/dev/null | sort -u | wc -l)
  296. ITEMSNUMBER=$(("$ITEMSNUMBER"+"$APPMAN_ITEMS"))
  297. fi
  298. if test -f /opt/am/remove; then
  299. ITEMSNUMBER=$(("$ITEMSNUMBER"-1))
  300. fi
  301. fi
  302. APPSNUMBER=$(("$ITEMSNUMBER" - "$LIBNUMBER"))
  303. # Determine the number of available apps from the list
  304. AVAILABLE_APPS_NUMBER=$(grep -v "ffwa-\|\"kdegames\"\|\"kdeutils\"\|\"node\"\|\"platform-tools\"" "$AMDATADIR/$ARCH-apps" | grep -e "$" -c)
  305. if ! test -f "$AMDATADIR/$ARCH-appimages"; then
  306. _online_check
  307. _sync_appimages_list
  308. AVAILABLE_APPIMAGES_NUMBER=$(grep -e "$" -c "$AMDATADIR/$ARCH-appimages")
  309. else
  310. AVAILABLE_APPIMAGES_NUMBER=$(grep -e "$" -c "$AMDATADIR/$ARCH-appimages")
  311. fi
  312. if ! test -f "$AMDATADIR/$ARCH-toolpack"; then
  313. _online_check
  314. _sync_toolpacks_list
  315. _completion_lists
  316. AVAILABLE_TOOLPACKS_NUMBER=$(grep -e "$" -c "$AMDATADIR/$ARCH-toolpack")
  317. else
  318. AVAILABLE_TOOLPACKS_NUMBER=$(grep -e "$" -c "$AMDATADIR/$ARCH-toolpack")
  319. fi
  320. [ -n "$AVAILABLE_TOOLPACKS_NUMBER" ] && AVAILABLE_TOTAL_APPS_NUMBER=$(("$AVAILABLE_APPS_NUMBER" + "$AVAILABLE_TOOLPACKS_NUMBER"))
  321. # Generate a list of the installed apps with version
  322. [ ! -f "$AMCACHEDIR"/version-args ] && _check_version
  323. if [ -n "$APPMAN_ITEMS" ]; then
  324. _check_version
  325. else
  326. grep " ◆ $ARGS " "$AMCACHEDIR"/version-args > "$AMCACHEDIR"/version-args-real
  327. sort "$AMCACHEDIR"/version-args-real > "$AMCACHEDIR"/version-args
  328. fi
  329. INSTALLED=$(sort "$AMCACHEDIR"/version-args 2>/dev/null | sed 's/ | / /g' | grep -v "◆ am " | uniq)
  330. MESSAGE2="$INSTALLED"
  331. # Check if among the installed apps are available libraries
  332. if [ "$LIBNUMBER" != 0 ]; then
  333. # Check if the installed libraries are more than one
  334. if [ "$LIBNUMBER" = 1 ]; then
  335. MESSAGE=" YOU HAVE INSTALLED $APPSNUMBER PROGRAMS OUT OF $AVAILABLE_TOTAL_APPS_NUMBER AVAILABLE, AND $LIBNUMBER LIBRARY"
  336. else
  337. MESSAGE=" YOU HAVE INSTALLED $APPSNUMBER PROGRAMS OUT OF $AVAILABLE_TOTAL_APPS_NUMBER AVAILABLE, AND $LIBNUMBER LIBRARIES"
  338. fi
  339. else
  340. MESSAGE=" YOU HAVE INSTALLED $APPSNUMBER PROGRAMS OUT OF $AVAILABLE_TOTAL_APPS_NUMBER AVAILABLE"
  341. fi
  342. }
  343. _list_appimages() {
  344. wget -q --tries=10 --timeout=20 --spider https://github.com && _sync_appimages_list
  345. if ! test -f "$AMDATADIR/$ARCH-appimages"; then
  346. _online_check
  347. _sync_appimages_list
  348. fi
  349. }
  350. _list_toolpacks() {
  351. wget -q --tries=10 --timeout=20 --spider https://github.com && _sync_toolpacks_list
  352. if ! test -f "$AMDATADIR/$ARCH-toolpack"; then
  353. _online_check
  354. _sync_toolpacks_list
  355. fi
  356. }
  357. _list_msg_head() {
  358. echo "" && echo "$MESSAGE" && echo "" && echo "$MESSAGE2" && echo ""
  359. }
  360. _list_msg_suggest_all() {
  361. printf "\n To list all installable programs, use the \"%b--all\033[0m\" flag\n" "${LightBlue}"
  362. }
  363. _list_msg_footer() {
  364. echo "$LIST" && echo ""
  365. }
  366. _list_toolpacks_msg() {
  367. _list_msg_head
  368. echo " LIST OF THE $AVAILABLE_TOOLPACKS_NUMBER PROGRAMS AVAILABLE IN THE \"TOOLPACKS\" DATABASE:"
  369. _list_msg_suggest_all
  370. _list_msg_footer
  371. }
  372. _list_appimages_msg() {
  373. _list_msg_head
  374. echo " LIST OF THE $AVAILABLE_APPIMAGES_NUMBER APPIMAGES AVAILABLE IN THE \"AM\" DATABASE:"
  375. _list_msg_suggest_all
  376. _list_msg_footer
  377. }
  378. _list_apps_msg() {
  379. _list_msg_head
  380. echo " LIST OF THE $AVAILABLE_APPS_NUMBER PROGRAMS AVAILABLE IN THE \"AM\" DATABASE:"
  381. _list_msg_suggest_all
  382. _list_msg_footer
  383. }
  384. _list_apps_all_msg() {
  385. _list_msg_head
  386. echo " LIST OF THE $AVAILABLE_TOTAL_APPS_NUMBER PROGRAMS AVAILABLE IN ALL SUPPORTED DATABASES:"
  387. _list_msg_footer
  388. }
  389. ################################################################################
  390. # USAGE
  391. ################################################################################
  392. case "$1" in
  393. '-a'|'about')
  394. [ -z "$2" ] && echo " USAGE: $AMCLI $1 [ARGUMENT]" && exit 1
  395. _online_check
  396. printf "%s\n" "-----------------------------------------------------------------------"
  397. [ ! -f "$AMCACHEDIR"/version-args ] && _check_version
  398. entries="$(echo "$@" | cut -f2- -d ' ')" # Removes first argument
  399. for arg in $entries; do
  400. if curl -o /dev/null -sIf "$AMCATALOGUEMARKDOWNS/${arg}.md" 1>/dev/null; then
  401. _about_page "$arg"
  402. elif curl -Ls "$toolpack_readme" | grep -q "^| $arg "; then
  403. arg="$arg.toolpack"
  404. _about_page "$arg"
  405. elif echo "$arg" | grep -q ".toolpack$"; then
  406. _about_page "$arg"
  407. else
  408. printf " ERROR: %b not found\033[0m\n" "${RED}\"$arg\""
  409. fi
  410. printf "%s\n" "-----------------------------------------------------------------------"
  411. done
  412. ;;
  413. '-f'|'files')
  414. if [ "$2" = "--less" ]; then
  415. _files_number && echo "$FILES_NUMBER"
  416. [ "$AMCLI" = am ] && [ -f "$APPMANCONFIG"/appman-config ] && _appman && echo "$DIVIDING_LINE" && _files_number && echo "$FILES_NUMBER"
  417. elif [ "$2" = "--byname" ]; then
  418. _files_sort_by_name
  419. [ "$AMCLI" = am ] && [ -f "$APPMANCONFIG"/appman-config ] && _appman && APPMAN_ON=1 && _files_number && [ "$FILES_NUMBER" != 0 ] && echo "$DIVIDING_LINE" && _files_sort_by_name
  420. _betatester_message_on
  421. else
  422. _files_sort_by_size
  423. [ "$AMCLI" = am ] && [ -f "$APPMANCONFIG"/appman-config ] && _appman && APPMAN_ON=1 && _files_number && [ "$FILES_NUMBER" != 0 ] && echo "$DIVIDING_LINE" && _files_sort_by_size
  424. _betatester_message_on
  425. fi
  426. ;;
  427. '-l'|'list')
  428. _list
  429. if [ "$2" = --all ]; then
  430. _list_toolpacks
  431. LIST=$(sort "$AMDATADIR/$ARCH-apps" "$AMDATADIR/$ARCH-toolpack" | uniq | _pretty_list)
  432. _list_apps_all_msg | less -Ir
  433. echo "$DIVIDING_LINE"
  434. echo " $(("$AVAILABLE_APPS_NUMBER" + "$AVAILABLE_TOOLPACKS_NUMBER")) programs in all supported databases"
  435. echo "$DIVIDING_LINE"
  436. elif [ "$2" = --appimages ]; then
  437. _list_appimages
  438. LIST=$(sort "$AMDATADIR/$ARCH-appimages" | _pretty_list)
  439. _list_appimages_msg | less -Ir
  440. echo "$DIVIDING_LINE"
  441. echo " $AVAILABLE_APPIMAGES_NUMBER AppImages in the \"AM\" database"
  442. echo "$DIVIDING_LINE"
  443. elif [ "$2" = --toolpack ]; then
  444. _list_toolpacks
  445. LIST=$(sort "$AMDATADIR/$ARCH-toolpack" | _pretty_list)
  446. _list_toolpacks_msg | less -Ir
  447. echo "$DIVIDING_LINE"
  448. echo " $AVAILABLE_TOOLPACKS_NUMBER programs in the \"Toolpacks\" database"
  449. echo "$DIVIDING_LINE"
  450. else
  451. LIST=$(sort "$AMDATADIR/$ARCH-apps" | _pretty_list)
  452. _list_apps_msg | less -Ir
  453. echo "$DIVIDING_LINE"
  454. echo " $AVAILABLE_APPS_NUMBER programs in the \"AM\" database"
  455. echo "$DIVIDING_LINE"
  456. fi
  457. ;;
  458. '-q'|'query')
  459. if [ -z "$2" ]; then
  460. echo " USAGE: $AMCLI $1 [ARGUMENT]"
  461. echo " $AMCLI $1 --all [ARGUMENT]"
  462. echo " $AMCLI $1 --appimages [ARGUMENT]"
  463. echo " $AMCLI $1 --pkg [ARGUMENT]"
  464. echo " $AMCLI $1 --toolpack [ARGUMENT]"; exit 1
  465. fi
  466. wget -q --tries=10 --timeout=20 --spider https://github.com && _completion_lists
  467. if [ "$2" = --pkg ]; then
  468. entries="$(echo "$@" | cut -f3- -d ' ' | tr -s ' ' '|')"
  469. printf "\n Search results for packages: %s\n\n" "$entries" | tr '[:lower:]' '[:upper:]'
  470. grep -iE "$entries" "$AMDATADIR/$ARCH-apps" --color=always | _pretty_list_compat
  471. [ -f "$AMDATADIR/$ARCH-toolpack" ] && grep -iE "$entries" "$AMDATADIR/$ARCH-toolpack" --color=always | _pretty_list_compat
  472. elif [ "$2" = --appimages ]; then
  473. entries="$(echo "$@" | cut -f3- -d ' ')"
  474. printf "\n Search results for \"%s\":\n\n" "$entries" | tr '[:lower:]' '[:upper:]'
  475. pattern="$(echo "$entries" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
  476. _list_appimages
  477. grep -Pi "$pattern" "$AMDATADIR/$ARCH-appimages" | _pretty_list_compat
  478. elif [ "$2" = --toolpack ]; then
  479. entries="$(echo "$@" | cut -f3- -d ' ')"
  480. printf "\n Search results for \"%s\":\n\n" "$entries" | tr '[:lower:]' '[:upper:]'
  481. pattern="$(echo "$entries" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
  482. _list_toolpacks
  483. grep -Pi "$pattern" "$AMDATADIR/$ARCH-toolpack" | _pretty_list_compat
  484. elif [ "$2" = --all ]; then
  485. entries="$(echo "$@" | cut -f3- -d ' ')"
  486. printf "\n Search results for \"%s\":\n\n" "$entries" | tr '[:lower:]' '[:upper:]'
  487. pattern="$(echo "$entries" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
  488. _list_toolpacks
  489. sort "$AMDATADIR/$ARCH-toolpack" "$AMDATADIR/$ARCH-apps" | grep -Pi "$pattern" | _pretty_list_compat
  490. else
  491. entries="$(echo "$@" | cut -f2- -d ' ')"
  492. printf "\n Search results for \"%s\":\n\n" "$entries" | tr '[:lower:]' '[:upper:]'
  493. pattern="$(echo "$entries" | sed 's/ /(?=.*/g; s/$/)/g; s/(/)(/g; s/^/(?=.*/g;')"
  494. grep -Pi "$pattern" "$AMDATADIR/$ARCH-apps" | _pretty_list_compat
  495. fi
  496. printf '\n'
  497. ;;
  498. esac