install.am 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. #!/bin/sh
  2. #############################################################################
  3. # THIS MODULE IS USED TO INSTALL APPS FROM THE DATABASE OR FROM LOCAL SCRIPTS
  4. #############################################################################
  5. BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
  6. #--------------------------------------------------------------------------
  7. # DOWNLOAD
  8. _convert_to_appman_compatible_script() {
  9. _detect_appman_apps
  10. _appman
  11. if [ -d "$APPMAN_APPSPATH" ]; then
  12. sed -i "s# /usr/local/bin# $HOME/.local/bin#g" ./"$arg"
  13. sed -i "s# /usr/local/share/applications# $DATADIR/applications#g" ./"$arg"
  14. sed -i "s# /opt# $APPMAN_APPSPATH#g" ./"$arg"
  15. sed -i "s# https://api.github.com#$HeaderAuthWithGITPAT https://api.github.com#g" ./"$arg"
  16. cat <<-HEREDOC >> ./"$arg"
  17. # POST INSTALLATION PATCH FOR ALL LAUNCHERS
  18. sed -i "s#Exec=\$APP#Exec=$HOME/.local/bin/$APP#g" $DATADIR/applications/*-AM.desktop
  19. sed -i "s#Exec=/usr/bin/#Exec=$HOME/.local/bin/#g" $DATADIR/applications/*-AM.desktop
  20. sed -i "s#Exec=/opt/#Exec=$HOME/$APPSDIR#g" $DATADIR/applications/*-AM.desktop
  21. sed -i "s#Icon=/opt/#Icon=$HOME/$APPSDIR#g" $DATADIR/applications/*-AM.desktop
  22. HEREDOC
  23. printf " Converting %s to an AppMan-compatible script.\r" "$arg" && sleep 0.25 &&
  24. printf " \r"
  25. else
  26. echo ' 💀 ERROR: "--convert" requires a configuration file in ~/.config/appman'
  27. fi
  28. }
  29. _download() {
  30. if curl --output /dev/null --silent --head --fail "$APPSDB/$arg" 1>/dev/null; then
  31. cd "$SCRIPTDIR" || return 1
  32. [ ! -f ./"$arg" ] && wget -q "$APPSDB/$arg" || return 1
  33. echo " ◆ \"$arg\" installation script downloaded! "
  34. elif curl --output /dev/null --silent --head --fail "$AMREPO/testing/$ARCH/$arg" 1>/dev/null; then
  35. cd "$SCRIPTDIR" || return 1
  36. [ ! -f ./"$arg" ] && wget -q "$AMREPO/testing/$ARCH/$arg" || return 1
  37. echo " ⚠️ \"$arg\" downloaded from \"testing\", the unstable branch, BE AWARE!"
  38. else
  39. echo " 💀 ERROR: \"$arg\" is NOT a valid argument"
  40. fi
  41. }
  42. #--------------------------------------------------------------------------
  43. # INSTALL
  44. _if_latest() {
  45. if echo "$FLAGS" | grep -q -- '--force-latest'; then
  46. # If you use the --latest option, add the "latest" flag to scripts that point to a very common "release"
  47. sed -i 's#/releases #/releases/latest #g' ./"$arg"
  48. fi
  49. }
  50. _if_icons() {
  51. if echo "$FLAGS" | grep -q -- '--icons'; then
  52. # Install the app so that it can rely on an icon theme (if available)
  53. sed -i "s#Icon=/opt/\$APP/icons/#Icon=#g" ./"$arg"
  54. fi
  55. }
  56. _if_debug() {
  57. if ! echo "$FLAGS" | grep -q -- "--debug" && wget --version | head -1 | grep -q ' 1.'; then
  58. # Patch "wget" (version 1.x) to have a progress bar and fix errors when applying patches
  59. sed -i "s#wget #wget -q --no-verbose --show-progress --progress=bar #g" ./"$arg"
  60. fi
  61. }
  62. _spooky_check() {
  63. if grep -i spooky ./"$arg" >/dev/null 2>&1; then
  64. printf "%b%b" "\n ${RED}WARNING:" " \"$arg\" does not have a transparent build process! \033[0m\n\n"
  65. echo " We can't be sure as to what is inside the application"
  66. echo " We highly recommend that you sandbox this application"
  67. echo ""
  68. read -p " Do you wish to continue? (N/y): " yn
  69. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  70. printf "\n INSTALLATION ABORTED! \n"
  71. return 1
  72. fi
  73. fi
  74. }
  75. # Patch to apply to installation scripts
  76. _apply_patches() {
  77. if [ "$AMCLI" = "appman" ]; then
  78. # Patches /usr/local for $HOME equivalent for AppMan
  79. sed -i -e "s#/usr/local/bin#$BINDIR#g" \
  80. -e "s#/usr/local/share#$DATADIR#g" \
  81. -e "s#/opt/#$APPSPATH/#g" ./"$arg"
  82. else
  83. "$SUDOCMD" mkdir -p /usr/local/share/applications /usr/local/bin
  84. fi
  85. sed -i "s# https://api.github.com#$HeaderAuthWithGITPAT https://api.github.com#g" ./"$arg"
  86. sed -i "s#DirIcon\$#DirIcon 2>/dev/null#g" ./"$arg"
  87. sed -i "s#DirIcon ./icons/\"\$APP\" 1#DirIcon ./icons/\"\$APP\" 2#g" ./"$arg"
  88. }
  89. _am_remover_check() {
  90. # Put permission check in remove script and change ownership of directory
  91. if [ "$AMCLI" = am ]; then
  92. $SUDOCMD sed -i "1 a [ \"\$(id -u)\" -ne 0 ] && echo "Permission denied" && exit 1" \
  93. "${LASTDIRPATH}"/remove 2>/dev/null
  94. $SUDOCMD chown -R "$USER" "${LASTDIRPATH}" 2>/dev/null
  95. fi
  96. }
  97. # Post-installation processes
  98. _post_installation_processes() {
  99. LASTDIR=$(ls -td "$APPSPATH"/* | head -1 | sed 's:.*/::')
  100. LASTDIRPATH="${APPSPATH}/${LASTDIR}"
  101. _am_remover_check
  102. # Check for AM-updater script sothat CLI can manage updates
  103. [ -f "${LASTDIRPATH}"/AM-updater ] && mkdir "${LASTDIRPATH}"/.am-installer 2>/dev/null \
  104. && curl -Ls "$APPSDB"/"$arg" > "${LASTDIRPATH}"/.am-installer/"$arg"
  105. find "${LASTDIRPATH}"/icons/* -xtype l -delete 2>/dev/null # Removes broken links
  106. # If you have a broken or missing icon in your "icons" directory, download one from the catalog
  107. [ -z "$(ls -A "${LASTDIRPATH}"/icons 2>/dev/null)" ] \
  108. && wget -q "$AMCATALOGUEICONS"/"$arg".png -O "${LASTDIRPATH}"/icons/"$arg" 2>/dev/null
  109. # Patch .desktop to change paths if the app is installed locally
  110. if [ "$AMCLI" = "appman" ]; then
  111. # Likely not needed anymore: "s#Icon=/opt#Icon=$HOME/$APPSDIR#g"
  112. sed -i -e "s#Exec=$arg#Exec=$BINDIR/$arg#g" \
  113. -e "s#Exec=\$APP#Exec=$BINDIR/\$APP#g" \
  114. -e "s#Exec=/usr/bin/#Exec=$BINDIR/#g" \
  115. -e "s#Exec=/opt/#Exec=$BINDIR/#g" "$DATADIR"/applications/*-AM.desktop 2>/dev/null
  116. fi
  117. if echo "$FLAGS" | grep -q -- '--icons'; then
  118. # Export all icons for hicolor theme usage
  119. _icon_theme_export_to_datadir 2>/dev/null
  120. fi
  121. }
  122. # End of the installation process
  123. _ending_the_installation() {
  124. unset "$LASTDIR" # Is this needed?
  125. LASTDIR=$(ls -td "$APPSPATH"/* | head -1 | sed 's:.*/::')
  126. if [ -f "${LASTDIRPATH}"/remove ]; then
  127. if test -d "${LASTDIRPATH}"/tmp; then
  128. echo " 💀 ERROR DURING INSTALLATION, REMOVED $APPNAME!"
  129. $SUDOCMD "$APPSPATH/$LASTDIR/remove" 1>/dev/null
  130. elif test -f "$APPSPATH/$LASTDIR/version" && [ -z "$(cat "$APPSPATH/$LASTDIR/version")" ]; then
  131. echo " 💀 ERROR DURING INSTALLATION, REMOVED $APPNAME!"
  132. $SUDOCMD "$APPSPATH/$LASTDIR/remove" 1> /dev/null
  133. else
  134. APPSIZE=$(du -sm "${LASTDIRPATH}" | awk '{print $1}' )
  135. LASTDIRNAME=$(echo "\"$LASTDIR\"" | tr '[:lower:]' '[:upper:]')
  136. printf "%b%b%s\n" " ${Green}" "$LASTDIRNAME INSTALLED\033[0m" " ($APPSIZE MB OF DISK SPACE)"
  137. $SUDOCMD rm "$AMCACHEDIR"/"$arg"
  138. _check_version
  139. app_version=$(grep -w " ◆ $LASTDIR |" 0<"$AMCACHEDIR"/version-args | sed 's:.*| ::')
  140. echo " ◆ $LASTDIR $app_version" >> "$AMCACHEDIR"/installed
  141. fi
  142. else
  143. echo " INSTALLATION ABORTED!"
  144. fi
  145. }
  146. # Check if the installation script contain a keyword related to a missing dependence
  147. _dependency_check_utils() {
  148. app_deps="ar gcc glib-compile-schemas make tar unzip"
  149. for name in $app_deps; do
  150. if grep "^$name" ./"$arg" 1>/dev/null && ! command -v "$name" >/dev/null 2>&1; then
  151. [ "$name" = "ar" ] && name="binutils"
  152. echo " 💀 ERROR: cannot install \"$arg\" without \"$name\""
  153. return 1
  154. fi
  155. done
  156. }
  157. # Check if the installation script is a metapackage (example one of the 40+ kdegames scripts)
  158. _metapackage_check() {
  159. for metapackage in $METAPACKAGES; do
  160. if grep -q "$metapackage" ./"$arg" 2> /dev/null; then
  161. if [ -d "$APPSPATH"/"$metapackage"/tmp ]; then
  162. $SUDOCMD "$APPSPATH"/"$metapackage"/remove 2> /dev/null
  163. elif [ -d "$APPSPATH"/"$metapackage" ]; then
  164. METAPACKAGE_NAME=$(echo "$metapackage" | tr '[:lower:]' '[:upper:]')
  165. echo " ◆ $APPNAME IS PART OF \"$METAPACKAGE_NAME\", ALREADY INSTALLED"
  166. return 1
  167. fi
  168. fi
  169. done
  170. }
  171. ######################
  172. # INSTALLATION PROCESS
  173. ######################
  174. # This function is needed to parse the installation script and then execute it
  175. _install_arg() {
  176. APPNAME=$(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')
  177. chmod a+x ./"$arg"
  178. _metapackage_check || return 1
  179. _dependency_check_utils || return 1
  180. if grep -q 'ffwa-' ./"$arg"; then
  181. ffbrowser=$(find ${PATH//:/ } -maxdepth 1 -name "firefox*" | sort | head -1)
  182. if [ -z "$ffbrowser" ]; then
  183. echo " 💀 ERROR: you cannot install \"$arg\" without installing \"firefox\""; return 0
  184. else
  185. sed -i 's#firefox --class#'"$(echo "$ffbrowser" | xargs -L 1 basename)"' --class#g' ./"$arg"
  186. fi
  187. elif grep -qi "^wget.*.sh.*chmod.*&&" ./"$arg"; then
  188. appimage_bulder_script=$(grep "^wget " ./"$arg" | tr '"' '\n' | grep -i "^http" | sed "s/\$APP/$arg/g")
  189. if curl --output /dev/null --silent --head --fail "$appimage_bulder_script" 1> /dev/null; then
  190. for name in $app_deps; do
  191. if curl -Ls "$appimage_bulder_script" | grep "^$name" 1>/dev/null; then
  192. if ! command -v "$name" >/dev/null 2>&1; then
  193. [ "$name" = "ar" ] && name="binutils"
  194. echo " 💀 ERROR: cannot install \"$arg\" without \"$name\""
  195. return 0
  196. fi
  197. fi
  198. done
  199. if curl -Ls "$appimage_bulder_script" | grep -ie "appimagetool\|pkg2appimage" 1>/dev/null; then
  200. if ! command -v convert >/dev/null 2>&1; then
  201. echo " 💀 ERROR: cannot create \"$arg\" without \"convert\" (from \"imagemagick\")"
  202. return 0
  203. fi
  204. fi
  205. else
  206. echo " 💀 ERROR: cannot create \"$arg\", the builder does not exists"
  207. return 0
  208. fi
  209. fi
  210. # Check if you are installing an app or a library
  211. echo " ◆ $APPNAME: starting installation script"
  212. if grep -qi "^wget.*.sh.*chmod.*&&" ./"$arg"; then
  213. printf "\n This script will create an AppImage on the fly, please wait...\n"
  214. elif grep -q "/usr/local/lib" ./"$arg"; then
  215. printf "\n ⚠️ This script will install a system library in /usr/local/lib\n\n"
  216. read -p " Do you wish to continue? (N/y): " yn
  217. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  218. printf "\n INSTALLATION ABORTED! \n"
  219. return 0
  220. fi
  221. fi
  222. _spooky_check || return 1
  223. _if_debug
  224. _if_icons
  225. _if_latest
  226. _apply_patches
  227. echo ""
  228. # Install script
  229. if grep -q "https://repology.org" ./"$arg"; then
  230. REPOLOGY_API_ALLOWED=$(curl -Ls https://repology.org/)
  231. if [ -z "$REPOLOGY_API_ALLOWED" ]; then
  232. if command -v torsocks 1>/dev/null; then
  233. sed -i "s/version=\$(wget/version=\$(torsocks wget/g" ./"$arg"
  234. else
  235. echo " 💀 Cannot install \"$arg\", you have no access to https://repology.org, needed to check the version of this program." \
  236. | fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
  237. echo ""
  238. echo " Install \"torsocks\" from your system package manager and retry!"
  239. return 0
  240. fi
  241. fi
  242. fi
  243. if grep -q "api.github.com" ./"$arg"; then
  244. 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)
  245. if [ -z "$GH_API_ALLOWED" ]; then
  246. if command -v torsocks 1>/dev/null; then
  247. $SUDOCMD torsocks ./"$arg"
  248. else
  249. echo " 💀 Cannot install \"$arg\", you have reached GitHub API limit." \
  250. | fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
  251. echo ""
  252. echo " Install \"torsocks\" from your system package manager and retry!"
  253. return 0
  254. fi
  255. else
  256. $SUDOCMD ./"$arg"
  257. fi
  258. else
  259. $SUDOCMD ./"$arg"
  260. fi
  261. echo ""
  262. _post_installation_processes
  263. _ending_the_installation
  264. }
  265. ####################
  266. # INSTALLATION CASES
  267. ####################
  268. # This function is for local installation scripts
  269. _install_local_script() {
  270. path2arg="$arg"
  271. arg=$(echo "$path2arg" | sed 's:.*/::')
  272. mkdir -p "$AMCACHEDIR"/tmp && rm -f "$AMCACHEDIR"/tmp/* \
  273. && cp "$path2arg" "$AMCACHEDIR"/tmp/"$arg" && cd "$AMCACHEDIR" \
  274. && mv ./tmp/"$arg" ./"$arg" && rmdir ./tmp || return
  275. if ! test -d "$APPSPATH"/"$arg"; then
  276. _install_arg
  277. else
  278. echo " ◆ \"$arg\" is already installed!" | tr '[:lower:]' '[:upper:]'
  279. fi
  280. }
  281. # This function is needed to handle Toolpacks
  282. _toolpack_handler() {
  283. mkdir -p "$CACHEDIR/toolpack"
  284. toolpack_version="curl -Ls "$toolpack_readme" | grep -i \"^| $arg \" | tr '|' '\\\n' | cut -c 2- | grep . | awk -F: \"NR==$toolpack_ver\""
  285. toolpak_url="curl -Ls "$toolpack_readme" | grep -i \"^| $arg \" | tr '|' '\\\n' | cut -c 2- | grep . | awk -F: \"NR==$toolpack_dl\""
  286. if echo "$arg" | grep -q "appimage$"; then
  287. curl -Ls "$AMREPO"/templates/AM-SAMPLE-AppImage > "$CACHEDIR/toolpack/$arg.toolpack" || exit 1
  288. else
  289. curl -Ls "$AMREPO"/templates/AM-SAMPLE-Archive > "$CACHEDIR/toolpack/$arg.toolpack" || exit 1
  290. fi
  291. sed -i "s#APP=SAMPLE#APP=$arg#g; s#FUNCTION#$toolpack_version#g; s#wget \"\$version\"#wget \$($toolpak_url)#g" "$CACHEDIR/toolpack/$arg.toolpack"
  292. sed -e '/\[ -e/ s/^#*/#/' -i "$CACHEDIR/toolpack/$arg.toolpack" 2>/dev/null
  293. chmod a+x "$CACHEDIR/toolpack/$arg.toolpack"
  294. arg="$CACHEDIR/toolpack/$arg.toolpack"
  295. }
  296. # This is for scripts hosted on the official online database
  297. _install_normally() {
  298. mkdir -p "$AMCACHEDIR"/tmp && rm -f "$AMCACHEDIR"/tmp/* || return
  299. curl -Ls "$APPSDB"/"$arg" > "$AMCACHEDIR"/tmp/"$arg" || return
  300. cd "$AMCACHEDIR" && mkdir -p tmp && cd tmp || return
  301. cd "$AMCACHEDIR" && mv ./tmp/"$arg" ./"$arg" && rmdir ./tmp || return
  302. _install_arg
  303. }
  304. ################################################################################
  305. # USAGE
  306. ################################################################################
  307. case "$1" in
  308. '-d'|'download')
  309. case $2 in
  310. '--convert')
  311. [ -z "$3" ] && echo " USAGE: $AMCLI $1 $2 [ARGUMENT]" && exit 1
  312. ;;
  313. '')
  314. echo " USAGE: $AMCLI $1 [ARGUMENT]"
  315. echo " USAGE: $AMCLI $1 --convert [ARGUMENT]"
  316. exit 1
  317. ;;
  318. esac
  319. if [ "$2" = "--convert" ]; then
  320. entries="$(echo "$@" | cut -f3- -d ' ')"
  321. for arg in $entries; do
  322. _download
  323. _convert_to_appman_compatible_script
  324. done
  325. else
  326. entries="$(echo "$@" | cut -f2- -d ' ')"
  327. for arg in $entries; do
  328. _download
  329. done
  330. fi
  331. ;;
  332. '-i'|'install')
  333. [ "$AMCLI" = "am" ] && echo "$@" | grep -q -- "--user" && _appman
  334. case $2 in
  335. '')
  336. echo " USAGE: $AMCLI $1 [ARGUMENT]"
  337. echo " USAGE: $AMCLI $1 --debug [ARGUMENT]"
  338. echo " USAGE: $AMCLI $1 --force-latest [ARGUMENT]"
  339. echo " USAGE: $AMCLI $1 --icons [ARGUMENT]"
  340. [ "$AMCLI" = "am" ] && echo " USAGE: $AMCLI $1 --user [ARGUMENT]"
  341. exit 1
  342. ;;
  343. esac
  344. [ "$AMCLI" = "am" ] && { $SUDOCMD printf "\r" || exit 1; }
  345. echo "============================================================================"
  346. echo ""
  347. printf " %bSTART OF ALL INSTALLATION PROCESSES\033[0m\n" "${LightBlue}"
  348. echo ""
  349. echo "============================================================================"
  350. _clean_amcachedir 2>/dev/null
  351. entries="$(echo "$@" | cut -f2- -d ' ' | tr ' ' '\n' | grep -v -- "--")"
  352. FLAGS=$(echo "$@" | tr ' ' '\n' | grep -- "--" | tr '\n ' ' ')
  353. METAPACKAGES="kdegames kdeutils node platform-tools"
  354. for arg in $entries; do
  355. echo ""
  356. cd "$REALDIR" || return
  357. # If the "tmp" directory is not removed, the installation failed, so remove the app
  358. if [ -d "$APPSPATH"/"$arg"/tmp ]; then
  359. $SUDOCMD "$APPSPATH"/"$arg"/remove 2> /dev/null
  360. fi
  361. # Various cases that may occur during installation
  362. if test -f "$APPSPATH"/"$arg"/remove; then
  363. echo " ◆ \"$arg\" is already installed!" | tr '[:lower:]' '[:upper:]'
  364. else
  365. if echo "$arg" | grep -q "/"; then
  366. if test -f "$arg" 2> /dev/null; then
  367. _install_local_script
  368. else
  369. echo " 💀 ERROR: the file \"$arg\" does NOT exist"
  370. fi
  371. elif echo "$@" | grep -q -- "--toolpack" || echo "$@" | grep -q -- ".toolpack$"; then
  372. arg=$(echo "$arg" | sed 's/\.toolpack//g')
  373. if curl -Ls "$toolpack_readme" | grep -q "^| $arg "; then
  374. _toolpack_handler
  375. _install_local_script
  376. elif curl --output /dev/null --silent --head --fail "$APPSDB"/"$arg" 1>/dev/null; then
  377. _install_normally
  378. else
  379. echo " 💀 ERROR: \"$arg\" does NOT exist in Toolpacks"
  380. fi
  381. elif curl --output /dev/null --silent --head --fail "$APPSDB"/"$arg" 1>/dev/null; then
  382. _install_normally
  383. else
  384. echo " 💀 ERROR: \"$arg\" does NOT exist in the database, see \"$AMCLI -l\""
  385. fi
  386. fi
  387. echo "____________________________________________________________________________"
  388. done
  389. if [ -f "$AMCACHEDIR"/installed ]; then
  390. echo "============================================================================"
  391. printf "\n %bEND OF ALL INSTALLATION PROCESSES\n\033[0m" "${LightBlue}"
  392. printf "\n The following new programs have been installed:\n\n"
  393. grep -w -v "◆ am" 0<"$AMCACHEDIR"/installed
  394. echo ""
  395. echo "============================================================================"
  396. exit 0
  397. else
  398. exit 1
  399. fi
  400. ;;
  401. '-ia'|'install-appimage')
  402. AMCLIPATH_ORIGIN="$AMCLIPATH"
  403. [ "$AMCLI" = "am" ] && echo "$@" | grep -q -- "--user" && _appman
  404. rm -f "$AMCACHEDIR"/install-args
  405. entries="$(echo "$@" | cut -f2- -d ' ' | tr ' ' '\n' | grep -v -- "--")"
  406. FLAGS=$(echo "$@" | tr ' ' '\n' | grep -- "--" | tr '\n ' ' ')
  407. APPIMAGE_NAMES=$(curl -Ls https://portable-linux-apps.github.io/appimages.md | tr '/)' '\n' | grep -i ".md$" | uniq | sed 's/.md$//g' | grep -v "\[")
  408. rm -f "$AMCACHEDIR/$ARCH-appimages"
  409. for appimage in $APPIMAGE_NAMES; do
  410. grep "◆ $appimage :" "$AMDATADIR/$ARCH-apps" >> "$AMCACHEDIR/$ARCH-appimages" &
  411. done
  412. for arg in $entries; do
  413. if grep -q "^◆ $arg : " "$AMCACHEDIR/$ARCH-appimages"; then
  414. echo "$arg" >> "$AMCACHEDIR"/install-args
  415. else
  416. arg="$arg-appimage"
  417. if ! grep -q "^◆ $arg : " "$AMCACHEDIR/$ARCH-appimages"; then
  418. echo " ✖ \"$(echo "$arg" | sed 's/-appimage//g')\" is not an Appimage"
  419. else
  420. echo "$arg" >> "$AMCACHEDIR"/install-args
  421. fi
  422. fi
  423. done
  424. APPIMAGES_ARGS=$(<"$AMCACHEDIR"/install-args sed 's/\n/ /g')
  425. "$AMCLIPATH_ORIGIN" -i $FLAGS "$APPIMAGES_ARGS"
  426. exit 1
  427. ;;
  428. '-e'|'extra')
  429. AMCLIPATH_ORIGIN="$AMCLIPATH"
  430. if [ -z "$2" ] || [ -z "$3" ]; then
  431. echo " USAGE: $AMCLI $1 user/project [ARGUMENT]"
  432. echo " USAGE: $AMCLI $1 user/project [ARGUMENT] [KEYWORD]"
  433. echo " USAGE: $AMCLI $1 --user user/project [ARGUMENT]"
  434. echo " USAGE: $AMCLI $1 --user user/project [ARGUMENT] [KEYWORD]"
  435. exit 1
  436. fi
  437. case $2 in
  438. '--user')
  439. USER_PROJECT=$(echo "$3" | sed 's#https://github.com/##g' | cut -f1,2 -d'/')
  440. EXTERNAL_APP_NAME="$4"
  441. APP_KEYWORD="$5"
  442. ;;
  443. *)
  444. USER_PROJECT=$(echo "$2" | sed 's#https://github.com/##g' | cut -f1,2 -d'/')
  445. EXTERNAL_APP_NAME="$3"
  446. APP_KEYWORD="$4"
  447. ;;
  448. esac
  449. mkdir -p "$CACHEDIR/extra"
  450. curl -Ls "$AMREPO"/templates/AM-SAMPLE-AppImage > "$CACHEDIR/extra/$EXTERNAL_APP_NAME" || exit 1
  451. sed -i "s#APP=SAMPLE#APP=$EXTERNAL_APP_NAME#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  452. API_GITHUB_REPO="https://api.github.com/repos/$USER_PROJECT/releases"
  453. sed -i "s#REPLACETHIS#$USER_PROJECT#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  454. q="'"
  455. if [ "$ARCH" = "x86_64" ]; then
  456. FILTER=' | grep -vi "i386\\|i686\\|i586\\|i486\\|aarch64\\|arm64\\|armv7l"'
  457. elif [ "$ARCH" = "i686" ]; then
  458. FILTER=' | grep -ie "i386\\|i686\\|i586\\|i486" '
  459. elif [ "$ARCH" = "aarch64" ]; then
  460. FILTER=' | grep -ie "aarch64\\|arm64" '
  461. fi
  462. FUNCTION='curl -Ls '"$API_GITHUB_REPO"' | sed '"$q"'s/[()",{} ]/\\n/g'"$q"' | grep -oi "https.*mage$"'"$FILTER"' | head -1'
  463. sed -i "s#FUNCTION)#$FUNCTION)#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  464. [ -n "$APP_KEYWORD" ] && sed -i "s# head -1# grep -i \"$APP_KEYWORD\" | head -1#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  465. chmod a+x "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  466. [ "$AMCLI" = "am" ] && [ "$2" = "--user" ] && "$AMCLIPATH_ORIGIN" -i --user "$CACHEDIR/extra/$EXTERNAL_APP_NAME" \
  467. || "$AMCLIPATH_ORIGIN" -i "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  468. exit 1
  469. ;;
  470. esac