install.am 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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 is for scripts hosted on the official online database
  282. _install_normally() {
  283. mkdir -p "$AMCACHEDIR"/tmp && rm -f "$AMCACHEDIR"/tmp/* || return
  284. curl -Ls "$APPSDB"/"$arg" > "$AMCACHEDIR"/tmp/"$arg" || return
  285. cd "$AMCACHEDIR" && mkdir -p tmp && cd tmp || return
  286. cd "$AMCACHEDIR" && mv ./tmp/"$arg" ./"$arg" && rmdir ./tmp || return
  287. _install_arg
  288. }
  289. ################################################################################
  290. # USAGE
  291. ################################################################################
  292. case "$1" in
  293. '-d'|'download')
  294. case $2 in
  295. '--convert')
  296. [ -z "$3" ] && echo " USAGE: $AMCLI $1 $2 [ARGUMENT]" && exit 1
  297. ;;
  298. '')
  299. echo " USAGE: $AMCLI $1 [ARGUMENT]"
  300. echo " USAGE: $AMCLI $1 --convert [ARGUMENT]"
  301. exit 1
  302. ;;
  303. esac
  304. if [ "$2" = "--convert" ]; then
  305. entries="$(echo "$@" | cut -f3- -d ' ')"
  306. for arg in $entries; do
  307. _download
  308. _convert_to_appman_compatible_script
  309. done
  310. else
  311. entries="$(echo "$@" | cut -f2- -d ' ')"
  312. for arg in $entries; do
  313. _download
  314. done
  315. fi
  316. ;;
  317. '-i'|'install')
  318. [ "$AMCLI" = "am" ] && echo "$@" | grep -q -- "--user" && _appman
  319. case $2 in
  320. '')
  321. echo " USAGE: $AMCLI $1 [ARGUMENT]"
  322. echo " USAGE: $AMCLI $1 --debug [ARGUMENT]"
  323. echo " USAGE: $AMCLI $1 --force-latest [ARGUMENT]"
  324. echo " USAGE: $AMCLI $1 --icons [ARGUMENT]"
  325. [ "$AMCLI" = "am" ] && echo " USAGE: $AMCLI $1 --user [ARGUMENT]"
  326. exit 1
  327. ;;
  328. esac
  329. [ "$AMCLI" = "am" ] && { $SUDOCMD printf "\r" || exit 1; }
  330. echo "============================================================================"
  331. echo ""
  332. printf " %bSTART OF ALL INSTALLATION PROCESSES\033[0m\n" "${LightBlue}"
  333. echo ""
  334. echo "============================================================================"
  335. _clean_amcachedir 2>/dev/null
  336. entries="$(echo "$@" | cut -f2- -d ' ' | tr ' ' '\n' | grep -v -- "--")"
  337. FLAGS=$(echo "$@" | tr ' ' '\n' | grep -- "--" | tr '\n ' ' ')
  338. METAPACKAGES="kdegames kdeutils node platform-tools"
  339. for arg in $entries; do
  340. echo ""
  341. cd "$REALDIR" || return
  342. # If the "tmp" directory is not removed, the installation failed, so remove the app
  343. if [ -d "$APPSPATH"/"$arg"/tmp ]; then
  344. $SUDOCMD "$APPSPATH"/"$arg"/remove 2> /dev/null
  345. fi
  346. # Various cases that may occur during installation
  347. if test -f "$APPSPATH"/"$arg"/remove; then
  348. echo " ◆ \"$arg\" is already installed!" | tr '[:lower:]' '[:upper:]'
  349. else
  350. if echo "$arg" | grep -q "/"; then
  351. if test -f "$arg" 2> /dev/null; then
  352. _install_local_script
  353. else
  354. echo " 💀 ERROR: the file \"$arg\" does NOT exist"
  355. fi
  356. elif curl --output /dev/null --silent --head --fail "$APPSDB"/"$arg" 1>/dev/null; then
  357. _install_normally
  358. else
  359. echo " 💀 ERROR: \"$arg\" does NOT exist in the database, see \"$AMCLI -l\""
  360. fi
  361. fi
  362. echo "____________________________________________________________________________"
  363. done
  364. if [ -f "$AMCACHEDIR"/installed ]; then
  365. echo "============================================================================"
  366. printf "\n %bEND OF ALL INSTALLATION PROCESSES\n\033[0m" "${LightBlue}"
  367. printf "\n The following new programs have been installed:\n\n"
  368. grep -w -v "◆ am" 0<"$AMCACHEDIR"/installed
  369. echo ""
  370. echo "============================================================================"
  371. exit 0
  372. else
  373. exit 1
  374. fi
  375. ;;
  376. '-ia'|'install-appimage')
  377. AMCLIPATH_ORIGIN="$AMCLIPATH"
  378. [ "$AMCLI" = "am" ] && echo "$@" | grep -q -- "--user" && _appman
  379. rm -f "$AMCACHEDIR"/install-args
  380. entries="$(echo "$@" | cut -f2- -d ' ' | tr ' ' '\n' | grep -v -- "--")"
  381. FLAGS=$(echo "$@" | tr ' ' '\n' | grep -- "--" | tr '\n ' ' ')
  382. APPIMAGE_NAMES=$(curl -Ls https://portable-linux-apps.github.io/appimages.md | tr '/)' '\n' | grep -i ".md$" | uniq | sed 's/.md$//g' | grep -v "\[")
  383. rm -f "$AMCACHEDIR/$ARCH-appimages"
  384. for appimage in $APPIMAGE_NAMES; do
  385. grep "◆ $appimage :" "$AMDATADIR/$ARCH-apps" >> "$AMCACHEDIR/$ARCH-appimages" &
  386. done
  387. for arg in $entries; do
  388. if grep -q "^◆ $arg : " "$AMCACHEDIR/$ARCH-appimages"; then
  389. echo "$arg" >> "$AMCACHEDIR"/install-args
  390. else
  391. arg="$arg-appimage"
  392. if ! grep -q "^◆ $arg : " "$AMCACHEDIR/$ARCH-appimages"; then
  393. echo " ✖ \"$(echo "$arg" | sed 's/-appimage//g')\" is not an Appimage"
  394. else
  395. echo "$arg" >> "$AMCACHEDIR"/install-args
  396. fi
  397. fi
  398. done
  399. APPIMAGES_ARGS=$(<"$AMCACHEDIR"/install-args sed 's/\n/ /g')
  400. "$AMCLIPATH_ORIGIN" -i $FLAGS "$APPIMAGES_ARGS"
  401. exit 1
  402. ;;
  403. '-e'|'extra')
  404. AMCLIPATH_ORIGIN="$AMCLIPATH"
  405. if [ -z "$2" ] || [ -z "$3" ]; then
  406. echo " USAGE: $AMCLI $1 user/project [ARGUMENT]"
  407. echo " USAGE: $AMCLI $1 user/project [ARGUMENT] [KEYWORD]"
  408. echo " USAGE: $AMCLI $1 --user user/project [ARGUMENT]"
  409. echo " USAGE: $AMCLI $1 --user user/project [ARGUMENT] [KEYWORD]"
  410. exit 1
  411. fi
  412. case $2 in
  413. '--user')
  414. USER_PROJECT=$(echo "$3" | sed 's#https://github.com/##g' | cut -f1,2 -d'/')
  415. EXTERNAL_APP_NAME="$4"
  416. APP_KEYWORD="$5"
  417. ;;
  418. *)
  419. USER_PROJECT=$(echo "$2" | sed 's#https://github.com/##g' | cut -f1,2 -d'/')
  420. EXTERNAL_APP_NAME="$3"
  421. APP_KEYWORD="$4"
  422. ;;
  423. esac
  424. mkdir -p "$CACHEDIR/extra"
  425. curl -Ls "$AMREPO"/templates/AM-SAMPLE-AppImage > "$CACHEDIR/extra/$EXTERNAL_APP_NAME" || exit 1
  426. sed -i "s#APP=SAMPLE#APP=$EXTERNAL_APP_NAME#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  427. API_GITHUB_REPO="https://api.github.com/repos/$USER_PROJECT/releases"
  428. sed -i "s#REPLACETHIS#$USER_PROJECT#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  429. q="'"
  430. if [ "$ARCH" = "x86_64" ]; then
  431. FILTER=' | grep -vi "i386\\|i686\\|i586\\|i486\\|aarch64\\|arm64\\|armv7l"'
  432. elif [ "$ARCH" = "i686" ]; then
  433. FILTER=' | grep -ie "i386\\|i686\\|i586\\|i486" '
  434. elif [ "$ARCH" = "aarch64" ]; then
  435. FILTER=' | grep -ie "aarch64\\|arm64" '
  436. fi
  437. FUNCTION='curl -Ls '"$API_GITHUB_REPO"' | sed '"$q"'s/[()",{} ]/\\n/g'"$q"' | grep -oi "https.*mage$"'"$FILTER"' | head -1'
  438. sed -i "s#FUNCTION)#$FUNCTION)#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  439. [ -n "$APP_KEYWORD" ] && sed -i "s# head -1# grep -i \"$APP_KEYWORD\" | head -1#g" "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  440. chmod a+x "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  441. [ "$AMCLI" = "am" ] && [ "$2" = "--user" ] && "$AMCLIPATH_ORIGIN" -i --user "$CACHEDIR/extra/$EXTERNAL_APP_NAME" \
  442. || "$AMCLIPATH_ORIGIN" -i "$CACHEDIR/extra/$EXTERNAL_APP_NAME"
  443. exit 1
  444. ;;
  445. esac