APP-MANAGER 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. #!/usr/bin/env bash
  2. AMVERSION="9.5-7"
  3. # Determine main repository and branch
  4. AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
  5. AMBRANCH=$(basename "$AMREPO")
  6. MODULES_SOURCE="$AMREPO/modules"
  7. # Determine the name of this script and its working directory
  8. export REALDIR="$PWD"
  9. DIR="$( cd "$( dirname "$0" )" && pwd )"
  10. CLI=$(basename "$0")
  11. # Determine system architecture and current user
  12. ARCH="$(uname -m)"
  13. [ "$ARCH" = "amd64" ] && ARCH=x86_64
  14. export ARCH
  15. # Fixes issue with less on bsd
  16. if uname | grep -q "BSD\|DragonFly\|DynFi\|FreeNAS\|helloSystem\|OPNsense\|pfSense\|TrueNAS\|XigmaNAS"; then
  17. TERM=xterm-clear
  18. export TERM
  19. fi
  20. # XDG Variables
  21. export BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
  22. export DATADIR="${XDG_DATA_HOME:-$HOME/.local/share}"
  23. export CONFIGDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
  24. export CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}"
  25. export APPMANCONFIG="$CONFIGDIR/appman"
  26. APPMANCONFIG="$CONFIGDIR/appman"
  27. SCRIPTDIR="${SCRIPTDIR:-$(xdg-user-dir DESKTOP 2>/dev/null)}"
  28. [ -d "$SCRIPTDIR" ] || SCRIPTDIR="$PWD"
  29. export SCRIPTDIR
  30. # Colors
  31. RED='\033[0;31m'
  32. Gold='\033[0;33m'
  33. Green='\033[0;32m'
  34. LightBlue='\033[1;34m'
  35. DIVIDING_LINE="-----------------------------------------------------------------------------"
  36. # Prevent the use of "sudo" ("AM")
  37. if [ "$(id -u)" = 0 ] && [ -n "${SUDO_USER:-$DOAS_USER}" ]; then
  38. printf "\n Please do not use \"sudo\" to execute \"%b\", try again.\n\n" "$CLI"
  39. exit 1
  40. fi
  41. if ! sed --version 2>/dev/null | grep -qi "gnu"; then
  42. NO_SED_I=true
  43. fi
  44. _create_cache_dir() {
  45. AMCACHEDIR="$CACHEDIR/$AMCLI"
  46. mkdir -p "$AMCACHEDIR"
  47. }
  48. _clean_amcachedir() {
  49. if [ "$AMCLI" = am ] && [ -d "$CACHEDIR"/am ]; then
  50. rm -f "$CACHEDIR"/am/* rm -f "$CACHEDIR"/am/*/* 2>/dev/null
  51. rmdir "$CACHEDIR"/am/* 2>/dev/null
  52. fi
  53. if [ -d "$CACHEDIR"/appman ]; then
  54. rm -f "$CACHEDIR"/appman/* "$CACHEDIR"/appman/*/* 2>/dev/null
  55. rmdir "$CACHEDIR"/appman/* 2>/dev/null
  56. fi
  57. }
  58. # Fit texts to an acceptable width
  59. _fit() {
  60. fold -sw 77 | sed 's/^/ /g'
  61. }
  62. # Makes "less" optional
  63. less() {
  64. if ! command less "$@" 2>/dev/null; then
  65. while read -r line; do echo "$line"; done
  66. echo "Install 'less' if you want to scroll this list"
  67. fi
  68. }
  69. # Force usage of a GNU implementation of "sed"
  70. sed() {
  71. if [ "$NO_SED_I" = true ] && [ "$1" = '-i' ]; then
  72. if command -v gsed >/dev/null 2>&1; then
  73. command gsed "$@"
  74. else
  75. shift
  76. tmpsedYYY="$(command sed "$@" 2>/dev/null)"
  77. while [ "$#" -gt 1 ]; do shift; done
  78. if [ -n "$tmpsedYYY" ] && [ -f "$1" ]; then
  79. echo "$tmpsedYYY" > "$1"
  80. unset tmpsedYYY
  81. else
  82. >&2 echo " 💀 ERROR: Your version of sed does not support '-i' flag"
  83. >&2 echo " without extension, we tried to workaround and failed"
  84. >&2 echo " Please install gsed"
  85. unset tmpsedYYY
  86. return 1
  87. fi
  88. fi
  89. else
  90. command sed "$@"
  91. fi
  92. }
  93. ################################################################################################################################################################
  94. # AM/APPMAN
  95. ################################################################################################################################################################
  96. # "APPMAN" CORE VARIABLES AND FUNCTIONS
  97. APPMAN_SETUP_MSG="Before proceeding with any task, where do you want to install apps?
  98. SYNTAX: /FULLPATH/TO/DIRNAME
  99. EXAMPLE: $HOME/My-apps
  100. NOTE: Any spaces in the path will be replaced for dashes
  101. NOTE: If no input is given then \"~/Applications\" will be used as default
  102. if you wish to later change the location, first remove all the programs and then edit the \"$APPMANCONFIG/appman-config\" file."
  103. _appman_check() {
  104. if [ ! -f "$APPMANCONFIG"/appman-config ]; then
  105. echo "$DIVIDING_LINE"
  106. [ "$AMCLI" = am ] && echo ">>> Configure AppMan" || echo ">>> Thank you for choosing AppMan!"
  107. echo "$DIVIDING_LINE"
  108. echo "$APPMAN_SETUP_MSG" | _fit
  109. echo "$DIVIDING_LINE"
  110. read -r -ep " Write the path or just press enter to use default:$(printf "\n\n ")" location
  111. location="$(echo "$location" | sed 's/[ \t]/-/g; s|^\./||' 2>/dev/null)"
  112. [ -z "$location" ] && location="$HOME/Applications"
  113. if ! echo "$location" | grep "^/" >/dev/null 2>&1; then
  114. location="$HOME/$location"
  115. fi
  116. if echo "$location" | grep "$BINDIR" >/dev/null 2>&1; then
  117. echo "$DIVIDING_LINE"
  118. echo " 💀 ERROR, you can't install applications in \"$BINDIR\""
  119. echo " $BINDIR is normally used for executables, Please choose a different path and retry!"
  120. echo "$DIVIDING_LINE"
  121. exit 1
  122. elif ! mkdir -p "$location" 2>/dev/null || [ ! -w "$location" ]; then
  123. echo " 💀 ERROR: You don't have write access to $location or it is invalid"
  124. exit 1
  125. fi
  126. mkdir -p "$APPMANCONFIG" || exit 1
  127. echo "${location%/}" > "$APPMANCONFIG"/appman-config || exit 1
  128. echo "$DIVIDING_LINE"
  129. echo " You are ready! Start installing your favorite apps locally!"
  130. echo " All apps will be installed in $location"
  131. echo " In case of problems, use the option \"-h\"."
  132. echo "$DIVIDING_LINE"
  133. fi
  134. }
  135. _appman() {
  136. _appman_check
  137. if ! grep -q "^/" "$APPMANCONFIG"/appman-config; then
  138. APPSDIR="$HOME/$(head -1 "$APPMANCONFIG"/appman-config 2>/dev/null)"
  139. else
  140. APPSDIR="$(head -1 "$APPMANCONFIG"/appman-config 2>/dev/null)"
  141. fi
  142. [ -n "$APPSDIR" ] && mkdir -p "$APPSDIR"/appman || exit 1
  143. mkdir -p "$BINDIR" "$DATADIR"/applications "$DATADIR"/icons || exit 1
  144. AMCLI="appman"
  145. AMCLIPATH="$DIR/$AMCLI"
  146. SUDOCMD=""
  147. APPSPATH="$APPSDIR"
  148. AMPATH="$APPSDIR/$AMCLI"
  149. _create_cache_dir
  150. if [ ! -w "$APPSPATH" ]; then
  151. echo "ERROR: You don't have write access to $APPSPATH" | _fit
  152. exit 1
  153. elif ! echo "$PATH" | grep "$BINDIR" >/dev/null 2>&1; then
  154. echo "$DIVIDING_LINE"
  155. printf "%b ⚠️ WARNING\033[0m: \"%b%b\033[0m\" is not in PATH, local apps may not run.\n" "${RED}" "${LightBlue}" "$BINDIR"
  156. fi
  157. MODULES_PATH="$AMPATH/modules"
  158. mkdir -p "$MODULES_PATH" || exit 1
  159. }
  160. # "AM" CORE VARIABLES
  161. _am() {
  162. AMCLI="am"
  163. AMCLIPATH="$AMCLI"
  164. if command -v sudo >/dev/null 2>&1; then
  165. export SUDOCMD="sudo"
  166. elif command -v doas >/dev/null 2>&1; then
  167. export SUDOCMD="doas"
  168. else
  169. echo 'ERROR: No sudo or doas found'
  170. exit 1
  171. fi
  172. APPSPATH="/opt"
  173. AMPATH="$APPSPATH/$AMCLI"
  174. _create_cache_dir
  175. MODULES_PATH="$AMPATH/modules"
  176. }
  177. # DETERMINE WHEN TO USE "AM" OR "APPMAN"
  178. if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
  179. _am
  180. mkdir -p "$MODULES_PATH" || exit 1
  181. elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
  182. _am
  183. AMPATH="$AMCACHEDIR"
  184. MODULES_PATH="/usr/lib/am/modules"
  185. else
  186. _appman
  187. fi
  188. _detect_appman_apps() {
  189. [ -f "$APPMANCONFIG/appman-config" ] && APPMAN_APPSPATH=$(<"$APPMANCONFIG/appman-config")
  190. if ! echo "$APPMAN_APPSPATH" | grep -q "^/"; then
  191. [ -f "$APPMANCONFIG/appman-config" ] && APPMAN_APPSPATH="$HOME/$(<"$APPMANCONFIG/appman-config")"
  192. fi
  193. }
  194. _determine_args() {
  195. ARGPATHS=$(find "$APPSPATH" -maxdepth 2 -name 'remove' -print 2>/dev/null | sort -u | sed 's|/remove||g')
  196. ARGS=$(echo "$ARGPATHS" | xargs -n 1 basename 2>/dev/null)
  197. if [ "$AMCLI" = am ]; then
  198. _detect_appman_apps
  199. if [ -d "$APPMAN_APPSPATH" ]; then
  200. APPMAN_PATHS=$(find "$APPMAN_APPSPATH" -maxdepth 2 -name 'remove' -print 2>/dev/null | sort -u | sed 's|/remove||g')
  201. ARGPATHS=$(printf "%b\n%b" "$ARGPATHS" "$APPMAN_PATHS")
  202. ARGS=$(echo "$ARGPATHS" | xargs -n 1 basename 2>/dev/null)
  203. fi
  204. fi
  205. # use "argpath=$(echo "$ARGPATHS" | grep "/$arg$")" to determine the full path of "arg"
  206. }
  207. _icon_theme_export_to_datadir() {
  208. PNG="$(file "$APPSPATH"/*/icons/* | grep -i '.png' | awk -F":" '{print $1}' | grep -vi .png)"
  209. SVG="$(file "$APPSPATH"/*/icons/* | grep -i '.svg' | awk -F":" '{print $1}' | grep -vi .svg)"
  210. for file in $PNG; do ln -s "$file" "${file}".png; done
  211. for file in $SVG; do ln -s "$file" "${file}".svg; done
  212. if [ -n "$APPMAN_APPSPATH" ]; then
  213. PNG="$(file "$APPMAN_APPSPATH"/*/icons/* | grep -i '.png' | awk -F":" '{print $1}' | grep -vi .png)"
  214. SVG="$(file "$APPMAN_APPSPATH"/*/icons/* | grep -i '.svg' | awk -F":" '{print $1}' | grep -vi .svg)"
  215. for file in $PNG; do ln -s "$file" "${file}".png; done
  216. for file in $SVG; do ln -s "$file" "${file}".svg; done
  217. fi
  218. mkdir -p "$DATADIR"/icons/hicolor/scalable/apps
  219. find "$DATADIR"/icons/hicolor/scalable/apps -xtype l -exec rm {} \;
  220. ln -s "$APPSPATH"/*/icons/*.* "$DATADIR"/icons/hicolor/scalable/apps
  221. [ -n "$APPMAN_APPSPATH" ] && ln -s "$APPMAN_APPSPATH"/*/icons/*.* "$DATADIR"/icons/hicolor/scalable/apps
  222. }
  223. ################################################################################################################################################################
  224. # FINALIZE
  225. ################################################################################################################################################################
  226. AMCLIUPPER=$(echo "$AMCLI" | tr '[:lower:]' '[:upper:]')
  227. # Create new data directory and move important files there
  228. AMDATADIR="$DATADIR/AM"
  229. mkdir -p "$AMDATADIR"
  230. # DEVELOPER MODE
  231. if [ -f "$AMDATADIR"/betatester ]; then
  232. AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/dev"
  233. AMBRANCH=$(basename "$AMREPO")
  234. MODULES_SOURCE="$AMREPO/modules"
  235. fi
  236. _betatester_message_on() {
  237. if [ -f "$AMDATADIR"/betatester ]; then
  238. echo "$DIVIDING_LINE"; echo "\"$AMCLIUPPER\" $AMVERSION: DEVELOPER MODE"; echo "$DIVIDING_LINE"
  239. fi
  240. }
  241. ################################################################################################################################################################
  242. # APPS DATABASE
  243. ################################################################################################################################################################
  244. # Apps database in use
  245. APPSDB="${APPSDB:-$AMREPO/programs/$ARCH}"
  246. APPSLISTDB="${APPSLISTDB:-$AMREPO/programs/$ARCH-apps}"
  247. ################################################################################################################################################################
  248. # SECURITY
  249. ################################################################################################################################################################
  250. # SAFETY CHECKS
  251. _am_dependences_check() {
  252. # Check for essential commands required by the application
  253. missing_deps=""
  254. AMDEPENDENCES="cat chmod chown curl file grep sed wget"
  255. for name in $AMDEPENDENCES; do
  256. if ! command -v "$name" >/dev/null 2>&1; then
  257. missing_deps="$name $missing_deps"
  258. fi
  259. done
  260. # Exit if any essential command is missing
  261. if [ -n "$missing_deps" ]; then
  262. echo "$DIVIDING_LINE"
  263. printf " ${RED}💀 ERROR! MISSING ESSENTIAL COMMANDS\033[0m: %s\n\n Install the above and try again! \n" "${missing_deps[*]}"
  264. echo "$DIVIDING_LINE"
  265. printf "%bList of the %b core dependences\033[0m:\n\n%b\n" "${Green}" "$AMCLIUPPER $AMVERSION" "$AMDEPENDENCES" | _fit
  266. echo "$DIVIDING_LINE"
  267. printf "If this message appears it is because you are missing some dependency and if its the first time its because something new has been introduced.\n\n" | _fit
  268. printf " See %bhttps://github.com/ivan-hc/AM#core-dependences\033[0m for more information\n" "${LightBlue}"
  269. echo "$DIVIDING_LINE"
  270. exit 1
  271. fi
  272. }
  273. _check_ubuntu_mess() {
  274. if command -v unshare >/dev/null 2>&1 && ! unshare --user -p /bin/true >/dev/null 2>&1; then
  275. echo "$DIVIDING_LINE"
  276. printf "\n %b⚠️ WARNING: ACCESS TO USER NAMESPACES IS RESTRICTED! \033[0m\n\n" "${RED}"
  277. echo " Some apps may not run, you need to enable access to user namespaces, see"
  278. printf " %bhttps://github.com/ivan-hc/AM/blob/main/docs/troubleshooting.md#ubuntu-mess\033[0m\n" "${LightBlue}"
  279. echo " to know more."
  280. echo ""
  281. echo "$DIVIDING_LINE"
  282. fi
  283. }
  284. _am_dependences_check
  285. _check_ubuntu_mess
  286. # Function to check online connections (uses github.com by default, as the database and CLI itself are stored/hosted there)
  287. _online_check() {
  288. if ! wget -q --tries=10 --timeout=20 --spider https://github.com; then
  289. printf "\n %b is offline, please check your internet connection and try again\n\n" "$AMCLI"
  290. exit 0
  291. fi
  292. }
  293. # BLACKLIST FILES
  294. appimagelauncher_msg="Your installation of AppImageLauncher may have been done via DEB, RPM, or AUR, which interrupts the \
  295. natural operation of \"systemd-binfmt\" in addition to launching the aforementioned daemon. To avoid problems with \"$AMCLIUPPER\" \
  296. and any other AppImages helper, it's preferable to use \"only\" the standalone AppImage of AppImageLauncher, whose official \
  297. updated release can also be installed via \"$AMCLIUPPER\". But as long as you have the currently installed version, you can't use this CLI."
  298. _blacklisted_file() {
  299. printf "\n %b💀WARNING! Detected \"%b\"\033[0m\n\n" "${RED}" "$blacklisted_file"
  300. echo "It will prevent \"$AMCLIUPPER\" from working correctly with AppImages, especially when extracting, integrating and updating them." | _fit
  301. echo ""
  302. if echo "$blacklisted_file" | grep -q appimagelauncherd; then
  303. echo "$appimagelauncher_msg" | _fit
  304. echo "" && echo " Please remove \"AppImageLauncher\", reboot and retry!"
  305. else
  306. echo " Please remove \"$blacklisted_file\", reboot and retry!"
  307. fi
  308. echo ""
  309. exit 0
  310. }
  311. if command -v appimaged &>/dev/null; then
  312. blacklisted_file=$(command -v appimaged)
  313. _blacklisted_file
  314. elif command -v appimagelauncherd &>/dev/null; then
  315. blacklisted_file=$(command -v appimagelauncherd)
  316. _blacklisted_file
  317. fi
  318. ################################################################################################################################################################
  319. # 3RD PARTY
  320. ################################################################################################################################################################
  321. _use_newrepo() {
  322. [ -z "$2" ] && echo " USAGE: $AMCLI $1 [ARGUMENT]" && exit 1
  323. case $2 in
  324. 'add')
  325. if [ -z "$3" ]; then
  326. echo " USAGE: $AMCLI $1 $2 /path/to/dir"; echo " $AMCLI $1 $2 {URL}"; exit 1
  327. else
  328. echo "$3" >> "$AMDATADIR/newrepo-lists"
  329. fi
  330. ;;
  331. 'enable'|'on')
  332. [ ! -f "$AMDATADIR/newrepo-lists" ] && echo " ERROR, \"$AMDATADIR/newrepo-lists\" file not found" && exit 1
  333. [ -f "$AMDATADIR/newrepo-off" ] && mv "$AMDATADIR/newrepo-off" "$AMDATADIR/newrepo-on" && echo " New repo ON!"
  334. ;;
  335. 'disable'|'off')
  336. [ ! -f "$AMDATADIR/newrepo-lists" ] && echo " ERROR, \"$AMDATADIR/newrepo-lists\" file not found" && exit 1
  337. [ -f "$AMDATADIR/newrepo-on" ] && mv "$AMDATADIR/newrepo-on" "$AMDATADIR/newrepo-off" && echo " New repo OFF!"
  338. ;;
  339. 'info')
  340. printf " Source: %b\n Apps: %b\n List: %b\n" "$AMREPO" "$APPSDB" "$APPSLISTDB"
  341. ;;
  342. 'purge')
  343. [ -f "$AMDATADIR/newrepo-lists" ] && rm -f "$AMDATADIR"/newrepo* && echo " Removed all 3rd party repositories"
  344. ;;
  345. 'select')
  346. [ ! -f "$AMDATADIR/newrepo-lists" ] && echo " ERROR, \"$AMDATADIR/newrepo-lists\" file not found" && exit 1
  347. printf "Select a repo from the list or press CTRL+C to abort:\n%b\n" "$DIVIDING_LINE"; sleep 1
  348. select repo in $(sort -u "$AMDATADIR/newrepo-lists" | uniq); do
  349. test -n "$repo" && break
  350. echo ">>> Invalid Selection"
  351. done
  352. echo "$repo" > "$AMDATADIR/newrepo-on"
  353. ;;
  354. esac
  355. }
  356. # 3RD PARTY DATABASES
  357. _am_newrepo_check() {
  358. # Determine if the CLI uses the "main" branch of https://github.com/ivan-hc/AM or an alternative one
  359. if [ -f "$AMDATADIR/newrepo-on" ]; then
  360. if grep -q "^http" "$AMDATADIR/newrepo-on"; then
  361. AMREPO=$(<"$AMDATADIR/newrepo-on")
  362. elif grep -q "^/" "$AMDATADIR/newrepo-on"; then
  363. AMREPO="file://$(<"$AMDATADIR/newrepo-on")"
  364. fi
  365. AMBRANCH=$(basename "$AMREPO")
  366. export APPSDB="$AMREPO/programs/$ARCH"
  367. export APPSLISTDB="$AMREPO/programs/$ARCH-apps"
  368. export MODULES_PATH="$AMPATH/modules"
  369. if [ "$1" != "newrepo" ] && [ "$1" != "neodb" ]; then
  370. echo "$DIVIDING_LINE"; echo " Source: $AMREPO"; echo "$DIVIDING_LINE"
  371. fi
  372. fi
  373. }
  374. _am_newrepo_check "$@"
  375. ################################################################################################################################################################
  376. # 3RD PARTY SOURCES
  377. ################################################################################################################################################################
  378. # APPBUNDLEHUB
  379. #export appbundle_repo="https://github.com/xplshn/AppBundleHUB"
  380. #export appbundle_readme="https://raw.githubusercontent.com/ivan-hc/am-extras/main/appbundlehub/${ARCH}.md"
  381. #[ -n "$appbundle_readme" ] && third_party_flags="$third_party_flags --appbundle"
  382. # SOARPKGS
  383. export soarpkg_repo="https://github.com/pkgforge/soarpkgs"
  384. export soarpkg_readme="https://raw.githubusercontent.com/ivan-hc/am-extras/main/soarpkgs/${ARCH}.md"
  385. [ -n "$soarpkg_readme" ] && third_party_flags="$third_party_flags --soarpkg"
  386. export soarpkg_missing_file_msg="\nIt appears that the selected file is not available.\n\nThis happens due to pkgforge's mirror Issue.\nLearn more: https://docs.pkgforge.dev/repositories/bincache/cache\n\nAlternatively, install \"soar\" or \"dbin\" and use those.\n\n"
  387. # TOOLPACKS/SOARPKGS
  388. export toolpack_repo="https://github.com/pkgforge/soarpkgs (ex toolpacks)"
  389. export toolpack_readme="https://raw.githubusercontent.com/ivan-hc/am-extras/main/soarpkgs-toolpacks/${ARCH}.md"
  390. [ -n "$toolpack_readme" ] && third_party_flags="$third_party_flags --toolpack"
  391. export toolpack_missing_file_msg="\nIt appears that the selected file is not available.\n\nThis happens due to pkgforge's mirror Issue.\nLearn more: https://docs.pkgforge.dev/repositories/bincache/cache\n\nAlternatively, install \"soar\" or \"dbin\" and use those.\n\n"
  392. #################################
  393. # ALL THE ABOVE
  394. #################################
  395. third_party_lists=$(echo "$third_party_flags" | tr '-' '\n' | sed 's/ //g' | xargs)
  396. _remove_known_third_party_extensions() {
  397. sed "s/$(echo "$third_party_lists" | sed 's/ /\\|/g')$//g; s/\.$//g"
  398. }
  399. _files_db_third_party() {
  400. for tp_list in $third_party_lists; do
  401. if test -f "$APPSPATH"/"$arg"/.am-installer/*."$tp_list"; then
  402. export DB="$tp_list"
  403. fi
  404. done
  405. }
  406. _third_party_lsts_filter() {
  407. grep -v -- "---\|^| appname" | grep "^| .* | .* | http.* | http.* | .* |$" 2>/dev/null | awk -F'|' '{print $2, $3}' | sed 's/^/◆/g; s/ / : /g; s/ $//g'
  408. }
  409. _sync_third_party_lists() {
  410. for tp_list in $third_party_lists; do
  411. rm -f "$AMDATADIR"/"$ARCH"-"$tp_list"
  412. tprepo_readme="${tp_list}_readme"
  413. if [ -n "${!tprepo_readme}" ]; then
  414. curl -Ls "${!tprepo_readme}" | _third_party_lsts_filter \
  415. | sed "s/$/. To install it use the --$tp_list flag or the .$tp_list extension./g" | sort > "$AMDATADIR"/"$ARCH"-"$tp_list" \
  416. || touch "$AMDATADIR"/"$ARCH"-"$tp_list"
  417. fi
  418. done
  419. }
  420. _completion_list_third_party() {
  421. for tp_list in $third_party_lists; do
  422. [ -f "$AMDATADIR"/"$ARCH"-"$tp_list" ] && awk '{print $2}' "$AMDATADIR"/"$ARCH"-"$tp_list" >> "$AMDATADIR"/list && awk '{print $2}' "$AMDATADIR"/"$ARCH"-"$tp_list" | sed -e "s/$/.$tp_list/" >> "$AMDATADIR"/list
  423. done
  424. }
  425. export awk_name="1" awk_description="2" awk_site="3" awk_dl="4" awk_ver="5" # Numbers to use in "awk" to determine columns
  426. third_party_flags_message=""
  427. if [ -n "$third_party_flags" ]; then
  428. for flag in $third_party_flags; do
  429. tpflag_name=$(echo "$flag" | tr '-' '\n ' | grep .)
  430. tprepo_name="${tpflag_name}_repo"
  431. third_party_flags_message="$third_party_flags_message\n
  432. ${Gold}--$tpflag_name\033[0m
  433. ${LightBlue}$AMCLI -i --$tpflag_name {PROGRAM}\033[0m
  434. ${LightBlue}am -i --$tpflag_name --user {PROGRAM}\033[0m
  435. ${LightBlue}$AMCLI -l --$tpflag_name\033[0m
  436. Description: This is a flag to use in \"-i\" and \"-l\" to install/list ${tpflag_name^}s from ${!tprepo_name}. You can also use it in \"-q\" as a keyword. For installations you can use .$tpflag_name as the package extension instead of using the flag.
  437. "
  438. done
  439. fi
  440. [ -z "$third_party_flags_message" ] && third_party_flags_message="none\n"
  441. ################################################################################################################################################################
  442. # UTILITIES
  443. ################################################################################################################################################################
  444. # COMPLETION LIST
  445. available_options="about add apikey backup clean config disable downgrade download enable extra files hide home icons info \
  446. install install-appimage launcher list lock neodb newrepo nolibfuse off on overwrite purge query remove sandbox \
  447. select sync template test unhide unlock update --all --appimages --apps --byname --config --convert --debug \
  448. --devmode-disable --devmode-enable --disable-notifications --enable-notifications --force-latest --home --icons \
  449. -ias --launcher --less --pkg --rollback --disable-sandbox --sandbox --system --user $third_party_flags"
  450. _completion_lists() {
  451. # Remove existing lists and download new ones
  452. curl -Ls "$APPSLISTDB" > "$AMDATADIR/$ARCH-apps"
  453. awk -v FS="(◆ | : )" '{print $2}' <"$AMDATADIR"/"$ARCH"-apps > "$AMDATADIR"/list
  454. _completion_list_third_party
  455. # Append options to the list
  456. for o in $available_options; do
  457. echo "$o" >> "$AMDATADIR"/list
  458. done
  459. # Detecl valid lists
  460. valid_lists="apps$\|appimages$"
  461. for tp_list in $third_party_lists; do
  462. valid_lists="$valid_lists\|$tp_list$"
  463. done
  464. for l in "$AMDATADIR"/"$ARCH"-*; do
  465. ! echo "$l" | grep -q "$valid_lists" && rm -f "$l"
  466. done
  467. }
  468. # BASH, FISH AND ZSH COMPLETION
  469. completion_file="$DATADIR/bash-completion/completions/$AMCLI"
  470. mkdir -p "$DATADIR/bash-completion/completions" || exit 1
  471. if ! grep -o " $AMCLI$" "$completion_file" >/dev/null 2>&1; then
  472. echo "complete -W \"\$(cat $AMDATADIR/list 2>/dev/null)\" $AMCLI" >> "$completion_file"
  473. if [ -f "${ZDOTDIR:-$HOME}"/.zshrc ] && echo "$SHELL" | grep -q "zsh"; then
  474. cat <<-HEREDOC >> "${ZDOTDIR:-$HOME}"/.zshrc
  475. autoload bashcompinit
  476. bashcompinit
  477. source "$completion_file"
  478. HEREDOC
  479. fi
  480. echo "Shell completion has been enabled!"
  481. fi
  482. if [ -d "$DATADIR"/fish/completions ] || [ -d /etc/fish/completions ] || [ -d /usr/share/fish/completions ]; then
  483. command -v fish 1>/dev/null && [ ! -f "$CONFIGDIR"/fish/completions/am.fish ] && mkdir -p "$CONFIGDIR"/fish/completions && echo "complete -c am -f -a \"(cat $DATADIR/AM/list 2>/dev/null)\"" > "$CONFIGDIR"/fish/completions/am.fish
  484. fi
  485. # VERSION OF THE INSTALLED APPS
  486. # Filters
  487. _check_version_filters() {
  488. sed -E "s/$ARCH|amd64|x86-64|x64|basic|standard|full|help|Qt[0-9]//g; s/-/\n/g; s/_/\n/g;" |\
  489. grep -vi "appimage\|$arg\|?\|tar." | grep "[0-9]" | head -1 | sed 's/^v//g; s/^\.//g; s/\.$//g;'
  490. }
  491. _check_version_grep_numbers() {
  492. grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1
  493. }
  494. # Versions
  495. _check_version_if_any_version_reference_is_somewhere() {
  496. txt_files=$(file "$argpath"/* | awk -F: '/ASCII text/ {print $1}')
  497. for txtf in $txt_files; do
  498. if [ -f "$argpath"/tbb_version.json ] && grep -qi "\"version\":" "$argpath"/tbb_version.json; then
  499. APPVERSION=$(sort "$argpath"/tbb_version.json | tr '"' '\n' | grep "^[0-9]" | head -1)
  500. elif grep -qi "^version=" "$txtf" && grep -qi "^name=" "$txtf"; then
  501. APPVERSION=$(grep -i "^version=" "$txtf" | cut -c 9- | tr -cd '[:alnum:]._-')
  502. fi
  503. done
  504. }
  505. _check_version_if_version_file_exists() {
  506. APPVERSION=$(sort "$argpath"/version | head -1 | sed 's:.*/::' | _check_version_filters)
  507. if [ -z "$APPVERSION" ]; then
  508. if grep -q "download$" "$argpath"/version; then
  509. APPVERSION=$(sort "$argpath"/version | tr '/' '\n' | _check_version_filters)
  510. elif grep -q "://" "$argpath"/version; then
  511. APPVERSION=$(sort "$argpath"/version | tr '/' '\n' | _check_version_grep_numbers)
  512. elif grep -q "/v[0-9]*" "$argpath"/version; then
  513. APPVERSION=$(sort "$argpath"/version | tr '/' '\n' | grep "^v[0-9]" | head -1 | sed 's/^v//g')
  514. elif [ "$(sort "$argpath"/version | wc -w | sed 's/ //g')" = 1 ]; then
  515. APPVERSION=$(sort "$argpath"/version | head -1)
  516. fi
  517. fi
  518. if [ -z "$APPVERSION" ]; then
  519. if grep -q "http.*download/.*[0-9].*/" "$argpath"/version; then
  520. APPVERSION=$(sort "$argpath"/version | tr '/-' '\n' | grep "[0-9]" | _check_version_filters | tail -1)
  521. fi
  522. fi
  523. }
  524. _check_version_if_library() {
  525. LIBNAME=$(sort "$argpath"/remove | tr ' ' '\n' | grep "usr/local/lib" | head -1 | sed 's:.*/::')
  526. APPVERSION=$(find /usr/local/lib -type f -name "$LIBNAME" -type f | sed 's:.*.so.::' | tail -1)
  527. }
  528. _check_version_if_binary_in_place() {
  529. APPVERSION=$(date -r "$argpath"/"$arg" "+%Y.%m.%d")
  530. }
  531. _check_version() {
  532. rm -f "$AMCACHEDIR"/version-args
  533. _determine_args
  534. for arg in $ARGS; do
  535. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  536. if [ -f "$argpath"/remove ]; then
  537. if [ -f "$argpath"/version ]; then
  538. _check_version_if_version_file_exists
  539. elif [ "$arg" = "$AMCLI" ]; then
  540. APPVERSION="$AMVERSION"
  541. elif echo "$arg" | grep -q "ffwa-"; then
  542. APPVERSION="WebApp"
  543. elif grep -q "usr/local/lib" "$argpath"/remove 2>/dev/null; then
  544. _check_version_if_library
  545. elif [ -f "$argpath"/updater ] || grep -qi "version=" "$argpath"/*; then
  546. _check_version_if_any_version_reference_is_somewhere
  547. else
  548. APPVERSION="unknown"
  549. fi
  550. if [ -z "$APPVERSION" ]; then
  551. [ -f "$argpath"/"$arg" ] && _check_version_if_binary_in_place || APPVERSION="unknown"
  552. fi
  553. echo " ◆ $arg | $APPVERSION" >> "$AMCACHEDIR"/version-args
  554. fi
  555. done
  556. }
  557. _check_version_for_auto_updatable_apps() {
  558. _determine_args
  559. for arg in $ARGS; do
  560. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  561. if [ -f "$argpath"/updater ]; then
  562. _check_version_if_any_version_reference_is_somewhere
  563. if [ "$AMCLI" = am ] && [ -d "$CACHEDIR"/am ] && grep -q " ◆ $arg |" "$CACHEDIR"/am/version-args; then
  564. OLDAPPVERSION=$(grep " ◆ $arg |" "$CACHEDIR"/am/version-args | awk 'END {print $NF}')
  565. sed -i "/ ◆ $arg |/s#$OLDAPPVERSION#$APPVERSION#" "$CACHEDIR"/am/*args*
  566. fi
  567. if [ -d "$CACHEDIR"/appman ] && grep -q " ◆ $arg |" "$CACHEDIR"/appman/version-args; then
  568. OLDAPPVERSION=$(grep " ◆ $arg |" "$CACHEDIR"/appman/version-args | awk 'END {print $NF}')
  569. sed -i "/ ◆ $arg |/s#$OLDAPPVERSION#$APPVERSION#" "$CACHEDIR"/appman/*args*
  570. fi
  571. fi
  572. done
  573. }
  574. if [ -f "$AMCACHEDIR"/version-args ]; then
  575. _check_version_for_auto_updatable_apps 2>/dev/null
  576. fi
  577. # This function removes all info and versions from the register
  578. _remove_info_files() {
  579. rm -f "$AMCACHEDIR"/files*
  580. rm -f "$AMCACHEDIR"/version-args
  581. }
  582. ################################################################################################################################################################
  583. # APIKEY
  584. ################################################################################################################################################################
  585. ghapikey_file="$AMDATADIR/ghapikey.txt"
  586. # Set header authorization if GitHub API key file exists
  587. [ -f "$ghapikey_file" ] && HeaderAuthWithGITPAT=" --header \"Authorization: token $(<"$ghapikey_file")\" "
  588. _use_apikey() {
  589. case $2 in
  590. 'del'|'delete'|'remove')
  591. [ -f "$ghapikey_file" ] || { echo " ✖ No file named $ghapikey_file has been found"; exit 1; }
  592. rm -f "$ghapikey_file" && echo " ✔ $ghapikey_file has been removed"
  593. exit 0
  594. esac
  595. if [[ "$2" =~ ^(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$ ]]; then
  596. test_apikey_output_with_wget=$(curl -Ls --header "Authorization: token $2" 'https://api.github.com/repos/ivan-hc/AM/releases' | head -1)
  597. [ -n "$test_apikey_output_with_wget" ] && echo "$2" > "$ghapikey_file" \
  598. && echo "Validation successful!" || echo "ERROR: This is not a valid key!"
  599. else
  600. echo "ERROR: Wrong expression, validation failed!"
  601. fi
  602. }
  603. _update_github_api_key_in_the_updater_files() {
  604. if [ -f "$ghapikey_file" ]; then
  605. ghapikey=$(<"$ghapikey_file")
  606. updater_files=("$APPSPATH"/*/AM-updater) # Assuming AM-updater is one level deeper
  607. for f in "${updater_files[@]}"; do
  608. if [ -f "$f" ] && grep -q "https://api.github.com" "$f"; then
  609. # Check if the file already contains a valid API key
  610. if ! grep -qE "(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})" "$f"; then
  611. # Insert HeaderAuthWithGITPAT before the GitHub API URL
  612. sed -i "s#https://api.github.com#$HeaderAuthWithGITPAT https://api.github.com#g" "$f"
  613. else
  614. # Replace existing API key with the one from ghapikey.txt
  615. 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"
  616. fi
  617. fi
  618. done
  619. fi
  620. }
  621. ################################################################################################################################################################
  622. # APPMAN MODE
  623. ################################################################################################################################################################
  624. APPMAN_MSG="$DIVIDING_LINE\n \"AM\" is running as \"AppMan\", use ${Green}am --system\033[0m to switch it back to \"AM\"\n$DIVIDING_LINE\n"
  625. APPMAN_MSG_OFF="$DIVIDING_LINE\n \"AppMan Mode\" disabled! \n$DIVIDING_LINE\n"
  626. APPMAN_MSG_THINK="$DIVIDING_LINE\nNOTE: You can also choose to simply use \"--user\" as a flag to install apps locally \
  627. (options \"-i\", \"-ia\" and \"-e\") instead of going fully into \"AppMan Mode\". \"AM\" can handle local applications as well.\n$DIVIDING_LINE\n"
  628. _use_appman() {
  629. _online_check
  630. [ "$CLI" = appman ] && echo " This function only works for AM" && exit 0
  631. printf "%b" "$APPMAN_MSG_THINK" | _fit
  632. read -r -p " Do you wish to enter \"AppMan Mode\" (y,N)?" yn
  633. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  634. echo "$DIVIDING_LINE"
  635. else
  636. [ ! -f "$APPMANCONFIG"/appman-mode ] && mkdir -p "$APPMANCONFIG" && touch "$APPMANCONFIG"/appman-mode
  637. _appman && printf "%b" "$APPMAN_MSG"
  638. fi
  639. }
  640. if [ "$AMCLI" = am ]; then
  641. if [ -f "$APPMANCONFIG"/appman-mode ]; then
  642. [ ! -f "$APPMANCONFIG"/appman-config ] && printf "%b" "$APPMAN_MSG"
  643. _appman
  644. AMCLIPATH="$(realpath "$0")"
  645. elif [ ! -w "$AMPATH" ]; then
  646. read -r -p " \"AM\" is read-only, want to use it in \"AppMan Mode\" (Y,n)? " yn
  647. if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
  648. exit 0
  649. else
  650. echo "$DIVIDING_LINE"; echo "\"AppMan Mode\" enabled!"; echo "$DIVIDING_LINE"
  651. _use_appman 1>/dev/null
  652. fi
  653. fi
  654. fi
  655. ################################################################################################################################################################
  656. # CLEAN
  657. ################################################################################################################################################################
  658. _clean_amcachedir_message() {
  659. _clean_amcachedir
  660. [ "$AMCLI" = am ] && [ -d "$CACHEDIR"/am ] && echo " ✔ Clear the contents of $CACHEDIR/am"
  661. [ -d "$CACHEDIR"/appman ] && echo " ✔ Clear the contents of $CACHEDIR/appman"
  662. }
  663. _clean_all_home_cache_directories_of_appimages() {
  664. for arg in $ARGPATHS; do
  665. if test -d "$arg"/*.home/.cache; then
  666. rm -Rf "$arg"/*/*.home/.cache/* && echo " ✔ Clear the contents of $arg/*.home/.cache"
  667. fi
  668. done
  669. }
  670. _clean_all_tmp_directories_from_appspath() {
  671. _determine_args
  672. for arg in $ARGPATHS; do
  673. if [ -d "$arg"/tmp ]; then
  674. rm -Rf "$arg"/tmp && echo " ✔ Removed $arg/tmp"
  675. fi
  676. done
  677. }
  678. _clean_launchers() {
  679. if [ -d "$DATADIR"/applications/AppImages ]; then
  680. rm -f "$AMCACHEDIR"/mountpoints
  681. for var in "$DATADIR"/applications/AppImages/*.desktop; do
  682. # full path to appimage
  683. appimagename=$(awk -F'=| ' '/Exec=/{print $2; exit}' "$var" | sed 's/"//g; s/\s.*$//')
  684. # name of the appimage
  685. launcher2del=$(basename -- "$(echo "$appimagename" | tr '[:upper:]' '[:lower:]')")
  686. # removable mount point where the appimage may be stored
  687. mountpoint=$(echo "$appimagename" | cut -d'/' -f1-4)
  688. if [ ! -f "$appimagename" ]; then
  689. if echo "$appimagename" | grep -q "^/media/\|^/mnt/"; then
  690. mountpoint=$(echo "$appimagename" | cut -d'/' -f1-4)
  691. unmounted_point=$(echo "$mountpoint" | cut -d'/' -f1-2)
  692. elif echo "$appimagename" | grep -q "^/run/media/"; then
  693. mountpoint=$(echo "$appimagename" | cut -d'/' -f1-5)
  694. unmounted_point="/run/media"
  695. else
  696. mountpoint=""
  697. fi
  698. if [ -n "$mountpoint" ] && [ ! -d "$mountpoint" ]; then
  699. echo "$mountpoint" >> "$AMCACHEDIR"/mountpoints
  700. echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
  701. echo " related AppImage is located in an unmounted path of $unmounted_point"
  702. else
  703. rm -f "$var"
  704. [ -n "$BINDIR" ] && [ -n "$launcher2del" ] && rm -f "$BINDIR"/"$launcher2del"*
  705. fi
  706. fi
  707. done
  708. if [ -f "$AMCACHEDIR"/mountpoints ]; then
  709. mountpoints=$(sort "$AMCACHEDIR"/mountpoints)
  710. for m in $mountpoints; do
  711. [ ! -d "$m" ] && mountpoint_enabled=1
  712. done
  713. fi
  714. [ -z "$mountpoint_enabled" ] && [ -n "$BINDIR" ] && cd "$BINDIR" && find . -xtype l -delete
  715. rm -f "$AMCACHEDIR"/mountpoints
  716. echo ' ✔ Removed orphaned launchers produced with the "--launcher" option'
  717. rmdir "$DATADIR"/applications/AppImages
  718. else
  719. [ -n "$BINDIR" ] && cd "$BINDIR" && find . -xtype l -delete
  720. fi
  721. }
  722. _clean_old_modules() {
  723. MODULES=$(sort "$(realpath "$0")" | tr '"' '\n' | grep "[a-z]\.am$" | uniq)
  724. [ -z "$MODULES_PATH" ] && exit 1
  725. for m in "$MODULES_PATH"/*; do
  726. if [[ "${MODULES}" != *"$(basename -- "$m")"* ]];then
  727. rm -f "$m" 2>/dev/null
  728. echo " ✔ Removed obsolete module named \"$(basename -- "$m")\""
  729. fi
  730. done
  731. }
  732. _use_clean() {
  733. echo " Cleaning temporary files and folders..." && sleep 0.1
  734. i=100 && while [ "$i" -ge 0 ]; do
  735. printf " %03d\r" "$i" && sleep 0.0001 && i=$((i - 1))
  736. done
  737. _detect_appman_apps
  738. _determine_args
  739. _clean_amcachedir_message
  740. _clean_all_home_cache_directories_of_appimages
  741. _clean_all_tmp_directories_from_appspath
  742. _clean_launchers 2>/dev/null
  743. _clean_old_modules
  744. }
  745. ################################################################################################################################################################
  746. # HIDE/UNHIDE
  747. ################################################################################################################################################################
  748. _use_hide_unhide() {
  749. entries="$(echo "$@" | cut -f2- -d ' ')"
  750. if [ "$1" = hide ]; then
  751. for arg in $entries; do
  752. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  753. [ -f "$argpath/remove" ] && mv "$argpath/remove" "$argpath/remove.old" \
  754. && echo "✔ $argpath has been hidden" || echo "✖ Can't hide \"$arg\", app already hidden or non-existent"
  755. done
  756. else
  757. for arg in $entries; do
  758. [ "$AMCLI" = am ] && [ -f "/opt/$arg/remove.old" ] && mv "/opt/$arg/remove.old" "/opt/$arg/remove" \
  759. && echo "✔ /opt/$arg can be managed again"
  760. [ -n "$APPMAN_APPSPATH" ] && [ -f "$APPMAN_APPSPATH/$arg/remove.old" ] && mv "$APPMAN_APPSPATH/$arg/remove.old" "$APPMAN_APPSPATH/$arg/remove" \
  761. && echo "✔ $APPMAN_APPSPATH/$arg can be managed again"
  762. done
  763. _clean_amcachedir
  764. fi
  765. }
  766. ################################################################################################################################################################
  767. # SYNC
  768. ################################################################################################################################################################
  769. _sync_installation_scripts() {
  770. printf "%b\n Checking for changes of the installation scripts in the online database...\n" "$DIVIDING_LINE"
  771. _determine_args
  772. for arg in $ARGS; do
  773. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  774. if [ -f "$argpath"/AM-updater ]; then
  775. mkdir -p "$argpath"/.am-installer
  776. scriptname=$(ls "$argpath/.am-installer/" | head -1)
  777. if [ -n "$scriptname" ]; then
  778. CURRENT=$(cat "$argpath"/.am-installer/"$scriptname")
  779. SOURCE=$(curl -Ls "$APPSDB"/"$scriptname")
  780. if [ "$CURRENT" = "$SOURCE" ]; then
  781. echo -ne "\r" 2>/dev/null
  782. else
  783. printf " ◆ %b%b\033[0m has changed, you may need to reinstall it, see\n https://github.com/ivan-hc/AM/blob/main/programs/%b/%b\n" "${RED}" "$scriptname" "$ARCH" "$scriptname"
  784. fi
  785. else
  786. if curl --output /dev/null --silent --head --fail "$APPSDB"/"$arg" 1>/dev/null; then
  787. printf " ◆ No installation script for %b, downloading one...\n" "$arg"
  788. mkdir -p "$argpath"/.am-installer
  789. wget -q "$APPSDB/$arg" -O "$argpath"/.am-installer/"$arg"
  790. fi
  791. fi
  792. fi
  793. done
  794. }
  795. _sync_appimages_list() {
  796. APPIMAGES_LIST="${APPIMAGES_LIST:-$AMREPO/programs/$ARCH-appimages}"
  797. curl -Ls "$APPIMAGES_LIST" > "$AMDATADIR/$ARCH-appimages"
  798. }
  799. _sync_databases() {
  800. printf "%b\n Check and update offline lists of additional databases...\n" "$DIVIDING_LINE"
  801. _sync_appimages_list
  802. _sync_third_party_lists 2>/dev/null
  803. _completion_lists
  804. }
  805. _sync_modules() {
  806. printf "%b\n Check for updates in modules...\n" "$DIVIDING_LINE"
  807. MODULES=$(curl -Ls "$AMREPO/APP-MANAGER" | tr '"' '\n' | grep "[a-z]\.am$")
  808. for module_name in $MODULES; do
  809. cd "$MODULES_PATH" || return 1
  810. if ! test -f ./"$module_name"; then
  811. echo " ◆ Downloading $module_name (not previously installed)..."
  812. curl -Os "$MODULES_SOURCE/$module_name" 2>/dev/null
  813. chmod a+x ./"$MODULENAME"
  814. fi
  815. CURRENT=$(cat ./"$module_name" 2>/dev/null)
  816. SOURCE=$(curl -Ls "$MODULES_SOURCE/$module_name")
  817. if [ "$CURRENT" = "$SOURCE" ]; then
  818. echo -ne "\r" 2>/dev/null
  819. else
  820. echo " ◆ Updating $module_name..."
  821. curl -Ls "$MODULES_SOURCE/$module_name" > ./"$module_name" 2>/dev/null
  822. fi
  823. done
  824. _clean_old_modules
  825. }
  826. _sync_amcli() {
  827. echo "$DIVIDING_LINE"
  828. CURRENT_AM_VERSION="$AMVERSION"
  829. echo -ne "\n ◆ SYNCHRONIZING \"$AMCLIUPPER\" VERSION \"$CURRENT_AM_VERSION\"...\r" && sleep 0.25
  830. _clean_amcachedir 1>/dev/null
  831. cd "$AMCACHEDIR" || return 1
  832. curl -Ls "$AMREPO"/APP-MANAGER > ./APP-MANAGER && chmod a+x ./APP-MANAGER
  833. echo y | mv ./APP-MANAGER "$(realpath "$0")"
  834. NEW_AM_VERSION=$("$AMCLIPATH" -v)
  835. if [ ! "$CURRENT_AM_VERSION" = "$NEW_AM_VERSION" ]; then
  836. echo -ne " A new release of \"$AMCLIUPPER\" is available, please wait...\r"
  837. echo " ◆ \"$AMCLIUPPER\" IS NOW UPDATED TO THE BRAND NEW \"$NEW_AM_VERSION\" VERSION!"
  838. printf "\n Replacement of version \"%b\" currently in use, COMPLETED! \n" "$CURRENT_AM_VERSION"
  839. printf "\n See https://github.com/ivan-hc/AM/commits/main\n\n"
  840. else
  841. echo " ◆ \"$AMCLIUPPER\" IS ALREADY UPDATED, CURRENT VERSION \"$CURRENT_AM_VERSION\""
  842. printf "\n See https://github.com/ivan-hc/AM/commits/%b\n\n" "$AMBRANCH"
  843. fi
  844. }
  845. _use_sync() {
  846. _online_check
  847. _betatester_message_on
  848. _sync_installation_scripts
  849. _sync_databases
  850. if [ "$(realpath "$0")" != "/usr/bin/am" ] && [ "$AMSYNC" != 1 ]; then
  851. _sync_modules
  852. _sync_amcli
  853. fi
  854. echo "$DIVIDING_LINE"
  855. }
  856. ################################################################################################################################################################
  857. # UPDATE
  858. ################################################################################################################################################################
  859. _update_updatable_apps_msg_head() {
  860. printf " \"%b\" CAN MANAGE UPDATES FOR THE FOLLOWING PROGRAMS:\n%b\n\n" "$AMCLIUPPER" "$DIVIDING_LINE"
  861. [ -f "$AMCACHEDIR/updatable-args-list" ] && grep "◆" "$AMCACHEDIR/updatable-args-list" | sort || echo " None"
  862. printf "\n All self-updatable programs are excluded\n"
  863. echo "$DIVIDING_LINE"
  864. }
  865. _update_list_updatable_apps() {
  866. _determine_args
  867. _check_version
  868. for arg in $ARGS; do
  869. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  870. if [ -d "$argpath" ]; then
  871. if [ -f "$argpath/AM-updater" ]; then
  872. app_version=$(grep -w " ◆ $arg |" "$AMCACHEDIR/version-args" | sed 's:.*| ::')
  873. echo " ◆ $arg $app_version" >> "$AMCACHEDIR"/updatable-args-list
  874. fi
  875. fi
  876. done
  877. }
  878. _update_determine_apps_version_changes() {
  879. [ -z "$debug_update" ] && echo "$DIVIDING_LINE"
  880. if [ -f "$AMCACHEDIR"/updatable-args-list ]; then
  881. mv "$AMCACHEDIR"/updatable-args-list "$AMCACHEDIR"/updatable-args-list-old
  882. _update_list_updatable_apps
  883. OLDVER="$AMCACHEDIR/updatable-args-list-old"
  884. NEWVER="$AMCACHEDIR/updatable-args-list"
  885. if cmp --silent -- "$NEWVER" "$OLDVER"; then
  886. echo ' Nothing to do here!'
  887. else
  888. printf " The following apps have been updated:\n\n"
  889. diff "$OLDVER" "$NEWVER" | grep "^>" | sed 's/^> //g'
  890. echo ""
  891. fi
  892. else
  893. echo ' No apps to update here!'
  894. fi
  895. }
  896. _update_torsocks_handler() {
  897. torsocks_congif_file=$(find /etc -type f -name torsocks.conf 2>/dev/null)
  898. if [ -n "$torsocks_congif_file" ]; then
  899. if grep -q "^#AllowOutboundLocalhost 1" "$torsocks_congif_file" && command -v appimageupdatetool 1>/dev/null; then
  900. [ ! -f "$AMDATADIR"/torsocks.conf ] && cat "$torsocks_congif_file" > "$AMDATADIR"/torsocks.conf
  901. sed -i 's/^#AllowOutboundLocalhost 1/AllowOutboundLocalhost 1/g' "$AMDATADIR"/torsocks.conf
  902. [ -f "$AMDATADIR"/torsocks.conf ] && export TORSOCKS_CONF_FILE="$AMDATADIR"/torsocks.conf
  903. GH_API_ALLOWED=$(torsocks curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/releases/latest | sed 's/[()",{} ]/\n/g' | grep "^ivan-hc" | head -1)
  904. if [ -z "$GH_API_ALLOWED" ]; then
  905. printf " ✖ %b update failed, please restart %btor.service\033[0m to fix! \n" "$APPNAME" "${Green}"
  906. exit 1
  907. fi
  908. fi
  909. fi
  910. }
  911. _update_run_updater() {
  912. if grep -q "api.github.com" "$argpath"/AM-updater; then
  913. GH_API_ALLOWED=$(curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/releases/latest | sed 's/[()",{} ]/\n/g' | grep "^ivan-hc" | head -1)
  914. if [ -z "$GH_API_ALLOWED" ]; then
  915. if command -v torsocks 1>/dev/null; then
  916. _update_torsocks_handler
  917. if [ -z "$debug_update" ]; then
  918. torsocks "$argpath"/AM-updater >/dev/null 2>&1
  919. else
  920. torsocks "$argpath"/AM-updater
  921. fi
  922. else
  923. echo " ✖ $APPNAME cannot be updated, you have reached GitHub API limit. Install \"torsocks\" from your system package manager and retry!" \
  924. | fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
  925. fi
  926. else
  927. if [ -z "$debug_update" ]; then
  928. "$argpath"/AM-updater >/dev/null 2>&1
  929. else
  930. "$argpath"/AM-updater
  931. fi
  932. fi
  933. else
  934. if [ -z "$debug_update" ]; then
  935. "$argpath"/AM-updater >/dev/null 2>&1
  936. else
  937. "$argpath"/AM-updater
  938. fi
  939. fi
  940. end=$(date +%s)
  941. timelapsed=$((end - start))
  942. [ "$timelapsed" = 1 ] && echo " ◆ $APPNAME is updated, $timelapsed second elapsed!" || echo " ◆ $APPNAME is updated, $timelapsed seconds elapsed!"
  943. [ -n "$debug_update" ] && echo "$DIVIDING_LINE"
  944. }
  945. _update_app() {
  946. APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
  947. start=$(date +%s)
  948. if [ -w "$argpath"/AM-updater ]; then
  949. _update_run_updater &
  950. else
  951. echo " ✖ $APPNAME is read-only, cannot update it!"
  952. fi
  953. }
  954. _update_all_apps() {
  955. for arg in $ARGS; do
  956. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  957. cd "$argpath" || exit 1
  958. arg=$(printf '%s\n' "${PWD##*/}")
  959. if [ -f "$argpath"/AM-updater ]; then
  960. _update_app
  961. fi
  962. done
  963. wait
  964. rm -f "$AMDATADIR"/torsocks.conf
  965. _update_determine_apps_version_changes
  966. rm -Rf "$APPSPATH"/*/tmp
  967. [ -d "$APPMAN_APPSPATH" ] && rm -Rf "$APPMAN_APPSPATH"/*/tmp
  968. }
  969. _update_launchers_not_found_msg() {
  970. MISSING_LAUNCHERS_MSG=" No launcher found."
  971. printf "%b\n%b\n%b\n" "$DIVIDING_LINE" "$MISSING_LAUNCHERS_MSG" "$DIVIDING_LINE"
  972. }
  973. _update_launchers() {
  974. _clean_launchers 2>/dev/null 1>/dev/null
  975. MISSING_LAUNCHERS_MSG="No launcher found, use option \"--launcher\" to create them."
  976. [ ! -d "$DATADIR"/applications/AppImages ] && _update_launchers_not_found_msg && exit 0
  977. [ -d "$DATADIR"/applications/AppImages ] && [ -z "$( ls -A "$DATADIR"/applications/AppImages )" ] && _update_launchers_not_found_msg && exit 0
  978. if ! command -v appimageupdatetool 1>/dev/null; then
  979. update_launchers_error_message=" 💀 ERROR! Missing command \"${RED}appimageupdatetool\033[0m\", install it and retry!"
  980. printf "%b\n%b\n%b\n" "$DIVIDING_LINE" "$update_launchers_error_message" "$DIVIDING_LINE"
  981. else
  982. echo " ◆ Update local AppImages integrated manually"
  983. for var in "$DATADIR"/applications/AppImages/*.desktop; do
  984. appimage_full_path=$(awk -F'=| ' '/Exec=/{print $2; exit}' "$var" | sed 's/"//g; s/\s.*$//')
  985. appimagename=$(basename -- "$appimage_full_path")
  986. appimage_path=$(echo "$appimage_full_path" | sed -E 's|/[^/]+$|/|; s/\/*$//g')
  987. printf "%b\n File: %b%b\033[0m\n Path: %b" "$DIVIDING_LINE" "${Green}" "$appimagename" "$appimage_path"
  988. if [ ! -f "$appimage_full_path" ]; then
  989. echo "(unmounted)" | _fit
  990. else
  991. printf "\n\n"
  992. appimageupdatetool -Or "$appimage_full_path"
  993. fi
  994. done
  995. fi
  996. }
  997. _use_update() {
  998. _online_check
  999. _update_github_api_key_in_the_updater_files
  1000. _clean_all_tmp_directories_from_appspath >/dev/null
  1001. ENTRIES="$(echo "$@" | cut -f2- -d ' ' | tr ' ' '\n' | grep -v -- "^-\|^$1$")"
  1002. FLAGS=$(echo "$@" | tr ' ' '\n' | grep -- "--" | tr '\n ' ' ')
  1003. if echo "$FLAGS" | grep -q -- "--debug"; then
  1004. debug_update="1"
  1005. fi
  1006. if [ -z "$ENTRIES" ]; then
  1007. _clean_amcachedir
  1008. _update_list_updatable_apps
  1009. printf "%b\n >> START OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE" "$DIVIDING_LINE"
  1010. if echo "$FLAGS" | grep -q -- "--apps"; then
  1011. _update_updatable_apps_msg_head
  1012. _update_all_apps
  1013. elif echo "$FLAGS" | grep -q -- "--launcher"; then
  1014. _update_launchers
  1015. else
  1016. _update_updatable_apps_msg_head
  1017. _update_all_apps
  1018. _use_sync
  1019. printf " >> END OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE"
  1020. sleep 0.2
  1021. exit 0
  1022. fi
  1023. printf "%b\n >> END OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE" "$DIVIDING_LINE"
  1024. sleep 0.2
  1025. exit 0
  1026. else
  1027. [ -n "$debug_update" ] && echo "$DIVIDING_LINE"
  1028. _determine_args
  1029. for arg in $ENTRIES; do
  1030. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  1031. if [ -f "$argpath"/AM-updater ]; then
  1032. cd "$argpath" 2>/dev/null || exit 1
  1033. _update_app
  1034. elif [ ! -d "$argpath" ]; then
  1035. echo " ✖ ERROR: \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\" does not exists!"
  1036. else
  1037. UPDATERS=$(cd "$argpath" 2>/dev/null && find . -name "*update*" -print 2>/dev/null)
  1038. [ -n "$UPDATERS" ] && arg_autoupdatable=", it may have its update system"
  1039. echo " ✖ Cannot manage updates for \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\"$arg_autoupdatable"
  1040. fi
  1041. done
  1042. wait
  1043. rm -f "$AMDATADIR"/torsocks.conf
  1044. exit 0
  1045. fi
  1046. }
  1047. _use_force_latest() {
  1048. _online_check
  1049. _determine_args
  1050. ENTRIES="$(echo "$@" | cut -f2- -d ' ')"
  1051. for arg in $ENTRIES; do
  1052. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  1053. if [ ! -d "$argpath" ]; then
  1054. echo " ERROR: \"$arg\" is not installed, see \"-f\""
  1055. elif [ ! -f "$argpath"/AM-updater ]; then
  1056. echo " ERROR: \"$AMCLI\" cannot manage updates for \"$arg\""
  1057. elif ! grep -q "api.github.com" "$argpath"/AM-updater; then
  1058. echo " ERROR: \"$arg\" source is not on Github"
  1059. elif ! grep -q "/releases | " "$argpath"/AM-updater; then
  1060. echo " ERROR: \"$arg\" does not redirect to a generic \"releases\""
  1061. else
  1062. sed -i 's#/releases | #/releases/latest | #g' "$argpath"/AM-updater
  1063. APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
  1064. start=$(date +%s)
  1065. _update_run_updater
  1066. fi
  1067. done
  1068. }
  1069. ################################################################################################################################################################
  1070. # USAGE
  1071. ################################################################################################################################################################
  1072. # HANDLE ALL THE EXTERNAL MODULES
  1073. _use_module() {
  1074. # Test if module exists
  1075. if [ ! -f "$MODULES_PATH/$MODULE" ]; then
  1076. _online_check
  1077. if ! wget -q "$MODULES_SOURCE/$MODULE" -O "$MODULES_PATH/$MODULE"; then
  1078. echo " Module not found, run \"$AMCLI -s\" to update \"$AMCLIUPPER\""
  1079. exit 1
  1080. fi
  1081. chmod a+x "$MODULES_PATH/$MODULE"
  1082. fi
  1083. # Source module
  1084. source "$MODULES_PATH/$MODULE" "$@"
  1085. }
  1086. case "$1" in
  1087. '')
  1088. echo " USAGE: $AMCLI [OPTION]"
  1089. echo " $AMCLI [OPTION] [ARGUMENT]"
  1090. echo ""
  1091. echo " Run the \"$AMCLI -h\" command to find out more"
  1092. exit 0
  1093. ;;
  1094. 'about'|'-a'|\
  1095. 'files'|'-f'|'-fi'|\
  1096. 'list'|'-l'|\
  1097. 'query'|'-q')
  1098. MODULE="database.am"
  1099. if [ -t 1 ]; then _use_module "$@"; else _use_module "$@" | sed -e 's/\x1b\[[0-9;]*m//g'; fi
  1100. ;;
  1101. 'backup'|'-b'|\
  1102. 'downgrade'|'--rollback'|\
  1103. 'icons'|'--icons'|\
  1104. 'launcher'|'--launcher'|\
  1105. 'lock'|'unlock'|\
  1106. 'nolibfuse'|\
  1107. 'overwrite'|'-o'|\
  1108. 'remove'|'-R'|'-r')
  1109. MODULE="management.am"
  1110. _use_module "$@"
  1111. ;;
  1112. 'config'|'-C'|'--config'|\
  1113. 'home'|'-H'|'--home'|\
  1114. 'sandbox'|'--sandbox'|\
  1115. '--disable-sandbox')
  1116. MODULE="sandboxes.am"
  1117. _use_module "$@"
  1118. ;;
  1119. 'download'|'-d'|\
  1120. 'extra'|'-e'|\
  1121. 'install'|'-i'|'-ias'|\
  1122. 'install-appimage'|'-ia')
  1123. MODULE="install.am"
  1124. _online_check
  1125. [ "$CLI" = am ] && [ -f "$APPMANCONFIG"/appman-mode ] && printf "%b" "$APPMAN_MSG"
  1126. _use_module "$@"
  1127. ;;
  1128. 'template'|'-t')
  1129. MODULE="template.am"
  1130. _online_check
  1131. _use_module "$@"
  1132. ;;
  1133. # INBUILT OPTIONS
  1134. '--devmode-disable'|'--devmode-enable')
  1135. [ "$1" = "--devmode-disable" ] && rm -f "$AMDATADIR"/betatester \
  1136. || touch "$AMDATADIR"/betatester && _betatester_message_on
  1137. ;;
  1138. '--force-latest')
  1139. _use_force_latest "$@"
  1140. ;;
  1141. '--system')
  1142. [ -f "$APPMANCONFIG"/appman-mode ] && rm -f "$APPMANCONFIG"/appman-mode && printf "%b" "$APPMAN_MSG_OFF"
  1143. ;;
  1144. 'apikey')
  1145. _use_apikey "$@"
  1146. ;;
  1147. 'appman'|'--user')
  1148. _use_appman
  1149. ;;
  1150. 'clean'|'-c')
  1151. _use_clean
  1152. ;;
  1153. 'hide'|'unhide')
  1154. _determine_args
  1155. _use_hide_unhide "$@"
  1156. ;;
  1157. 'newrepo'|'neodb')
  1158. _use_newrepo "$@"
  1159. ;;
  1160. 'sync'|'-s')
  1161. _use_sync
  1162. ;;
  1163. 'update'|'-u'|'-U')
  1164. _use_update "$@"
  1165. ;;
  1166. 'version'|'-v'|'--version')
  1167. echo "$AMVERSION"
  1168. ;;
  1169. '--disable-notifications')
  1170. _determine_args
  1171. for n in $ARGPATHS; do sed -e '/notify-send/ s/^#*/#/' -i "$n/AM-updater" 2>/dev/null; done
  1172. ;;
  1173. '--enable-notifications')
  1174. _determine_args
  1175. for n in $ARGPATHS; do sed -e '/notify-send/ s/^#*//' -i "$n/AM-updater" 2>/dev/null; done
  1176. ;;
  1177. 'help'|'-h')
  1178. ################################################################################################################################################################
  1179. # HELP
  1180. ################################################################################################################################################################
  1181. _use_help() {
  1182. [ "$CLI" = am ] && [ -f "$APPMANCONFIG"/appman-mode ] && printf "%b" "$APPMAN_MSG"
  1183. echo -e "
  1184. NAME: ${Green}$AMCLIUPPER\033[0m VERSION: ${Green}$AMVERSION\033[0m
  1185. SYNOPSIS: ${LightBlue}$AMCLI {OPTION}\033[0m
  1186. ${LightBlue}$AMCLI {OPTION} {PROGRAM}\033[0m
  1187. DESCRIPTION: A command line utility to install and manage AppImages and other portable programs for GNU/Linux thanks to its AUR-inspired database.
  1188. OPTIONS:
  1189. ${Gold}about, -a\033[0m
  1190. ${LightBlue}$AMCLI -a {PROGRAM}\033[0m
  1191. Description: Shows more info about one or more apps.
  1192. ${Gold}apikey\033[0m
  1193. ${LightBlue}$AMCLI apikey {Github Token}
  1194. ${LightBlue}$AMCLI apikey delete\033[0m
  1195. Description: Accede to github APIs using your personal access tokens. The file named \"ghapikey.txt\" will be saved in $AMDATADIR. Use \"del\" to remove it.
  1196. ${Gold}backup, -b\033[0m
  1197. ${LightBlue}$AMCLI -b {PROGRAM}\033[0m
  1198. Description: Create a snapshot of the current version of an installed program.
  1199. ${Gold}clean, -c\033[0m
  1200. ${LightBlue}$AMCLI -c\033[0m
  1201. Description: Removes all the unnecessary files and folders.
  1202. ${Gold}config, -C, --config\033[0m
  1203. ${LightBlue}$AMCLI -C {PROGRAM}\033[0m
  1204. Description: Set a dedicated \$XDD_CONFIG_HOME for one or more AppImages.
  1205. ${Gold}downgrade, --rollback\033[0m
  1206. ${LightBlue}$AMCLI --rollback {PROGRAM}\033[0m
  1207. Description: Download an older or specific app version.
  1208. ${Gold}download, -d\033[0m
  1209. ${LightBlue}$AMCLI -d {PROGRAM}
  1210. ${LightBlue}$AMCLI -d --convert {PROGRAM}\033[0m
  1211. Description: Download one or more installation scripts to your desktop or convert them to local installers for \"AppMan\". To test the scripts, use the \"${LightBlue}$AMCLI -i '/path/to/script'\033[0m\" command or enter the directory of the script and run the \"${LightBlue}$AMCLI -i ./script\033[0m\" command, even using dedicated flags, if necessary (see \"-i\").
  1212. ${Gold}extra, -e\033[0m
  1213. ${LightBlue}$AMCLI -e user/project {APPNAME}
  1214. ${LightBlue}$AMCLI -e user/project {APPNAME} {KEYWORD}\033[0m
  1215. Description: Install AppImages from github.com, outside the database. This allows you to install, update and manage them all like the others. Where \"user/project\" can be the whole URL to the github repository, give a name to the program so that it can be used from the command line. Optionally, add an \"univoque\" keyword if multiple AppImages are listed.
  1216. ${Gold}files, -f, -fi\033[0m
  1217. ${LightBlue}$AMCLI -f
  1218. ${LightBlue}$AMCLI -f --byname
  1219. ${LightBlue}$AMCLI -f --less\033[0m
  1220. Description: Shows the list of all installed programs, with sizes. By default apps are sorted by size, use \"--byname\" to sort by name. With the option \"--less\" it shows only the number of installed apps. Option \"-fi\" only shows installed apps, not the AppImages integrated with the \"--launcher\" option.
  1221. ${Gold}help, -h\033[0m
  1222. ${LightBlue}$AMCLI -h\033[0m
  1223. Description: Prints this message.
  1224. ${Gold}hide\033[0m
  1225. ${LightBlue}$AMCLI hide {PROGRAM}\033[0m
  1226. Description: Prevents an installed application from being shown or managed by \"$AMCLI\".
  1227. ${Gold}home, -H, --home\033[0m
  1228. ${LightBlue}$AMCLI -H {PROGRAM}\033[0m
  1229. Description: Set a dedicated \$HOME directory for one or more AppImages.
  1230. ${Gold}icons, --icons\033[0m
  1231. ${LightBlue}$AMCLI --icons {PROGRAM}
  1232. ${LightBlue}$AMCLI --icons --all\033[0m
  1233. Description: Allow installed apps to use system icon themes. You can specify the name of the apps to change or use the \"--all\" flag to change all of them at once. This will remove the icon path from the .desktop file and add the symbolic link of all available icons in the $DATADIR/icons/hicolor/scalable/apps directory. The \"--icons\" option can be used as \"flag\" in the \"-i\" and \"-ia\" options.
  1234. ${Gold}install, -i\033[0m
  1235. ${LightBlue}$AMCLI -i {PROGRAM}
  1236. ${LightBlue}$AMCLI -i --debug {PROGRAM}
  1237. ${LightBlue}$AMCLI -i --force-latest {PROGRAM}
  1238. ${LightBlue}$AMCLI -i --icons {PROGRAM}
  1239. ${LightBlue}$AMCLI -i --sandbox {PROGRAM}\033[0m
  1240. Description: Install one or more programs or libraries from the list. With the \"--debug\" option you can see log messages to debug the script. For more details on \"--force-latest\", see the dedicated option, below. Use the \"--icons\" flag to allow the program to use icon themes. It can also be extended with additional flags (see third-party flags, at the bottom of this message). The \"--sandbox\" flag allows you to set sandboxes for AppImage packages.
  1241. ${Gold}install-appimage, -ia, -ias\033[0m
  1242. ${LightBlue}$AMCLI -ia {PROGRAM}
  1243. ${LightBlue}$AMCLI -ia --debug {PROGRAM}
  1244. ${LightBlue}$AMCLI -ia --force-latest {PROGRAM}
  1245. ${LightBlue}$AMCLI -ia --icons {PROGRAM}
  1246. ${LightBlue}$AMCLI -ia --sandbox {PROGRAM}
  1247. ${LightBlue}$AMCLI -ias {PROGRAM}\033[0m
  1248. Description: Same as \"install\" (see above) but for AppImages only. Option \"-ias\" (aka Install AppImage & Sandbox) is equivalent to \"-ia --sandbox\", to set sandboxes for AppImage packages.
  1249. ${Gold}lock\033[0m
  1250. ${LightBlue}$AMCLI lock {PROGRAM}\033[0m
  1251. Description: Prevent an application being updated, if it has an\"AM-updater\" script.
  1252. ${Gold}list, -l\033[0m
  1253. ${LightBlue}$AMCLI -l
  1254. ${LightBlue}$AMCLI -l --all
  1255. ${LightBlue}$AMCLI -l --appimages\033[0m
  1256. Description: Shows the list of all the apps available, or just the AppImages. It can also be extended with additional flags, the \"--all\" flag allows you to consult the set of all supported databases (see third-party flags, at the bottom of this message).
  1257. ${Gold}newrepo, neodb\033[0m
  1258. ${LightBlue}$AMCLI newrepo add {URL}\\{PATH}
  1259. ${LightBlue}$AMCLI newrepo select
  1260. ${LightBlue}$AMCLI newrepo on\\off
  1261. ${LightBlue}$AMCLI newrepo purge
  1262. ${LightBlue}$AMCLI newrepo info\033[0m
  1263. Description: Set a new default repo, use \"add\" to append the path to a local directory or an online URL, then use \"select\" to use it by default, a message will warn you about the usage of this repo instead of the default one. Use \"on\"/\"off\" to enable/disable it. Use \"purge\" to remove all 3rd party repos. Use \"info\" to see the source from where installation scripts and lists are taken.
  1264. ${Gold}nolibfuse\033[0m
  1265. ${LightBlue}$AMCLI nolibfuse {PROGRAM}\033[0m
  1266. Description: Convert old AppImages and get rid of \"libfuse2\" dependence.
  1267. ${Gold}overwrite, -o\033[0m
  1268. ${LightBlue}$AMCLI -o {PROGRAM}\033[0m
  1269. Description: Overwrite apps with snapshots saved previously (see \"-b\").
  1270. ${Gold}query, -q\033[0m
  1271. ${LightBlue}$AMCLI -q {KEYWORD}
  1272. ${LightBlue}$AMCLI -q --all {KEYWORD}
  1273. ${LightBlue}$AMCLI -q --appimages {KEYWORD}
  1274. ${LightBlue}$AMCLI -q --pkg {PROGRAM1} {PROGRAM2}\033[0m
  1275. Description: Search for keywords in the list of available applications, add the \"--appimages\" option to list only the AppImages or add \"--pkg\" to list multiple programs at once. The \"--all\" flag allows you to consult the set of all supported databases.
  1276. ${Gold}remove, -r\033[0m
  1277. ${LightBlue}$AMCLI -r {PROGRAM}\033[0m
  1278. Description: Removes one or more apps, requires confirmation.
  1279. ${Gold}-R\033[0m
  1280. ${LightBlue}$AMCLI -R {PROGRAM}\033[0m
  1281. Description: Removes one or more apps without asking.
  1282. ${Gold}sandbox, --sandbox\033[0m
  1283. ${LightBlue}$AMCLI sandbox {PROGRAM}\033[0m
  1284. Description: Run an AppImage in a sandbox using Aisap.
  1285. NOTE, \"--sandbox\" can be used as a flag in \"-i\" and \"-ia\" or can be replaced using the option \"-ias\" (aka Install AppImage & Sandbox).
  1286. ${Gold}sync, -s\033[0m
  1287. ${LightBlue}$AMCLI -s\033[0m
  1288. Description: Updates this script to the latest version hosted.
  1289. ${Gold}template, -t\033[0m
  1290. ${LightBlue}$AMCLI -t {PROGRAM}\033[0m
  1291. Description: Generate a custom installation script. To test the scripts, use the \"${LightBlue}$AMCLI -i '/path/to/script'\033[0m\" command or enter the directory of the script and run the \"${LightBlue}$AMCLI -i ./script\033[0m\" command, even using dedicated flags, if necessary (see \"-i\").
  1292. ${Gold}unhide\033[0m
  1293. ${LightBlue}$AMCLI unhide {PROGRAM}\033[0m
  1294. Description: Allow a hidden app to be shown and managed again (nulls \"hide\").
  1295. ${Gold}unlock\033[0m
  1296. ${LightBlue}$AMCLI unlock {PROGRAM}\033[0m
  1297. Description: Unlock updates for the selected program (nulls \"lock\").
  1298. ${Gold}update, -u, -U\033[0m
  1299. ${LightBlue}$AMCLI -u
  1300. ${LightBlue}$AMCLI -u --apps
  1301. ${LightBlue}$AMCLI -u --debug
  1302. ${LightBlue}$AMCLI -u --apps --debug
  1303. ${LightBlue}$AMCLI -u {PROGRAM}\033[0m
  1304. ${LightBlue}$AMCLI -u --debug {PROGRAM}
  1305. ${LightBlue}$AMCLI -u --launcher\033[0m
  1306. Description: Update everything. Add \"--apps\" to update only the apps or write only the apps you want to update by adding their names. Add the \"--debug\" flag to view the output of AM-updater scripts. Add the \"--launcher\" flag to try to update only local AppImages integrated with the \"--launcher\" option (see \"--launcher\").
  1307. ${Gold}version, -v\033[0m
  1308. ${LightBlue}$AMCLI -v\033[0m
  1309. Description: Shows the version.
  1310. ${Gold}--devmode-disable\033[0m
  1311. ${LightBlue}$AMCLI --devmode-disable\033[0m
  1312. Description: Undo \"--devmode-enable\" (see below).
  1313. ${Gold}--devmode-enable\033[0m
  1314. ${LightBlue}$AMCLI --devmode-enable\033[0m
  1315. Description: Use the development branch (at your own risk).
  1316. ${Gold}--disable-notifications\033[0m
  1317. ${LightBlue}$AMCLI --disable-notifications\033[0m
  1318. Description: Disable notifications during apps update.
  1319. ${Gold}--disable-sandbox\033[0m
  1320. ${LightBlue}$AMCLI --disable-sandbox {PROGRAM}\033[0m
  1321. Description: Disable the sandbox for the selected app.
  1322. ${Gold}--enable-notifications\033[0m
  1323. ${LightBlue}$AMCLI --enable-notifications\033[0m
  1324. Description: Enable notifications during apps update (nulls \"--disable-notifications\").
  1325. ${Gold}--force-latest\033[0m
  1326. ${LightBlue}$AMCLI --force-latest {PROGRAM}\033[0m
  1327. Description: Downgrades an installed app from pre-release to \"latest\".
  1328. ${Gold}--launcher\033[0m
  1329. ${LightBlue}$AMCLI --launcher /path/to/\${APPIMAGE}\033[0m
  1330. Description: Drag/drop one or more AppImages in the terminal and embed them in the apps menu and customize a command to use from the CLI.
  1331. NOTE that \"--launcher\" can be used as a flag in \"-u\" to try to update the integrated AppImages (see \"-u\"). This works only if \"appimageupdatetool\" is installed and delta updates are supported. This flag does not work miracles, I strongly suggest to use options \"-ia\" and \"-e\" instead.
  1332. ${Gold}--system\033[0m
  1333. ${LightBlue}am --system\033[0m
  1334. ${Gold}--user\033[0m
  1335. ${LightBlue}am --user\033[0m
  1336. Description: Made \"AM\" run in \"AppMan Mode\", locally, useful for unprivileged users. This option only works with \"AM\".
  1337. The \"--user\" option can also be used just as a flag for installation options. For example:
  1338. - Use it to install applications locally, option \"-i\" or \"install\":
  1339. ${LightBlue}am -i --user {PROGRAM}\033[0m
  1340. - Also suboptions of \"-i\" can work with this flag:
  1341. ${LightBlue}am -i --user --debug {PROGRAM}\033[0m
  1342. ${LightBlue}am -i --user --force-latest {PROGRAM}
  1343. ${LightBlue}am -i --user --icons {PROGRAM}
  1344. ${LightBlue}am -i --user --debug --force-latest {PROGRAM}
  1345. ${LightBlue}am -i --user --debug --force-latest --icons {PROGRAM}\033[0m
  1346. - Same for AppImages only, option \"-ia\" or \"install-appimage\":
  1347. ${LightBlue}am -ia --user {PROGRAM}\033[0m
  1348. ${LightBlue}am -ia --user --debug {PROGRAM}
  1349. ${LightBlue}am -ia --user --force-latest {PROGRAM}
  1350. ${LightBlue}am -ia --user --icons {PROGRAM}
  1351. ${LightBlue}am -ia --user --debug --force-latest {PROGRAM}\033[0m
  1352. ${LightBlue}am -ia --user --debug --force-latest --icons {PROGRAM}\033[0m
  1353. - External AppImages can be installed like this as well, option \"-e\" or \"extra\":
  1354. ${LightBlue}am -e --user user/project {APPNAME}\033[0m
  1355. ${LightBlue}am -e --user user/project {APPNAME} {KEYWORD}\033[0m
  1356. NOTE, \"AM\" 9 or higher is also able to, update and manage apps locally, by default, and without having to switch to \"AppMan Mode\".
  1357. Description: Switch \"AM\" back to \"AM\" from \"AppMan Mode\" (see \"--user\").
  1358. $DIVIDING_LINE
  1359. THIRD-PARTY FLAGS: $third_party_flags_message
  1360. $DIVIDING_LINE
  1361. SITES:
  1362. https://github.com/ivan-hc/AM
  1363. https://portable-linux-apps.github.io
  1364. \n" | sed 's/^ //g' | _fit | less -Ir
  1365. }
  1366. if [ -t 1 ]; then _use_help; else _use_help | sed -e 's/\x1b\[[0-9;]*m//g'; fi
  1367. ;;
  1368. *)
  1369. exec "$AMCLIPATH"
  1370. ;;
  1371. esac
  1372. # vim:tabstop=4:shiftwidth=4:expandtab