APP-MANAGER 57 KB

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