database.am 20 KB

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