management.am 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #!/usr/bin/env bash
  2. ##############################################################################################
  3. # THIS MODULE INCLUDES ALL THE ACTIONS INTENDED TO MANAGE THE APPS INSTALLED FROM THE DATABASE
  4. # AND ONE OPTION IS FOR LOCAL APPIMAGES INSTEAD
  5. # OPTIONS: BACKUP/RESTORE, CONFIG/HOME, DOWNGRADE, LAUNCHER, LOCK/UNLOCK, NOLIBFUSE, REMOVE
  6. ##############################################################################################
  7. ################################################################################################################################################################
  8. # BACKUP
  9. ################################################################################################################################################################
  10. _backup_name() {
  11. printf "\n ◆ To set date and time as a name, press ENTER (default)\n ◆ To set the version as a name, press \"1\"\n ◆ To set a custom name, write anything else\n\n"
  12. read -r -p " Write your choice here, or leave blank to use \"date/time\": " response
  13. case "$response" in
  14. '')
  15. backupname=$(date +%F-%X | sed 's/://g' | sed 's/-//g')
  16. ;;
  17. '1')
  18. _check_version
  19. backupname=$(grep -w " ◆ $app_name |" "$AMCACHEDIR"/version-args 2>/dev/null | sed 's:.*| ::')
  20. ;;
  21. *)
  22. backupname="$(echo "$response" | sed 's/ /_/g')"
  23. ;;
  24. esac
  25. }
  26. _backup() {
  27. if [ ! -f "$argpath"/remove ]; then
  28. echo " \"$2\" is not a valid argument or is not installed."
  29. else
  30. read -r -p " Do you wish to backup the current version of $2? (y/N) " yn
  31. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  32. printf "\n OPERATION ABORTED!\n\n"
  33. else
  34. mkdir -p "$HOME/.am-snapshots/$2"
  35. app_name="$2"
  36. _backup_name
  37. if test -d "$HOME/.am-snapshots/$2/$backupname"; then
  38. echo " 💀 ERROR: \"$2/$backupname\" already exists, ABORTED!"
  39. echo "$DIVIDING_LINE"
  40. return 1
  41. else
  42. cp -r "$argpath" "$HOME/.am-snapshots/$2/$backupname"
  43. fi
  44. echo " SAVED in $HOME/.am-snapshots/$2/$backupname"
  45. fi
  46. fi
  47. echo "$DIVIDING_LINE"
  48. }
  49. ################################################################################################################################################################
  50. # RESTORE
  51. ################################################################################################################################################################
  52. _overwrite() {
  53. if [ ! -d "$HOME/.am-snapshots/$2" ]; then
  54. echo " ERROR: No snapshot for \"$2\" found."
  55. elif [ ! -f "$argpath"/remove ]; then
  56. echo " \"$2\" is not a valid argument or is not installed."
  57. else
  58. read -r -p " Do you wish to overwrite $2 with an older version? (y,N) " yn
  59. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  60. printf "\n OPERATION ABORTED! \n\n"
  61. else
  62. printf "\n Please, select a snapshot or press ZERO to abort:\n\n"
  63. sleep 1
  64. select d in "$HOME/.am-snapshots/$2"/*; do
  65. if [ -n "$d" ]; then
  66. break
  67. else
  68. printf "\n Invalid selection. ABORTED! \n"
  69. return 1
  70. fi
  71. done
  72. cp -r --backup=t "$d"/* "$argpath"/
  73. rm -R -f ./tmp "$argpath"/*~
  74. echo " RESTORE COMPLETED SUCCESSFULLY!"
  75. fi
  76. fi
  77. echo "$DIVIDING_LINE"
  78. }
  79. ################################################################################################################################################################
  80. # CONFIG/HOME
  81. ################################################################################################################################################################
  82. _isolate_appimage() {
  83. _determine_args
  84. if [ -z "$argpath" ]; then
  85. printf " ✖ ERROR: \"%b\" is not installed\n" "$arg"
  86. elif [ -f "$argpath"/"$arg" ] && ! head -c10 "$argpath"/"$arg" 2>/dev/null | grep -qa '^.ELF....AI$'; then
  87. printf " ✖ ERROR: \"%b\" is NOT an AppImage\n" "$arg"
  88. else
  89. if echo "$1" | grep -q -- "C\|config$"; then
  90. if [ -d "$argpath"/"$arg".config ]; then
  91. echo "✖ ERROR: \"$arg\" already contains a config dir" | _fit
  92. else
  93. mkdir "$argpath"/"$arg".config || return 1
  94. echo "✔ \$XDG_CONFIG_HOME set to \"$argpath.config\" for \"$arg\"" | _fit
  95. fi
  96. fi
  97. if echo "$1" | grep -q -- "H\|home$"; then
  98. if [ -d "$argpath"/"$arg".home ]; then
  99. echo "✖ ERROR: \"$arg\" already contains a home dir" | _fit
  100. else
  101. mkdir "$argpath"/"$arg".home || return 1
  102. echo "✔ \$HOME set to \"$argpath.home\" for \"$arg\"" | _fit
  103. fi
  104. fi
  105. fi
  106. }
  107. ################################################################################################################################################################
  108. # DOWNGRADE
  109. ################################################################################################################################################################
  110. _downgrade_entries_filter() {
  111. grep -vi "^#\|version0=" ./AM-updater | grep "api.github.com" \
  112. | tr '=' '\n' | sed 's/^\$(//g' \
  113. | tail -1 | sed '1,${
  114. s/version=$(//g
  115. s/head -1)/head -100/g
  116. s/tail -1)/head -100/g
  117. s#$REPO#'"$REPO"'#g
  118. s#releases/latest#releases#g
  119. s#releases #releases?per_page=100 #g
  120. s#/$tag/$app##g
  121. }'
  122. }
  123. _downgrade() {
  124. # Safety checks
  125. if [ ! -f "$argpath"/AM-updater ]; then
  126. echo " No AM-updater available for \"$2\", cannot detect any URL!"
  127. return 1
  128. elif [ -f "$argpath"/"$2"-rollback ]; then
  129. cd "$argpath" || return 1
  130. ./"$2"-rollback || return 1
  131. return 0
  132. elif ! grep -q "api.github.com" "$argpath"/AM-updater; then
  133. echo " The option \"$1\" only works for https://github.com"
  134. return 1
  135. fi
  136. cd "$argpath" || return 1
  137. entries_list=$(_downgrade_entries_filter)
  138. urls="$(eval "$entries_list" 2>/dev/null | grep -vi "zsync$")"
  139. if ! echo "$urls" | grep -q "[0-9]"; then
  140. echo " ERROR: No valid links found, sorry!"
  141. exit 1
  142. fi
  143. echo "$DIVIDING_LINE"
  144. echo "You have chosen to roll back \"$2\"."
  145. echo "$DIVIDING_LINE"
  146. echo "Select a URL from this menu (read carefully) or press ZERO to abort:"
  147. echo "$DIVIDING_LINE"
  148. sleep 1
  149. select d in $urls; do
  150. if [ -n "$d" ]; then
  151. break
  152. else
  153. printf "\n Invalid selection. ABORTED! \n"
  154. return 1
  155. fi
  156. done
  157. cp ./AM-updater ./AM-rollback
  158. sed -i 's/version0/#version0/g' ./AM-rollback
  159. sed -i 's/appimageupdatetool -Or/#appimageupdatetool -Or/g' ./AM-rollback
  160. [ -f ./"$2".zsync ] && mv ./"$2".zsync ./"$2".zsync.old
  161. if wget --version | head -1 | grep -q ' 1.'; then
  162. sed -i '/wget/c\wget -q --show-progress '"$d"'' ./AM-rollback
  163. else
  164. sed -i '/wget/c\wget '"$d"'' ./AM-rollback
  165. fi
  166. ./AM-rollback && rm -f ./AM-rollback || return 1
  167. mv ./"$2".zsync.old ./"$2".zsync 2>/dev/null
  168. echo "$d" > ./version
  169. echo "ROLLBACK SUCCESSFUL!"
  170. }
  171. ################################################################################################################################################################
  172. # ICON THEME CHANGER
  173. ################################################################################################################################################################
  174. _icon_theme() {
  175. if [ "$AMCLI" = am ] && test -f /usr/local/share/applications/"$arg"*AM.desktop; then
  176. $SUDOCMD sed -i "s#Icon=$argpath/icons/#Icon=#g" /usr/local/share/applications/"$arg"*AM.desktop 2>/dev/null
  177. else
  178. sed -i "s#Icon=$argpath/icons/#Icon=#g" "$DATADIR"/applications/"$arg"*AM.desktop 2>/dev/null
  179. fi
  180. _icon_theme_export_to_datadir 2>/dev/null
  181. }
  182. ################################################################################################################################################################
  183. # LAUNCHER
  184. ################################################################################################################################################################
  185. _launcher_appimage_integration() {
  186. if grep -Eaoq -m 1 "appimage-extract" "$arg"; then
  187. "$arg" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$appimage".desktop
  188. "$arg" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
  189. COUNT=0
  190. while [ "$COUNT" -lt 10 ]; do # Tries to get the actual icon/desktop if it is a symlink to another symlink
  191. if [ -L ./"$appimage".desktop ]; then
  192. LINKPATH="$(readlink ./"$appimage".desktop | sed 's|^\./||' 2>/dev/null)"
  193. "$arg" --appimage-extract "$LINKPATH" 1>/dev/null && mv ./squashfs-root/"$LINKPATH" ./"$appimage".desktop
  194. fi
  195. if [ -L ./DirIcon ]; then
  196. LINKPATH="$(readlink ./DirIcon | sed 's|^\./||' 2>/dev/null)"
  197. "$arg" --appimage-extract "$LINKPATH" 1>/dev/null && mv ./squashfs-root/"$LINKPATH" "$DATADIR"/icons/ 1>/dev/null
  198. fi
  199. [ ! -L ./"$appimage".desktop ] && [ ! -L ./DirIcon ] && break
  200. COUNT=$((COUNT + 1))
  201. done
  202. elif command -v 7z >/dev/null 2>&1; then
  203. 7z x -osquashfs-root "$arg" 1>/dev/null
  204. mv ./squashfs-root/*.desktop ./"$appimage".desktop
  205. mv ./squashfs-root/.DirIcon ./DirIcon || test -f ./squashfs-root/*.png && mv ./squashfs-root/*.png ./DirIcon || test -f ./squashfs-root/*.svg && mv ./squashfs-root/*.svg ./DirIcon
  206. COUNT=0
  207. while [ "$COUNT" -lt 10 ]; do
  208. if [ -L ./"$appimage".desktop ]; then
  209. LINKPATH="$(readlink ./"$appimage".desktop | sed 's|^\./||' 2>/dev/null)"
  210. mv ./squashfs-root/"$LINKPATH" ./"$appimage".desktop
  211. fi
  212. if [ -L ./DirIcon ]; then
  213. LINKPATH="$(readlink ./DirIcon | sed 's|^\./||' 2>/dev/null)"
  214. mv ./squashfs-root/"$LINKPATH" ./DirIcon 1>/dev/null
  215. fi
  216. [ ! -L ./"$appimage".desktop ] && [ ! -L ./DirIcon ] && break
  217. COUNT=$((COUNT + 1))
  218. done
  219. icon_name=$(grep "^Icon=" ./"$appimage".desktop | head -1 | sed 's/^Icon=//g')
  220. sed -i 's/.svg$//g; s/.png$//g' ./"$appimage".desktop
  221. mv ./DirIcon "$DATADIR"/icons/"$icon_name" 1>/dev/null
  222. else
  223. echo "WARNING: cannot extract old type 1 AppImages, install \"7z\" and retry." | _fit
  224. fi
  225. if [ -d ./squashfs-root ]; then
  226. sed -i "s#Exec=[^ ]*#Exec=\"$arg\"#g" ./"$appimage".desktop
  227. mv ./"$appimage".desktop "$DATADIR"/applications/AppImages/"$appimage"-AM.desktop
  228. fi
  229. }
  230. _launcher_appimage_bin() {
  231. rm -R -f ./squashfs-root ./DirIcon
  232. mkdir -p "$BINDIR"
  233. if ! echo "$PATH" | grep "$BINDIR" >/dev/null 2>&1; then
  234. echo "$DIVIDING_LINE"
  235. echo "WARNING: \"$BINDIR\" is not in PATH, apps may not run from command line." | _fit
  236. echo "$DIVIDING_LINE"
  237. fi
  238. read -r -p " Write a custom command to launch the app, or leave blank: " response
  239. if [ -z "$response" ]; then
  240. appimage_cmd=$(echo "$appimage" | tr '[:upper:]' '[:lower:]')
  241. if ! echo "$appimage" | grep -q -i ".appimage"; then
  242. [ -n "$BINDIR" ] && printf '#!/bin/sh\n%s' "$arg" >> "$BINDIR"/"$appimage_cmd".appimage \
  243. && chmod a+x "$BINDIR"/"$appimage_cmd".appimage && echo "New command: \"$appimage_cmd.appimage\" in $BINDIR" | _fit
  244. else
  245. [ -n "$BINDIR" ] && printf '#!/bin/sh\n%s' "$arg" >> "$BINDIR"/"$appimage_cmd" \
  246. && chmod a+x "$BINDIR"/"$appimage_cmd" && echo "New command: \"$appimage_cmd\" in $BINDIR" | _fit
  247. fi
  248. elif command -v "$response" 1>/dev/null; then
  249. if test -f "$BINDIR"/"$response"; then
  250. echo "WARNING, \"$BINDIR/$response\" already exists!" | _fit
  251. read -r -p " Do you Want to override it? (y,N) " yn
  252. if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  253. ln -sf "$arg" "$BINDIR"/"$response"
  254. else
  255. echo " You have chosen not to assign a command."
  256. fi
  257. else
  258. echo "ERROR: the \"$response\" command alredy exists, retry!" | _fit
  259. fi
  260. else
  261. [ -n "$BINDIR" ] && ln -sf "$arg" "$BINDIR"/"$response"
  262. fi
  263. }
  264. _launcher(){
  265. _clean_launchers 2>/dev/null 1>/dev/null
  266. if [ ! -f "$arg" ]; then
  267. printf "%b\n ERROR: \"%b\" not found\n%b\n" "$DIVIDING_LINE" "$arg" "$DIVIDING_LINE" | _fit
  268. elif ! head -c10 "$arg" 2>/dev/null | grep -qa '^.ELF....AI$' 2>/dev/null; then
  269. printf "%b\n ERROR: \"%b\" is NOT an AppImage\n%b\n" "$DIVIDING_LINE" "$arg" "$DIVIDING_LINE" | _fit
  270. else
  271. printf " ◆ File: %s\n" "$arg"
  272. appimage=$(basename -- "$arg")
  273. mkdir -p "$DATADIR"/applications/AppImages
  274. mkdir -p "$DATADIR"/icons
  275. chmod a+x "$arg"
  276. cd "$(dirname "$arg")" || return
  277. _launcher_appimage_integration 2>/dev/null
  278. [ -d ./squashfs-root ] && _launcher_appimage_bin
  279. fi
  280. }
  281. ################################################################################################################################################################
  282. # LOCK/UNLOCK
  283. ################################################################################################################################################################
  284. _lock() {
  285. if [ ! -f "$argpath"/AM-updater ]; then
  286. echo " \"$AMCLIUPPER\" cannot manage updates for $2, \"AM-updater\" file not found!"
  287. return 1
  288. fi
  289. read -r -p " Do you wish to keep $2 at its current version? (y/N) " yn
  290. if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  291. mv "$argpath"/AM-updater "$argpath"/AM-LOCK 1>/dev/null
  292. echo " $2 has been locked at current version!"
  293. else
  294. echo " Operation aborted!"
  295. return 1
  296. fi
  297. }
  298. _unlock() {
  299. if ! test -f "$argpath"/AM-LOCK; then
  300. echo " \"$2\" cannot be unlocked, \"AM-LOCK\" file not found!"
  301. return 1
  302. fi
  303. read -r -p " Do you wish to unlock updates for $2? (Y/n) " yn
  304. if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
  305. echo " $2 is still locked at current version!"
  306. return 1
  307. else
  308. mv "$argpath"/AM-LOCK "$argpath"/AM-updater 1>/dev/null
  309. echo " \"$2\" can now receive updates!"
  310. fi
  311. }
  312. ################################################################################################################################################################
  313. # NO LIBFUSE
  314. ################################################################################################################################################################
  315. _nolibfuse() {
  316. AMCLIPATH_ORIGIN="$AMCLIPATH"
  317. target="$(echo "${2}" | tr '[:lower:]' '[:upper:]')"
  318. echo "$DIVIDING_LINE"
  319. # safety checks
  320. if [ ! -d "$argpath" ]; then
  321. printf " 💀Error, \"%b\" is NOT installed\n" "$target"
  322. return 1
  323. else
  324. cd "$argpath" || return 1
  325. fi
  326. if ! head -c10 ./"$arg" 2>/dev/null | grep -qa '^.ELF....AI$' 2>/dev/null; then
  327. printf " 💀Error, \"%b\" is NOT an AppImage\n" "$target"
  328. return 1
  329. elif file "$arg" 2>/dev/null | grep -qi "static"; then
  330. printf " ◆ \"%b\" is already a new generation AppImage.\n" "$target"
  331. return 1
  332. elif test -f ./*.zsync; then
  333. echo " Warning! Your AppImage uses \"zsync\" to update."
  334. echo " The .zsync file will be removed and will no longer work"
  335. echo " your \"AM-updater\" will likely still be able to update the AppImage"
  336. echo " by comparing the old vs new version url, but it is not guaranteed"
  337. read -r -p " Do you want to proceede anyway? (N/y) " yn
  338. if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  339. return 1
  340. fi
  341. fi
  342. # If appimagetool is not installed, download it
  343. if ! command -v appimagetool 1>/dev/null; then
  344. _online_check
  345. printf " ...downloading appimagetool\r"
  346. wget -q "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$ARCH.AppImage" -O ./appimagetool || return 1
  347. chmod a+x ./appimagetool
  348. fi
  349. # Extract the AppImage
  350. printf " ...extracting the AppImage\r"
  351. if grep -Eaoq -m 1 "appimage-extract" "$2"; then
  352. ./"$2" --appimage-extract >/dev/null 2>&1 && chmod 0755 ./squashfs-root
  353. #elif command -v 7z >/dev/null 2>&1; then
  354. # 7z x -osquashfs-root "$arg" 1>/dev/null && chmod 0755 ./squashfs-root
  355. # sed -i 's/.svg$//g; s/.png$//g' ./squashfs-root/*.desktop
  356. # find ./squashfs-root -type f -exec chmod +x {} \;
  357. # wait
  358. #else
  359. # echo "WARNING: cannot extract old type 1 AppImages, install \"7z\" and retry." | _fit
  360. fi
  361. # Convert the AppImage to a new generation one
  362. printf " ...trying to convert in new generation AppImage\r"
  363. if [ -f ./appimagetool ]; then
  364. PATH="$PATH:$PWD" ARCH="$(uname -m)" ./appimagetool -n ./squashfs-root >/dev/null 2>&1
  365. elif command -v appimagetool 1>/dev/null; then
  366. ARCH="$(uname -m)" appimagetool -n ./squashfs-root >/dev/null 2>&1
  367. fi
  368. # Test if the AppImage has been created
  369. if ! test -f ./*.AppImage; then
  370. echo " 💀Error when trying to convert $target. Operation Aborted."
  371. rm -Rf ./appimagetool ./squashfs-root
  372. return 1
  373. fi
  374. mv ./"$2" ./"$2".old && mv ./*.AppImage ./"$2" || return 1
  375. echo " ◆ $target has been converted to a new generation AppImage."
  376. rm -Rf ./appimagetool ./squashfs-root ./*.zsync
  377. if [ -f ./AM-updater ] && ! grep -q 'nolibfuse' ./AM-updater; then
  378. sed -i "s/^else/ echo y | $AMCLIPATH_ORIGIN nolibfuse \"\$APP\"\n notify-send \"\$APP has been converted too\!\"\nelse/g" ./AM-updater 2>/dev/null
  379. echo " The next update may replace this AppImage with a Type2 one"
  380. echo " so I added this command to the bottom of the \"AM-updater\" script!"
  381. fi
  382. echo " Contact the upstream developers to make them officially upgrade!"
  383. read -r -p " Do you wish to remove the old libfuse2 AppImage? (Y/n) " yn
  384. if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
  385. return 1
  386. else
  387. rm -f ./*.old
  388. fi
  389. }
  390. ################################################################################################################################################################
  391. # REMOVE
  392. ################################################################################################################################################################
  393. _detect_path_to_remove() {
  394. if [ -f "$APPMAN_APPSPATH"/"$arg"/remove ]; then
  395. RMPATH="1"
  396. elif [ -f "$APPSPATH"/"$arg"/remove ]; then
  397. [ -w "$APPSPATH"/"$arg" ] && $SUDOCMD echo -e "\r" >/dev/null
  398. RMPATH="1"
  399. else
  400. RMPATH=""
  401. fi
  402. echo "$DIVIDING_LINE"
  403. }
  404. _remove() {
  405. [ "$AMCLI" = am ] && _detect_appman_apps
  406. _detect_path_to_remove
  407. [ -z "$RMPATH" ] && echo -e " \"${RED}$arg\033[0m\" is not a valid \"APPNAME\", see \"$AMCLI -f\" for more." && return 1
  408. read -r -p " ◆ Do you wish to remove \"$arg\"? (Y/n) " yn
  409. if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
  410. echo -e " \"${LightBlue}$arg\033[0m\" has not been removed!"
  411. else
  412. [ "$AMCLI" = am ] && "$APPMAN_APPSPATH"/"$arg"/remove 2>/dev/null || $SUDOCMD "$APPSPATH"/"$arg"/remove 2>/dev/null || return 1
  413. _clean_amcachedir
  414. sleep 0.1
  415. echo -e " \"${Green}$arg\033[0m\" has been removed!"
  416. fi
  417. [ -d "$DATADIR"/icons/hicolor/scalable/apps ] && find "$DATADIR"/icons/hicolor/scalable/apps -xtype l -exec rm {} \;
  418. }
  419. _hard_remove() {
  420. [ "$AMCLI" = am ] && _detect_appman_apps
  421. _detect_path_to_remove
  422. [ -z "$RMPATH" ] && echo -e " \"${RED}$arg\033[0m\" is not a valid \"APPNAME\", see \"$AMCLI -f\" for more." && return 1
  423. [ "$AMCLI" = am ] && "$APPMAN_APPSPATH"/"$arg"/remove 2>/dev/null || $SUDOCMD "$APPSPATH"/"$arg"/remove 2>/dev/null || return 1
  424. _clean_amcachedir
  425. sleep 0.1
  426. echo -e " \"${Green}$arg\033[0m\" has been removed!"
  427. [ -d "$DATADIR"/icons/hicolor/scalable/apps ] && find "$DATADIR"/icons/hicolor/scalable/apps -xtype l -exec rm {} \;
  428. }
  429. ################################################################################################################################################################
  430. # USAGE
  431. ################################################################################################################################################################
  432. # Main logic
  433. [ -z "$2" ] && echo " USAGE: $AMCLI $1 [ARGUMENT]" && exit 1
  434. case "$1" in
  435. 'backup'|'-b')
  436. # Do a snapshot of an installed app
  437. _determine_args
  438. entries="$(echo "$@" | cut -f2- -d ' ')"
  439. for arg in $entries; do
  440. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  441. _backup "${@}"
  442. shift
  443. done
  444. ;;
  445. 'config'|'-C'|'--config'|'home'|'-H'|'--home'|'-HC'|'-CH'|'HC'|'CH')
  446. # Set dedicated $HOME and $XDG_CONFIG_HOME directories for one or more AppImages.
  447. _determine_args
  448. echo "$DIVIDING_LINE"
  449. entries="$(echo "$@" | cut -f2- -d ' ')"
  450. for arg in $entries; do
  451. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  452. _isolate_appimage "${@}"
  453. echo "$DIVIDING_LINE"
  454. argpath=""
  455. done
  456. ;;
  457. 'downgrade'|'--rollback')
  458. # Downgrade the installed app to a previous version, from its online source
  459. _online_check
  460. _determine_args
  461. entries="$(echo "$@" | cut -f2- -d ' ')"
  462. for arg in $entries; do
  463. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  464. _downgrade "${@}"
  465. _clean_amcachedir
  466. _update_list_updatable_apps
  467. shift
  468. done
  469. ;;
  470. 'icons'|'--icons')
  471. # Place local AppImages into the menu by dragging and dropping them into the terminal
  472. _determine_args
  473. if [ "$2" = "--all" ]; then
  474. entries="$ARGS"
  475. read -r -p " ◆ Do you wish to allow custom icon theming for ALL the apps? (y,N) " yn
  476. else
  477. entries="$(echo "$@" | cut -f2- -d ' ')"
  478. read -r -p " ◆ Do you wish to allow custom icon theming for the selected apps? (y,N) " yn
  479. fi
  480. if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
  481. for arg in $entries; do
  482. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  483. _icon_theme "${@}"
  484. done
  485. echo " ✔ Success!"
  486. else
  487. echo " ✖ Aborted!"
  488. fi
  489. ;;
  490. 'launcher'|'--launcher')
  491. # Place local AppImages into the menu by dragging and dropping them into the terminal
  492. entries="$(echo "$@" | cut -f2- -d ' ')"
  493. if [ "$2" = "-u" ] || [ "$2" = "-U" ] || [ "$2" = "update" ]; then
  494. entries="$(echo "$@" | cut -f3- -d ' ')"
  495. echo "$DIVIDING_LINE"
  496. _update_launchers
  497. printf "%b\n ◆ Updates check finished! \n" "$DIVIDING_LINE"
  498. fi
  499. for arg in $entries; do
  500. echo "$DIVIDING_LINE"
  501. _launcher "${@}"
  502. done
  503. echo "$DIVIDING_LINE"
  504. ;;
  505. 'lock')
  506. # Lock the version of an installed app
  507. _determine_args
  508. entries="$(echo "$@" | cut -f2- -d ' ')"
  509. for arg in $entries; do
  510. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  511. _lock "${@}"
  512. shift
  513. done
  514. ;;
  515. 'unlock')
  516. # Unlock the version of an installed app
  517. _determine_args
  518. entries="$(echo "$@" | cut -f2- -d ' ')"
  519. for arg in $entries; do
  520. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  521. _unlock "${@}"
  522. shift
  523. done
  524. ;;
  525. 'nolibfuse')
  526. # Convert old AppImages to a new standard and get rid of libfuse2 dependency
  527. _determine_args
  528. entries="$(echo "$@" | cut -f2- -d ' ')"
  529. for arg in $entries; do
  530. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  531. _nolibfuse "${@}"
  532. _remove_info_files
  533. shift
  534. done
  535. echo "$DIVIDING_LINE"
  536. ;;
  537. 'overwrite'|'-o')
  538. # Restore an app to a previous version using a snapshot (see "backup" or "-b", above)
  539. _determine_args
  540. entries="$(echo "$@" | cut -f2- -d ' ')"
  541. for arg in $entries; do
  542. argpath=$(echo "$ARGPATHS" | grep "/$arg$")
  543. _overwrite "${@}"
  544. _remove_info_files
  545. shift
  546. done
  547. ;;
  548. 'remove'|'-r')
  549. # Remove apps
  550. entries="$(echo "$@" | cut -f2- -d ' ')"
  551. for arg in $entries; do
  552. _remove "${@}"
  553. _remove_info_files
  554. shift
  555. done
  556. echo "$DIVIDING_LINE"
  557. ;;
  558. '-R')
  559. # Remove apps without confirmation
  560. entries="$(echo "$@" | cut -f2- -d ' ')"
  561. for arg in $entries; do
  562. _hard_remove "${@}"
  563. _remove_info_files
  564. shift
  565. done
  566. echo "$DIVIDING_LINE"
  567. ;;
  568. esac