install.am 22 KB

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