APP-MANAGER 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. #!/usr/bin/env bash
  2. AMVERSION="9.5-2"
  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. 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. # TOOLPACKS/SOARPKGS
  383. export toolpack_repo="https://github.com/pkgforge/soarpkgs (ex toolpacks)"
  384. export toolpack_readme="https://raw.githubusercontent.com/ivan-hc/am-extras/main/soarpkgs-toolpacks/${ARCH}.md"
  385. [ -n "$toolpack_readme" ] && third_party_flags="$third_party_flags --toolpack"
  386. 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"
  387. #################################
  388. # ALL THE ABOVE
  389. #################################
  390. third_party_lists=$(echo "$third_party_flags" | tr '-' '\n' | sed 's/ //g' | xargs)
  391. _remove_known_third_party_extensions() {
  392. sed "s/$(echo "$third_party_lists" | sed 's/ /\\|/g')$//g; s/\.$//g"
  393. }
  394. _files_db_third_party() {
  395. for tp_list in $third_party_lists; do
  396. if test -f "$APPSPATH"/"$arg"/.am-installer/*."$tp_list"; then
  397. export DB="$tp_list"
  398. fi
  399. done
  400. }
  401. _third_party_lsts_filter() {
  402. grep -v -- "---\|^| appname" | grep "^| .* | .* | http.* | http.* | .* |$" 2>/dev/null | awk -F'|' '{print $2, $3}' | sed 's/^/◆/g; s/ / : /g; s/ $//g'
  403. }
  404. _sync_third_party_lists() {
  405. for tp_list in $third_party_lists; do
  406. rm -f "$AMDATADIR"/"$ARCH"-"$tp_list"
  407. tprepo_readme="${tp_list}_readme"
  408. if [ -n "${!tprepo_readme}" ]; then
  409. curl -Ls "${!tprepo_readme}" | _third_party_lsts_filter \
  410. | sed "s/$/. To install it use the --$tp_list flag or the .$tp_list extension./g" | sort > "$AMDATADIR"/"$ARCH"-"$tp_list" \
  411. || touch "$AMDATADIR"/"$ARCH"-"$tp_list"
  412. fi
  413. done
  414. }
  415. _completion_list_third_party() {
  416. for tp_list in $third_party_lists; do
  417. [ -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
  418. done
  419. }
  420. export awk_name="1" awk_description="2" awk_site="3" awk_dl="4" awk_ver="5" # Numbers to use in "awk" to determine columns
  421. third_party_flags_message=""
  422. if [ -n "$third_party_flags" ]; then
  423. for flag in $third_party_flags; do
  424. tpflag_name=$(echo "$flag" | tr '-' '\n ' | grep .)
  425. tprepo_name="${tpflag_name}_repo"
  426. third_party_flags_message="$third_party_flags_message\n
  427. ${Gold}--$tpflag_name\033[0m
  428. ${LightBlue}$AMCLI -i --$tpflag_name {PROGRAM}\033[0m
  429. ${LightBlue}am -i --$tpflag_name --user {PROGRAM}\033[0m
  430. ${LightBlue}$AMCLI -l --$tpflag_name\033[0m
  431. 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.
  432. "
  433. done
  434. fi
  435. [ -z "$third_party_flags_message" ] && third_party_flags_message="none\n"
  436. ################################################################################################################################################################
  437. # UTILITIES
  438. ################################################################################################################################################################
  439. # COMPLETION LIST
  440. available_options="about add apikey backup clean config disable downgrade download enable extra files hide home icons info \
  441. install install-appimage launcher list lock neodb newrepo nolibfuse off on overwrite purge query remove sandbox \
  442. select sync template test unhide unlock update --all --appimages --apps --byname --config --convert --debug \
  443. --devmode-disable --devmode-enable --disable-notifications --enable-notifications --force-latest --home --icons \
  444. -ias --launcher --less --pkg --rollback --disable-sandbox --sandbox --system --user $third_party_flags"
  445. _completion_lists() {
  446. # Remove existing lists and download new ones
  447. curl -Ls "$APPSLISTDB" > "$AMDATADIR/$ARCH-apps"
  448. awk -v FS="(◆ | : )" '{print $2}' <"$AMDATADIR"/"$ARCH"-apps > "$AMDATADIR"/list
  449. _completion_list_third_party
  450. # Append options to the list
  451. for o in $available_options; do
  452. echo "$o" >> "$AMDATADIR"/list
  453. done
  454. # Detecl valid lists
  455. valid_lists="apps$\|appimages$"
  456. for tp_list in $third_party_lists; do
  457. valid_lists="$valid_lists\|$tp_list$"
  458. done
  459. for l in "$AMDATADIR"/"$ARCH"-*; do
  460. ! echo "$l" | grep -q "$valid_lists" && rm -f "$l"
  461. done
  462. }
  463. # BASH, FISH AND ZSH COMPLETION
  464. completion_file="$DATADIR/bash-completion/completions/$AMCLI"
  465. mkdir -p "$DATADIR/bash-completion/completions" || exit 1
  466. if ! grep -o " $AMCLI$" "$completion_file" >/dev/null 2>&1; then
  467. echo "complete -W \"\$(cat $AMDATADIR/list 2>/dev/null)\" $AMCLI" >> "$completion_file"
  468. if [ -f "${ZDOTDIR:-$HOME}"/.zshrc ] && echo "$SHELL" | grep -q "zsh"; then
  469. cat <<-HEREDOC >> "${ZDOTDIR:-$HOME}"/.zshrc
  470. autoload bashcompinit
  471. bashcompinit
  472. source "$completion_file"
  473. HEREDOC
  474. fi
  475. echo "Shell completion has been enabled!"
  476. fi
  477. if [ -d "$DATADIR"/fish/completions ] || [ -d /etc/fish/completions ] || [ -d /usr/share/fish/completions ]; then
  478. 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
  479. fi
  480. # VERSION OF THE INSTALLED APPS
  481. # Filters
  482. _check_version_filters() {
  483. sed -E "s/$ARCH|amd64|x86-64|x64|basic|standard|full|help|Qt[0-9]//g; s/-/\n/g; s/_/\n/g;" |\
  484. grep -vi "appimage\|$arg\|?\|tar." | grep "[0-9]" | head -1 | sed 's/^v//g; s/^\.//g; s/\.$//g;'
  485. }
  486. _check_version_grep_numbers() {
  487. grep -Eo "([0-9]{1,}\.)+[0-9]{1,}" | head -1
  488. }
  489. # Versions
  490. _check_version_if_any_version_reference_is_somewhere() {
  491. txt_files=$(file "$argpath"/* | awk -F: '/ASCII text/ {print $1}')
  492. for txtf in $txt_files; do
  493. if [ -f "$argpath"/tbb_version.json ] && grep -qi "\"version\":" "$argpath"/tbb_version.json; then
  494. APPVERSION=$(sort "$argpath"/tbb_version.json | tr '"' '\n' | grep "^[0-9]" | head -1)
  495. elif grep -qi "^version=" "$txtf" && grep -qi "^name=" "$txtf"; then
  496. APPVERSION=$(grep -i "^version=" "$txtf" | cut -c 9- | tr -cd '[:alnum:]._-')
  497. fi
  498. done
  499. }
  500. _check_version_if_version_file_exists() {
  501. APPVERSION=$(sort "$argpath"/version | head -1 | sed 's:.*/::' | _check_version_filters)
  502. if [ -z "$APPVERSION" ]; then
  503. if grep -q "download$" "$argpath"/version; then
  504. APPVERSION=$(sort "$argpath"/version | tr '/' '\n' | _check_version_filters)
  505. elif grep -q "://" "$argpath"/version; then
  506. APPVERSION=$(sort "$argpath"/version | tr '/' '\n' | _check_version_grep_numbers)
  507. elif grep -q "/v[0-9]*" "$argpath"/version; then
  508. APPVERSION=$(sort "$argpath"/version | tr '/' '\n' | grep "^v[0-9]" | head -1 | sed 's/^v//g')
  509. elif [ "$(sort "$argpath"/version | wc -w | sed 's/ //g')" = 1 ]; then
  510. APPVERSION=$(sort "$argpath"/version | head -1)
  511. fi
  512. fi
  513. if [ -z "$APPVERSION" ]; then
  514. if grep -q "http.*download/.*[0-9].*/" "$argpath"/version; then
  515. APPVERSION=$(sort "$argpath"/version | tr '/-' '\n' | grep "[0-9]" | _check_version_filters | tail -1)
  516. fi
  517. fi
  518. }
  519. _check_version_if_library() {
  520. LIBNAME=$(sort "$argpath"/remove | tr ' ' '\n' | grep "usr/local/lib" | head -1 | sed 's:.*/::')
  521. APPVERSION=$(find /usr/local/lib -type f -name "$LIBNAME" -type f | sed 's:.*.so.::' | tail -1)
  522. }
  523. _check_version_if_binary_in_place() {
  524. APPVERSION=$(date -r "$argpath"/"$arg" "+%Y.%m.%d")
  525. }
  526. _check_version() {
  527. rm -f "$AMCACHEDIR"/version-args
  528. _determine_args
  529. for arg in $ARGS; do
  530. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  531. if [ -f "$argpath"/remove ]; then
  532. if [ -f "$argpath"/version ]; then
  533. _check_version_if_version_file_exists
  534. elif [ "$arg" = "$AMCLI" ]; then
  535. APPVERSION="$AMVERSION"
  536. elif echo "$arg" | grep -q "ffwa-"; then
  537. APPVERSION="WebApp"
  538. elif grep -q "usr/local/lib" "$argpath"/remove 2>/dev/null; then
  539. _check_version_if_library
  540. elif [ -f "$argpath"/updater ] || grep -qi "version=" "$argpath"/*; then
  541. _check_version_if_any_version_reference_is_somewhere
  542. else
  543. APPVERSION="unknown"
  544. fi
  545. if [ -z "$APPVERSION" ]; then
  546. [ -f "$argpath"/"$arg" ] && _check_version_if_binary_in_place || APPVERSION="unknown"
  547. fi
  548. echo " ◆ $arg | $APPVERSION" >> "$AMCACHEDIR"/version-args
  549. fi
  550. done
  551. }
  552. _check_version_for_auto_updatable_apps() {
  553. _determine_args
  554. for arg in $ARGS; do
  555. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  556. if [ -f "$argpath"/updater ]; then
  557. _check_version_if_any_version_reference_is_somewhere
  558. if [ "$AMCLI" = am ] && [ -d "$CACHEDIR"/am ] && grep -q " ◆ $arg |" "$CACHEDIR"/am/version-args; then
  559. OLDAPPVERSION=$(grep " ◆ $arg |" "$CACHEDIR"/am/version-args | awk 'END {print $NF}')
  560. sed -i "/ ◆ $arg |/s#$OLDAPPVERSION#$APPVERSION#" "$CACHEDIR"/am/*args*
  561. fi
  562. if [ -d "$CACHEDIR"/appman ] && grep -q " ◆ $arg |" "$CACHEDIR"/appman/version-args; then
  563. OLDAPPVERSION=$(grep " ◆ $arg |" "$CACHEDIR"/appman/version-args | awk 'END {print $NF}')
  564. sed -i "/ ◆ $arg |/s#$OLDAPPVERSION#$APPVERSION#" "$CACHEDIR"/appman/*args*
  565. fi
  566. fi
  567. done
  568. }
  569. if [ -f "$AMCACHEDIR"/version-args ]; then
  570. _check_version_for_auto_updatable_apps 2>/dev/null
  571. fi
  572. # This function removes all info and versions from the register
  573. _remove_info_files() {
  574. rm -f "$AMCACHEDIR"/files*
  575. rm -f "$AMCACHEDIR"/version-args
  576. }
  577. ################################################################################################################################################################
  578. # APIKEY
  579. ################################################################################################################################################################
  580. ghapikey_file="$AMDATADIR/ghapikey.txt"
  581. # Set header authorization if GitHub API key file exists
  582. [ -f "$ghapikey_file" ] && HeaderAuthWithGITPAT=" --header \"Authorization: token $(<"$ghapikey_file")\" "
  583. _use_apikey() {
  584. case $2 in
  585. 'del'|'delete'|'remove')
  586. [ -f "$ghapikey_file" ] || { echo " ✖ No file named $ghapikey_file has been found"; exit 1; }
  587. rm -f "$ghapikey_file" && echo " ✔ $ghapikey_file has been removed"
  588. exit 0
  589. esac
  590. if [[ "$2" =~ ^(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$ ]]; then
  591. test_apikey_output_with_wget=$(curl -Ls --header "Authorization: token $2" 'https://api.github.com/repos/ivan-hc/AM/releases' | head -1)
  592. [ -n "$test_apikey_output_with_wget" ] && echo "$2" > "$ghapikey_file" \
  593. && echo "Validation successful!" || echo "ERROR: This is not a valid key!"
  594. else
  595. echo "ERROR: Wrong expression, validation failed!"
  596. fi
  597. }
  598. _update_github_api_key_in_the_updater_files() {
  599. if [ -f "$ghapikey_file" ]; then
  600. ghapikey=$(<"$ghapikey_file")
  601. updater_files=("$APPSPATH"/*/AM-updater) # Assuming AM-updater is one level deeper
  602. for f in "${updater_files[@]}"; do
  603. if [ -f "$f" ] && grep -q "https://api.github.com" "$f"; then
  604. # Check if the file already contains a valid API key
  605. if ! grep -qE "(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})" "$f"; then
  606. # Insert HeaderAuthWithGITPAT before the GitHub API URL
  607. sed -i "s#https://api.github.com#$HeaderAuthWithGITPAT https://api.github.com#g" "$f"
  608. else
  609. # Replace existing API key with the one from ghapikey.txt
  610. 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"
  611. fi
  612. fi
  613. done
  614. fi
  615. }
  616. ################################################################################################################################################################
  617. # APPMAN MODE
  618. ################################################################################################################################################################
  619. 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"
  620. APPMAN_MSG_OFF="$DIVIDING_LINE\n \"AppMan Mode\" disabled! \n$DIVIDING_LINE\n"
  621. APPMAN_MSG_THINK="$DIVIDING_LINE\nNOTE: You can also choose to simply use \"--user\" as a flag to install apps locally \
  622. (options \"-i\", \"-ia\" and \"-e\") instead of going fully into \"AppMan Mode\". \"AM\" can handle local applications as well.\n$DIVIDING_LINE\n"
  623. _use_appman() {
  624. _online_check
  625. [ "$CLI" = appman ] && echo " This function only works for AM" && exit 0
  626. printf "%b" "$APPMAN_MSG_THINK" | _fit
  627. read -r -p " Do you wish to enter \"AppMan Mode\" (y,N)?" yn
  628. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  629. echo "$DIVIDING_LINE"
  630. else
  631. [ ! -f "$APPMANCONFIG"/appman-mode ] && mkdir -p "$APPMANCONFIG" && touch "$APPMANCONFIG"/appman-mode
  632. _appman && printf "%b" "$APPMAN_MSG"
  633. fi
  634. }
  635. if [ "$AMCLI" = am ]; then
  636. if [ -f "$APPMANCONFIG"/appman-mode ]; then
  637. [ ! -f "$APPMANCONFIG"/appman-config ] && printf "%b" "$APPMAN_MSG"
  638. _appman
  639. AMCLIPATH="$(realpath "$0")"
  640. elif [ ! -w "$AMPATH" ]; then
  641. read -r -p " \"AM\" is read-only, want to use it in \"AppMan Mode\" (Y,n)? " yn
  642. if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
  643. exit 0
  644. else
  645. echo "$DIVIDING_LINE"; echo "\"AppMan Mode\" enabled!"; echo "$DIVIDING_LINE"
  646. _use_appman 1>/dev/null
  647. fi
  648. fi
  649. fi
  650. ################################################################################################################################################################
  651. # CLEAN
  652. ################################################################################################################################################################
  653. _clean_amcachedir_message() {
  654. _clean_amcachedir
  655. [ "$AMCLI" = am ] && [ -d "$CACHEDIR"/am ] && echo " ✔ Clear the contents of $CACHEDIR/am"
  656. [ -d "$CACHEDIR"/appman ] && echo " ✔ Clear the contents of $CACHEDIR/appman"
  657. }
  658. _clean_all_home_cache_directories_of_appimages() {
  659. for arg in $ARGPATHS; do
  660. if test -d "$arg"/*.home/.cache; then
  661. rm -Rf "$arg"/*/*.home/.cache/* && echo " ✔ Clear the contents of $arg/*.home/.cache"
  662. fi
  663. done
  664. }
  665. _clean_all_tmp_directories_from_appspath() {
  666. _determine_args
  667. for arg in $ARGPATHS; do
  668. if [ -d "$arg"/tmp ]; then
  669. rm -Rf "$arg"/tmp && echo " ✔ Removed $arg/tmp"
  670. fi
  671. done
  672. }
  673. _clean_launchers() {
  674. if [ -d "$DATADIR"/applications/AppImages ]; then
  675. rm -f "$AMCACHEDIR"/mountpoints
  676. for var in "$DATADIR"/applications/AppImages/*.desktop; do
  677. # full path to appimage
  678. appimagename=$(awk -F'=| ' '/Exec=/{print $2; exit}' "$var" | sed 's/"//g; s/\s.*$//')
  679. # name of the appimage
  680. launcher2del=$(basename -- "$(echo "$appimagename" | tr '[:upper:]' '[:lower:]')")
  681. # removable mount point where the appimage may be stored
  682. mountpoint=$(echo "$appimagename" | cut -d'/' -f1-4)
  683. if [ ! -f "$appimagename" ]; then
  684. if echo "$appimagename" | grep -q "^/media/\|^/mnt/"; then
  685. mountpoint=$(echo "$appimagename" | cut -d'/' -f1-4)
  686. unmounted_point=$(echo "$mountpoint" | cut -d'/' -f1-2)
  687. elif echo "$appimagename" | grep -q "^/run/media/"; then
  688. mountpoint=$(echo "$appimagename" | cut -d'/' -f1-5)
  689. unmounted_point="/run/media"
  690. else
  691. mountpoint=""
  692. fi
  693. if [ -n "$mountpoint" ] && [ ! -d "$mountpoint" ]; then
  694. echo "$mountpoint" >> "$AMCACHEDIR"/mountpoints
  695. echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
  696. echo " related AppImage is located in an unmounted path of $unmounted_point"
  697. else
  698. rm -f "$var"
  699. [ -n "$BINDIR" ] && [ -n "$launcher2del" ] && rm -f "$BINDIR"/"$launcher2del"*
  700. fi
  701. fi
  702. done
  703. if [ -f "$AMCACHEDIR"/mountpoints ]; then
  704. mountpoints=$(sort "$AMCACHEDIR"/mountpoints)
  705. for m in $mountpoints; do
  706. [ ! -d "$m" ] && mountpoint_enabled=1
  707. done
  708. fi
  709. [ -z "$mountpoint_enabled" ] && [ -n "$BINDIR" ] && cd "$BINDIR" && find . -xtype l -delete
  710. rm -f "$AMCACHEDIR"/mountpoints
  711. echo ' ✔ Removed orphaned launchers produced with the "--launcher" option'
  712. rmdir "$DATADIR"/applications/AppImages
  713. else
  714. [ -n "$BINDIR" ] && cd "$BINDIR" && find . -xtype l -delete
  715. fi
  716. }
  717. _clean_old_modules() {
  718. MODULES=$(sort "$(realpath "$0")" | tr '"' '\n' | grep "[a-z]\.am$" | uniq)
  719. [ -z "$MODULES_PATH" ] && exit 1
  720. for m in "$MODULES_PATH"/*; do
  721. if [[ "${MODULES}" != *"$(basename -- "$m")"* ]];then
  722. rm -f "$m" 2>/dev/null
  723. echo " ✔ Removed obsolete module named \"$(basename -- "$m")\""
  724. fi
  725. done
  726. }
  727. _use_clean() {
  728. echo " Cleaning temporary files and folders..." && sleep 0.1
  729. i=100 && while [ "$i" -ge 0 ]; do
  730. printf " %03d\r" "$i" && sleep 0.0001 && i=$((i - 1))
  731. done
  732. _detect_appman_apps
  733. _determine_args
  734. _clean_amcachedir_message
  735. _clean_all_home_cache_directories_of_appimages
  736. _clean_all_tmp_directories_from_appspath
  737. _clean_launchers 2>/dev/null
  738. _clean_old_modules
  739. }
  740. ################################################################################################################################################################
  741. # HIDE/UNHIDE
  742. ################################################################################################################################################################
  743. _use_hide_unhide() {
  744. entries="$(echo "$@" | cut -f2- -d ' ')"
  745. if [ "$1" = hide ]; then
  746. for arg in $entries; do
  747. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  748. [ -f "$argpath/remove" ] && mv "$argpath/remove" "$argpath/remove.old" \
  749. && echo "✔ $argpath has been hidden" || echo "✖ Can't hide \"$arg\", app already hidden or non-existent"
  750. done
  751. else
  752. for arg in $entries; do
  753. [ "$AMCLI" = am ] && [ -f "/opt/$arg/remove.old" ] && mv "/opt/$arg/remove.old" "/opt/$arg/remove" \
  754. && echo "✔ /opt/$arg can be managed again"
  755. [ -n "$APPMAN_APPSPATH" ] && [ -f "$APPMAN_APPSPATH/$arg/remove.old" ] && mv "$APPMAN_APPSPATH/$arg/remove.old" "$APPMAN_APPSPATH/$arg/remove" \
  756. && echo "✔ $APPMAN_APPSPATH/$arg can be managed again"
  757. done
  758. _clean_amcachedir
  759. fi
  760. }
  761. ################################################################################################################################################################
  762. # SYNC
  763. ################################################################################################################################################################
  764. _sync_installation_scripts() {
  765. printf "%b\n Checking for changes of the installation scripts in the online database...\n" "$DIVIDING_LINE"
  766. _determine_args
  767. for arg in $ARGS; do
  768. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  769. if [ -f "$argpath"/AM-updater ]; then
  770. mkdir -p "$argpath"/.am-installer
  771. scriptname=$(ls "$argpath/.am-installer/" | head -1)
  772. if [ -n "$scriptname" ]; then
  773. CURRENT=$(cat "$argpath"/.am-installer/"$scriptname")
  774. SOURCE=$(curl -Ls "$APPSDB"/"$scriptname")
  775. if [ "$CURRENT" = "$SOURCE" ]; then
  776. echo -ne "\r" 2>/dev/null
  777. else
  778. printf " ◆ Changed https://github.com/ivan-hc/AM/blob/main/programs/%b/%b\n" "$ARCH" "$scriptname"
  779. fi
  780. else
  781. if curl --output /dev/null --silent --head --fail "$APPSDB"/"$arg" 1>/dev/null; then
  782. printf " ◆ No installation script for %b, downloading one...\n" "$arg"
  783. mkdir -p "$argpath"/.am-installer
  784. wget -q "$APPSDB/$arg" -O "$argpath"/.am-installer/"$arg"
  785. fi
  786. fi
  787. fi
  788. done
  789. }
  790. _sync_appimages_list() {
  791. APPIMAGES_LIST="${APPIMAGES_LIST:-$AMREPO/programs/$ARCH-appimages}"
  792. curl -Ls "$APPIMAGES_LIST" > "$AMDATADIR/$ARCH-appimages"
  793. }
  794. _sync_databases() {
  795. printf "%b\n Check and update offline lists of additional databases...\n" "$DIVIDING_LINE"
  796. _sync_appimages_list
  797. _sync_third_party_lists 2>/dev/null
  798. _completion_lists
  799. }
  800. _sync_modules() {
  801. printf "%b\n Check for updates in modules...\n" "$DIVIDING_LINE"
  802. MODULES=$(curl -Ls "$AMREPO/APP-MANAGER" | tr '"' '\n' | grep "[a-z]\.am$")
  803. for module_name in $MODULES; do
  804. cd "$MODULES_PATH" || return 1
  805. if ! test -f ./"$module_name"; then
  806. echo " ◆ Downloading $module_name (not previously installed)..."
  807. curl -Os "$MODULES_SOURCE/$module_name" 2>/dev/null
  808. chmod a+x ./"$MODULENAME"
  809. fi
  810. CURRENT=$(cat ./"$module_name" 2>/dev/null)
  811. SOURCE=$(curl -Ls "$MODULES_SOURCE/$module_name")
  812. if [ "$CURRENT" = "$SOURCE" ]; then
  813. echo -ne "\r" 2>/dev/null
  814. else
  815. echo " ◆ Updating $module_name..."
  816. curl -Ls "$MODULES_SOURCE/$module_name" > ./"$module_name" 2>/dev/null
  817. fi
  818. done
  819. _clean_old_modules
  820. }
  821. _sync_amcli() {
  822. echo "$DIVIDING_LINE"
  823. CURRENT_AM_VERSION="$AMVERSION"
  824. echo -ne "\n ◆ SYNCHRONIZING \"$AMCLIUPPER\" VERSION \"$CURRENT_AM_VERSION\"...\r" && sleep 0.25
  825. _clean_amcachedir 1>/dev/null
  826. cd "$AMCACHEDIR" || return 1
  827. curl -Ls "$AMREPO"/APP-MANAGER > ./APP-MANAGER && chmod a+x ./APP-MANAGER
  828. echo y | mv ./APP-MANAGER "$(realpath "$0")"
  829. NEW_AM_VERSION=$("$AMCLIPATH" -v)
  830. if [ ! "$CURRENT_AM_VERSION" = "$NEW_AM_VERSION" ]; then
  831. echo -ne " A new release of \"$AMCLIUPPER\" is available, please wait...\r"
  832. echo " ◆ \"$AMCLIUPPER\" IS NOW UPDATED TO THE BRAND NEW \"$NEW_AM_VERSION\" VERSION!"
  833. printf "\n Replacement of version \"%b\" currently in use, COMPLETED! \n" "$CURRENT_AM_VERSION"
  834. printf "\n See https://github.com/ivan-hc/AM/commits/main\n\n"
  835. else
  836. echo " ◆ \"$AMCLIUPPER\" IS ALREADY UPDATED, CURRENT VERSION \"$CURRENT_AM_VERSION\""
  837. printf "\n See https://github.com/ivan-hc/AM/commits/%b\n\n" "$AMBRANCH"
  838. fi
  839. }
  840. _use_sync() {
  841. _online_check
  842. _betatester_message_on
  843. _sync_installation_scripts
  844. _sync_databases
  845. if [ "$(realpath "$0")" != "/usr/bin/am" ] && [ "$AMSYNC" != 1 ]; then
  846. _sync_modules
  847. _sync_amcli
  848. fi
  849. echo "$DIVIDING_LINE"
  850. }
  851. ################################################################################################################################################################
  852. # UPDATE
  853. ################################################################################################################################################################
  854. _update_updatable_apps_msg_head() {
  855. printf " \"%b\" CAN MANAGE UPDATES FOR THE FOLLOWING PROGRAMS:\n%b\n\n" "$AMCLIUPPER" "$DIVIDING_LINE"
  856. [ -f "$AMCACHEDIR/updatable-args-list" ] && grep "◆" "$AMCACHEDIR/updatable-args-list" | sort || echo " None"
  857. printf "\n All self-updatable programs are excluded\n"
  858. echo "$DIVIDING_LINE"
  859. }
  860. _update_list_updatable_apps() {
  861. _determine_args
  862. _check_version
  863. for arg in $ARGS; do
  864. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  865. if [ -d "$argpath" ]; then
  866. if [ -f "$argpath/AM-updater" ]; then
  867. app_version=$(grep -w " ◆ $arg |" "$AMCACHEDIR/version-args" | sed 's:.*| ::')
  868. echo " ◆ $arg $app_version" >> "$AMCACHEDIR"/updatable-args-list
  869. fi
  870. fi
  871. done
  872. }
  873. _update_determine_apps_version_changes() {
  874. [ -z "$debug_update" ] && echo "$DIVIDING_LINE"
  875. if [ -f "$AMCACHEDIR"/updatable-args-list ]; then
  876. mv "$AMCACHEDIR"/updatable-args-list "$AMCACHEDIR"/updatable-args-list-old
  877. _update_list_updatable_apps
  878. OLDVER="$AMCACHEDIR/updatable-args-list-old"
  879. NEWVER="$AMCACHEDIR/updatable-args-list"
  880. if cmp --silent -- "$NEWVER" "$OLDVER"; then
  881. echo ' Nothing to do here!'
  882. else
  883. printf " The following apps have been updated:\n\n"
  884. diff "$OLDVER" "$NEWVER" | grep "^>" | sed 's/^> //g'
  885. echo ""
  886. fi
  887. else
  888. echo ' No apps to update here!'
  889. fi
  890. }
  891. _update_torsocks_handler() {
  892. torsocks_congif_file=$(find /etc -type f -name torsocks.conf 2>/dev/null)
  893. if [ -n "$torsocks_congif_file" ]; then
  894. if grep -q "^#AllowOutboundLocalhost 1" "$torsocks_congif_file" && command -v appimageupdatetool 1>/dev/null; then
  895. [ ! -f "$AMDATADIR"/torsocks.conf ] && cat "$torsocks_congif_file" > "$AMDATADIR"/torsocks.conf
  896. sed -i 's/^#AllowOutboundLocalhost 1/AllowOutboundLocalhost 1/g' "$AMDATADIR"/torsocks.conf
  897. [ -f "$AMDATADIR"/torsocks.conf ] && export TORSOCKS_CONF_FILE="$AMDATADIR"/torsocks.conf
  898. 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)
  899. if [ -z "$GH_API_ALLOWED" ]; then
  900. printf " ✖ %b update failed, please restart %btor.service\033[0m to fix! \n" "$APPNAME" "${Green}"
  901. exit 1
  902. fi
  903. fi
  904. fi
  905. }
  906. _update_run_updater() {
  907. if grep -q "api.github.com" "$argpath"/AM-updater; then
  908. 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)
  909. if [ -z "$GH_API_ALLOWED" ]; then
  910. if command -v torsocks 1>/dev/null; then
  911. _update_torsocks_handler
  912. if [ -z "$debug_update" ]; then
  913. torsocks "$argpath"/AM-updater >/dev/null 2>&1
  914. else
  915. torsocks "$argpath"/AM-updater
  916. fi
  917. else
  918. echo " ✖ $APPNAME cannot be updated, you have reached GitHub API limit. Install \"torsocks\" from your system package manager and retry!" \
  919. | fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
  920. fi
  921. else
  922. if [ -z "$debug_update" ]; then
  923. "$argpath"/AM-updater >/dev/null 2>&1
  924. else
  925. "$argpath"/AM-updater
  926. fi
  927. fi
  928. else
  929. if [ -z "$debug_update" ]; then
  930. "$argpath"/AM-updater >/dev/null 2>&1
  931. else
  932. "$argpath"/AM-updater
  933. fi
  934. fi
  935. end=$(date +%s)
  936. timelapsed=$((end - start))
  937. [ "$timelapsed" = 1 ] && echo " ◆ $APPNAME is updated, $timelapsed second elapsed!" || echo " ◆ $APPNAME is updated, $timelapsed seconds elapsed!"
  938. [ -n "$debug_update" ] && echo "$DIVIDING_LINE"
  939. }
  940. _update_app() {
  941. APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
  942. start=$(date +%s)
  943. if [ -w "$argpath"/AM-updater ]; then
  944. _update_run_updater &
  945. else
  946. echo " ✖ $APPNAME is read-only, cannot update it!"
  947. fi
  948. }
  949. _update_all_apps() {
  950. for arg in $ARGS; do
  951. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  952. cd "$argpath" || exit 1
  953. arg=$(printf '%s\n' "${PWD##*/}")
  954. if [ -f "$argpath"/AM-updater ]; then
  955. _update_app
  956. fi
  957. done
  958. wait
  959. rm -f "$AMDATADIR"/torsocks.conf
  960. _update_determine_apps_version_changes
  961. rm -Rf "$APPSPATH"/*/tmp
  962. [ -d "$APPMAN_APPSPATH" ] && rm -Rf "$APPMAN_APPSPATH"/*/tmp
  963. }
  964. _update_launchers_not_found_msg() {
  965. MISSING_LAUNCHERS_MSG=" No launcher found."
  966. printf "%b\n%b\n%b\n" "$DIVIDING_LINE" "$MISSING_LAUNCHERS_MSG" "$DIVIDING_LINE"
  967. }
  968. _update_launchers() {
  969. _clean_launchers 2>/dev/null 1>/dev/null
  970. MISSING_LAUNCHERS_MSG="No launcher found, use option \"--launcher\" to create them."
  971. [ ! -d "$DATADIR"/applications/AppImages ] && _update_launchers_not_found_msg && exit 0
  972. [ -d "$DATADIR"/applications/AppImages ] && [ -z "$( ls -A "$DATADIR"/applications/AppImages )" ] && _update_launchers_not_found_msg && exit 0
  973. if ! command -v appimageupdatetool 1>/dev/null; then
  974. update_launchers_error_message=" 💀 ERROR! Missing command \"${RED}appimageupdatetool\033[0m\", install it and retry!"
  975. printf "%b\n%b\n%b\n" "$DIVIDING_LINE" "$update_launchers_error_message" "$DIVIDING_LINE"
  976. else
  977. echo " ◆ Update local AppImages integrated manually"
  978. for var in "$DATADIR"/applications/AppImages/*.desktop; do
  979. appimage_full_path=$(awk -F'=| ' '/Exec=/{print $2; exit}' "$var" | sed 's/"//g; s/\s.*$//')
  980. appimagename=$(basename -- "$appimage_full_path")
  981. appimage_path=$(echo "$appimage_full_path" | sed -E 's|/[^/]+$|/|; s/\/*$//g')
  982. printf "%b\n File: %b%b\033[0m\n Path: %b" "$DIVIDING_LINE" "${Green}" "$appimagename" "$appimage_path"
  983. if [ ! -f "$appimage_full_path" ]; then
  984. echo "(unmounted)" | _fit
  985. else
  986. printf "\n\n"
  987. appimageupdatetool -Or "$appimage_full_path"
  988. fi
  989. done
  990. fi
  991. }
  992. _use_update() {
  993. _online_check
  994. _update_github_api_key_in_the_updater_files
  995. _clean_all_tmp_directories_from_appspath >/dev/null
  996. ENTRIES="$(echo "$@" | cut -f2- -d ' ' | tr ' ' '\n' | grep -v -- "^-\|^$1$")"
  997. FLAGS=$(echo "$@" | tr ' ' '\n' | grep -- "--" | tr '\n ' ' ')
  998. if echo "$FLAGS" | grep -q -- "--debug"; then
  999. debug_update="1"
  1000. fi
  1001. if [ -z "$ENTRIES" ]; then
  1002. _clean_amcachedir
  1003. _update_list_updatable_apps
  1004. printf "%b\n >> START OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE" "$DIVIDING_LINE"
  1005. if echo "$FLAGS" | grep -q -- "--apps"; then
  1006. _update_updatable_apps_msg_head
  1007. _update_all_apps
  1008. elif echo "$FLAGS" | grep -q -- "--launcher"; then
  1009. _update_launchers
  1010. else
  1011. _update_updatable_apps_msg_head
  1012. _update_all_apps
  1013. _use_sync
  1014. printf " >> END OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE"
  1015. sleep 0.2
  1016. exit 0
  1017. fi
  1018. printf "%b\n >> END OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE" "$DIVIDING_LINE"
  1019. sleep 0.2
  1020. exit 0
  1021. else
  1022. [ -n "$debug_update" ] && echo "$DIVIDING_LINE"
  1023. _determine_args
  1024. for arg in $ENTRIES; do
  1025. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  1026. if [ -f "$argpath"/AM-updater ]; then
  1027. cd "$argpath" 2>/dev/null || exit 1
  1028. _update_app
  1029. else
  1030. UPDATERS=$(cd "$argpath" 2>/dev/null && find . -name "*update*" -print 2>/dev/null)
  1031. [ -n "$UPDATERS" ] && arg_autoupdatable=", it may have its update system"
  1032. echo " ✖ Cannot manage updates for \"$(echo "$arg" | tr '[:lower:]' '[:upper:]')\"$arg_autoupdatable"
  1033. fi
  1034. done
  1035. wait
  1036. rm -f "$AMDATADIR"/torsocks.conf
  1037. exit 0
  1038. fi
  1039. }
  1040. _use_force_latest() {
  1041. _online_check
  1042. _determine_args
  1043. ENTRIES="$(echo "$@" | cut -f2- -d ' ')"
  1044. for arg in $ENTRIES; do
  1045. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  1046. if [ ! -d "$argpath" ]; then
  1047. echo " ERROR: \"$arg\" is not installed, see \"-f\""
  1048. elif [ ! -f "$argpath"/AM-updater ]; then
  1049. echo " ERROR: \"$AMCLI\" cannot manage updates for \"$arg\""
  1050. elif ! grep -q "api.github.com" "$argpath"/AM-updater; then
  1051. echo " ERROR: \"$arg\" source is not on Github"
  1052. elif ! grep -q "/releases | " "$argpath"/AM-updater; then
  1053. echo " ERROR: \"$arg\" does not redirect to a generic \"releases\""
  1054. else
  1055. sed -i 's#/releases | #/releases/latest | #g' "$argpath"/AM-updater
  1056. APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
  1057. start=$(date +%s)
  1058. _update_run_updater
  1059. fi
  1060. done
  1061. }
  1062. ################################################################################################################################################################
  1063. # USAGE
  1064. ################################################################################################################################################################
  1065. # HANDLE ALL THE EXTERNAL MODULES
  1066. _use_module() {
  1067. # Test if module exists
  1068. if [ ! -f "$MODULES_PATH/$MODULE" ]; then
  1069. _online_check
  1070. if ! wget -q "$MODULES_SOURCE/$MODULE" -O "$MODULES_PATH/$MODULE"; then
  1071. echo " Module not found, run \"$AMCLI -s\" to update \"$AMCLIUPPER\""
  1072. exit 1
  1073. fi
  1074. chmod a+x "$MODULES_PATH/$MODULE"
  1075. fi
  1076. # Source module
  1077. source "$MODULES_PATH/$MODULE" "$@"
  1078. }
  1079. case "$1" in
  1080. '')
  1081. echo " USAGE: $AMCLI [OPTION]"
  1082. echo " $AMCLI [OPTION] [ARGUMENT]"
  1083. echo ""
  1084. echo " Run the \"$AMCLI -h\" command to find out more"
  1085. exit 0
  1086. ;;
  1087. 'about'|'-a'|\
  1088. 'files'|'-f'|'-fi'|\
  1089. 'list'|'-l'|\
  1090. 'query'|'-q')
  1091. MODULE="database.am"
  1092. if [ -t 1 ]; then _use_module "$@"; else _use_module "$@" | sed -e 's/\x1b\[[0-9;]*m//g'; fi
  1093. ;;
  1094. 'backup'|'-b'|\
  1095. 'downgrade'|'--rollback'|\
  1096. 'icons'|'--icons'|\
  1097. 'launcher'|'--launcher'|\
  1098. 'lock'|'unlock'|\
  1099. 'nolibfuse'|\
  1100. 'overwrite'|'-o'|\
  1101. 'remove'|'-R'|'-r')
  1102. MODULE="management.am"
  1103. _use_module "$@"
  1104. ;;
  1105. 'config'|'-C'|'--config'|\
  1106. 'home'|'-H'|'--home'|\
  1107. 'sandbox'|'--sandbox'|\
  1108. '--disable-sandbox')
  1109. MODULE="sandboxes.am"
  1110. _use_module "$@"
  1111. ;;
  1112. 'download'|'-d'|\
  1113. 'extra'|'-e'|\
  1114. 'install'|'-i'|'-ias'|\
  1115. 'install-appimage'|'-ia')
  1116. MODULE="install.am"
  1117. _online_check
  1118. [ "$CLI" = am ] && [ -f "$APPMANCONFIG"/appman-mode ] && printf "%b" "$APPMAN_MSG"
  1119. _use_module "$@"
  1120. ;;
  1121. 'template'|'-t')
  1122. MODULE="template.am"
  1123. _online_check
  1124. _use_module "$@"
  1125. ;;
  1126. # INBUILT OPTIONS
  1127. '--devmode-disable'|'--devmode-enable')
  1128. [ "$1" = "--devmode-disable" ] && rm -f "$AMDATADIR"/betatester \
  1129. || touch "$AMDATADIR"/betatester && _betatester_message_on
  1130. ;;
  1131. '--force-latest')
  1132. _use_force_latest "$@"
  1133. ;;
  1134. '--system')
  1135. [ -f "$APPMANCONFIG"/appman-mode ] && rm -f "$APPMANCONFIG"/appman-mode && printf "%b" "$APPMAN_MSG_OFF"
  1136. ;;
  1137. 'apikey')
  1138. _use_apikey "$@"
  1139. ;;
  1140. 'appman'|'--user')
  1141. _use_appman
  1142. ;;
  1143. 'clean'|'-c')
  1144. _use_clean
  1145. ;;
  1146. 'hide'|'unhide')
  1147. _determine_args
  1148. _use_hide_unhide "$@"
  1149. ;;
  1150. 'newrepo'|'neodb')
  1151. _use_newrepo "$@"
  1152. ;;
  1153. 'sync'|'-s')
  1154. _use_sync
  1155. ;;
  1156. 'update'|'-u'|'-U')
  1157. _use_update "$@"
  1158. ;;
  1159. 'version'|'-v'|'--version')
  1160. echo "$AMVERSION"
  1161. ;;
  1162. '--disable-notifications')
  1163. _determine_args
  1164. for n in $ARGPATHS; do sed -e '/notify-send/ s/^#*/#/' -i "$n/AM-updater" 2>/dev/null; done
  1165. ;;
  1166. '--enable-notifications')
  1167. _determine_args
  1168. for n in $ARGPATHS; do sed -e '/notify-send/ s/^#*//' -i "$n/AM-updater" 2>/dev/null; done
  1169. ;;
  1170. 'help'|'-h')
  1171. ################################################################################################################################################################
  1172. # HELP
  1173. ################################################################################################################################################################
  1174. _use_help() {
  1175. [ "$CLI" = am ] && [ -f "$APPMANCONFIG"/appman-mode ] && printf "%b" "$APPMAN_MSG"
  1176. echo -e "
  1177. NAME: ${Green}$AMCLIUPPER\033[0m VERSION: ${Green}$AMVERSION\033[0m
  1178. SYNOPSIS: ${LightBlue}$AMCLI {OPTION}\033[0m
  1179. ${LightBlue}$AMCLI {OPTION} {PROGRAM}\033[0m
  1180. DESCRIPTION: A command line utility to install and manage AppImages and other portable programs for GNU/Linux thanks to its AUR-inspired database.
  1181. OPTIONS:
  1182. ${Gold}about, -a\033[0m
  1183. ${LightBlue}$AMCLI -a {PROGRAM}\033[0m
  1184. Description: Shows more info about one or more apps.
  1185. ${Gold}apikey\033[0m
  1186. ${LightBlue}$AMCLI apikey {Github Token}
  1187. ${LightBlue}$AMCLI apikey delete\033[0m
  1188. 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.
  1189. ${Gold}backup, -b\033[0m
  1190. ${LightBlue}$AMCLI -b {PROGRAM}\033[0m
  1191. Description: Create a snapshot of the current version of an installed program.
  1192. ${Gold}clean, -c\033[0m
  1193. ${LightBlue}$AMCLI -c\033[0m
  1194. Description: Removes all the unnecessary files and folders.
  1195. ${Gold}config, -C, --config\033[0m
  1196. ${LightBlue}$AMCLI -C {PROGRAM}\033[0m
  1197. Description: Set a dedicated \$XDD_CONFIG_HOME for one or more AppImages.
  1198. ${Gold}downgrade, --rollback\033[0m
  1199. ${LightBlue}$AMCLI --rollback {PROGRAM}\033[0m
  1200. Description: Download an older or specific app version.
  1201. ${Gold}download, -d\033[0m
  1202. ${LightBlue}$AMCLI -d {PROGRAM}
  1203. ${LightBlue}$AMCLI -d --convert {PROGRAM}\033[0m
  1204. 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\").
  1205. ${Gold}extra, -e\033[0m
  1206. ${LightBlue}$AMCLI -e user/project {APPNAME}
  1207. ${LightBlue}$AMCLI -e user/project {APPNAME} {KEYWORD}\033[0m
  1208. 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.
  1209. ${Gold}files, -f, -fi\033[0m
  1210. ${LightBlue}$AMCLI -f
  1211. ${LightBlue}$AMCLI -f --byname
  1212. ${LightBlue}$AMCLI -f --less\033[0m
  1213. 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.
  1214. ${Gold}help, -h\033[0m
  1215. ${LightBlue}$AMCLI -h\033[0m
  1216. Description: Prints this message.
  1217. ${Gold}hide\033[0m
  1218. ${LightBlue}$AMCLI hide {PROGRAM}\033[0m
  1219. Description: Prevents an installed application from being shown or managed by \"$AMCLI\".
  1220. ${Gold}home, -H, --home\033[0m
  1221. ${LightBlue}$AMCLI -H {PROGRAM}\033[0m
  1222. Description: Set a dedicated \$HOME directory for one or more AppImages.
  1223. ${Gold}icons, --icons\033[0m
  1224. ${LightBlue}$AMCLI --icons {PROGRAM}
  1225. ${LightBlue}$AMCLI --icons --all\033[0m
  1226. 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.
  1227. ${Gold}install, -i\033[0m
  1228. ${LightBlue}$AMCLI -i {PROGRAM}
  1229. ${LightBlue}$AMCLI -i --debug {PROGRAM}
  1230. ${LightBlue}$AMCLI -i --force-latest {PROGRAM}
  1231. ${LightBlue}$AMCLI -i --icons {PROGRAM}
  1232. ${LightBlue}$AMCLI -i --sandbox {PROGRAM}\033[0m
  1233. 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.
  1234. ${Gold}install-appimage, -ia, -ias\033[0m
  1235. ${LightBlue}$AMCLI -ia {PROGRAM}
  1236. ${LightBlue}$AMCLI -ia --debug {PROGRAM}
  1237. ${LightBlue}$AMCLI -ia --force-latest {PROGRAM}
  1238. ${LightBlue}$AMCLI -ia --icons {PROGRAM}
  1239. ${LightBlue}$AMCLI -ia --sandbox {PROGRAM}
  1240. ${LightBlue}$AMCLI -ias {PROGRAM}\033[0m
  1241. 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.
  1242. ${Gold}lock\033[0m
  1243. ${LightBlue}$AMCLI lock {PROGRAM}\033[0m
  1244. Description: Prevent an application being updated, if it has an\"AM-updater\" script.
  1245. ${Gold}list, -l\033[0m
  1246. ${LightBlue}$AMCLI -l
  1247. ${LightBlue}$AMCLI -l --all
  1248. ${LightBlue}$AMCLI -l --appimages\033[0m
  1249. 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).
  1250. ${Gold}newrepo, neodb\033[0m
  1251. ${LightBlue}$AMCLI newrepo add {URL}\\{PATH}
  1252. ${LightBlue}$AMCLI newrepo select
  1253. ${LightBlue}$AMCLI newrepo on\\off
  1254. ${LightBlue}$AMCLI newrepo purge
  1255. ${LightBlue}$AMCLI newrepo info\033[0m
  1256. 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.
  1257. ${Gold}nolibfuse\033[0m
  1258. ${LightBlue}$AMCLI nolibfuse {PROGRAM}\033[0m
  1259. Description: Convert old AppImages and get rid of \"libfuse2\" dependence.
  1260. ${Gold}overwrite, -o\033[0m
  1261. ${LightBlue}$AMCLI -o {PROGRAM}\033[0m
  1262. Description: Overwrite apps with snapshots saved previously (see \"-b\").
  1263. ${Gold}query, -q\033[0m
  1264. ${LightBlue}$AMCLI -q {KEYWORD}
  1265. ${LightBlue}$AMCLI -q --all {KEYWORD}
  1266. ${LightBlue}$AMCLI -q --appimages {KEYWORD}
  1267. ${LightBlue}$AMCLI -q --pkg {PROGRAM1} {PROGRAM2}\033[0m
  1268. 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.
  1269. ${Gold}remove, -r\033[0m
  1270. ${LightBlue}$AMCLI -r {PROGRAM}\033[0m
  1271. Description: Removes one or more apps, requires confirmation.
  1272. ${Gold}-R\033[0m
  1273. ${LightBlue}$AMCLI -R {PROGRAM}\033[0m
  1274. Description: Removes one or more apps without asking.
  1275. ${Gold}sandbox, --sandbox\033[0m
  1276. ${LightBlue}$AMCLI sandbox {PROGRAM}\033[0m
  1277. Description: Run an AppImage in a sandbox using Aisap.
  1278. NOTE, \"--sandbox\" can be used as a flag in \"-i\" and \"-ia\" or can be replaced using the option \"-ias\" (aka Install AppImage & Sandbox).
  1279. ${Gold}sync, -s\033[0m
  1280. ${LightBlue}$AMCLI -s\033[0m
  1281. Description: Updates this script to the latest version hosted.
  1282. ${Gold}template, -t\033[0m
  1283. ${LightBlue}$AMCLI -t {PROGRAM}\033[0m
  1284. 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\").
  1285. ${Gold}unhide\033[0m
  1286. ${LightBlue}$AMCLI unhide {PROGRAM}\033[0m
  1287. Description: Allow a hidden app to be shown and managed again (nulls \"hide\").
  1288. ${Gold}unlock\033[0m
  1289. ${LightBlue}$AMCLI unlock {PROGRAM}\033[0m
  1290. Description: Unlock updates for the selected program (nulls \"lock\").
  1291. ${Gold}update, -u, -U\033[0m
  1292. ${LightBlue}$AMCLI -u
  1293. ${LightBlue}$AMCLI -u --apps
  1294. ${LightBlue}$AMCLI -u --debug
  1295. ${LightBlue}$AMCLI -u --apps --debug
  1296. ${LightBlue}$AMCLI -u {PROGRAM}\033[0m
  1297. ${LightBlue}$AMCLI -u --debug {PROGRAM}
  1298. ${LightBlue}$AMCLI -u --launcher\033[0m
  1299. 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\").
  1300. ${Gold}version, -v\033[0m
  1301. ${LightBlue}$AMCLI -v\033[0m
  1302. Description: Shows the version.
  1303. ${Gold}--devmode-disable\033[0m
  1304. ${LightBlue}$AMCLI --devmode-disable\033[0m
  1305. Description: Undo \"--devmode-enable\" (see below).
  1306. ${Gold}--devmode-enable\033[0m
  1307. ${LightBlue}$AMCLI --devmode-enable\033[0m
  1308. Description: Use the development branch (at your own risk).
  1309. ${Gold}--disable-notifications\033[0m
  1310. ${LightBlue}$AMCLI --disable-notifications\033[0m
  1311. Description: Disable notifications during apps update.
  1312. ${Gold}--disable-sandbox\033[0m
  1313. ${LightBlue}$AMCLI --disable-sandbox {PROGRAM}\033[0m
  1314. Description: Disable the sandbox for the selected app.
  1315. ${Gold}--enable-notifications\033[0m
  1316. ${LightBlue}$AMCLI --enable-notifications\033[0m
  1317. Description: Enable notifications during apps update (nulls \"--disable-notifications\").
  1318. ${Gold}--force-latest\033[0m
  1319. ${LightBlue}$AMCLI --force-latest {PROGRAM}\033[0m
  1320. Description: Downgrades an installed app from pre-release to \"latest\".
  1321. ${Gold}--launcher\033[0m
  1322. ${LightBlue}$AMCLI --launcher /path/to/\${APPIMAGE}\033[0m
  1323. 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.
  1324. 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.
  1325. ${Gold}--system\033[0m
  1326. ${LightBlue}am --system\033[0m
  1327. ${Gold}--user\033[0m
  1328. ${LightBlue}am --user\033[0m
  1329. Description: Made \"AM\" run in \"AppMan Mode\", locally, useful for unprivileged users. This option only works with \"AM\".
  1330. The \"--user\" option can also be used just as a flag for installation options. For example:
  1331. - Use it to install applications locally, option \"-i\" or \"install\":
  1332. ${LightBlue}am -i --user {PROGRAM}\033[0m
  1333. - Also suboptions of \"-i\" can work with this flag:
  1334. ${LightBlue}am -i --user --debug {PROGRAM}\033[0m
  1335. ${LightBlue}am -i --user --force-latest {PROGRAM}
  1336. ${LightBlue}am -i --user --icons {PROGRAM}
  1337. ${LightBlue}am -i --user --debug --force-latest {PROGRAM}
  1338. ${LightBlue}am -i --user --debug --force-latest --icons {PROGRAM}\033[0m
  1339. - Same for AppImages only, option \"-ia\" or \"install-appimage\":
  1340. ${LightBlue}am -ia --user {PROGRAM}\033[0m
  1341. ${LightBlue}am -ia --user --debug {PROGRAM}
  1342. ${LightBlue}am -ia --user --force-latest {PROGRAM}
  1343. ${LightBlue}am -ia --user --icons {PROGRAM}
  1344. ${LightBlue}am -ia --user --debug --force-latest {PROGRAM}\033[0m
  1345. ${LightBlue}am -ia --user --debug --force-latest --icons {PROGRAM}\033[0m
  1346. - External AppImages can be installed like this as well, option \"-e\" or \"extra\":
  1347. ${LightBlue}am -e --user user/project {APPNAME}\033[0m
  1348. ${LightBlue}am -e --user user/project {APPNAME} {KEYWORD}\033[0m
  1349. NOTE, \"AM\" 9 or higher is also able to, update and manage apps locally, by default, and without having to switch to \"AppMan Mode\".
  1350. Description: Switch \"AM\" back to \"AM\" from \"AppMan Mode\" (see \"--user\").
  1351. $DIVIDING_LINE
  1352. THIRD-PARTY FLAGS: $third_party_flags_message
  1353. $DIVIDING_LINE
  1354. SITES:
  1355. https://github.com/ivan-hc/AM
  1356. https://portable-linux-apps.github.io
  1357. \n" | sed 's/^ //g' | _fit | less -Ir
  1358. }
  1359. if [ -t 1 ]; then _use_help; else _use_help | sed -e 's/\x1b\[[0-9;]*m//g'; fi
  1360. ;;
  1361. *)
  1362. exec "$AMCLIPATH"
  1363. ;;
  1364. esac
  1365. # vim:tabstop=4:shiftwidth=4:expandtab