Skip to content

Commit

Permalink
Fix e improve --launcher option and related functions (#1139)
Browse files Browse the repository at this point in the history
* Option --launcher, fix missing BINDIR message

* Add /run/media support to -c in AppImage launchers removal

* Option -c, launchers, don't remove dead links if mountpoint is detected

* Use one function to clean launchers (option -c)

* Update APP-MANAGER
  • Loading branch information
ivan-hc authored Nov 18, 2024
1 parent 1b3b82f commit 1a97b59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
52 changes: 28 additions & 24 deletions APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="9.1.1-4"
AMVERSION="9.1.1-6"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down Expand Up @@ -612,34 +612,38 @@ function _clean_all_tmp_directories_from_appspath() {
done
}

function _clean_determine_removable_launchers() {
if ! test -f "$APPIMAGENAME" 2>/dev/null; then
if ! test -d "$MOUNTPOINTS" 2>/dev/null; then
if echo "$MOUNTPOINTS" | grep -q "/media/"; then
unmounted_poin="/media"
elif echo "$MOUNTPOINTS" | grep -q "/mnt/"; then
unmounted_poin="/mnt"
fi
echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
echo " related AppImage is located in an unmounted path of $unmounted_poin"
else
rm -f "$var"
rm -f "$HOME"/.local/bin/"$launcher2del"*
cd "$HOME"/.local/bin && find . -xtype l -delete
fi
fi
}

function _clean_launchers() {
if test -d "$DATADIR"/applications/AppImages 2>/dev/null; then
if test -d "$DATADIR"/applications/AppImages; then
for var in "$DATADIR"/applications/AppImages/*.desktop; do
APPIMAGENAME=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/\s.*$//')
launcher2del=$(basename -- "$(echo "$APPIMAGENAME" | tr '[:upper:]' '[:lower:]')")
MOUNTPOINTS=$(echo "$APPIMAGENAME" | cut -d'/' -f1-4)
_clean_determine_removable_launchers
# full path to appimage
appimagename=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/\s.*$//')
# name of the appimage
launcher2del=$(basename -- "$(echo "$appimagename" | tr '[:upper:]' '[:lower:]')")
# removable mount point where the appimage may be stored
mountpoint=$(echo "$appimagename" | cut -d'/' -f1-4)
if ! test -f "$appimagename"; then
if echo "$mountpoint" | grep -q "^/media/\|^/mnt/\|^/run/media/" && ! test -d "$mountpoint"; then
if echo "$mountpoint" | grep -q "^/media/"; then
unmounted_point="/media"
elif echo "$mountpoint" | grep -q "^/mnt/"; then
unmounted_point="/mnt"
elif echo "$mountpoint" | grep -q "^/run/media/"; then
unmounted_point="/run/media"
fi
echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
echo " related AppImage is located in an unmounted path of $unmounted_point"
else
rm -f "$var"
rm -f "$HOME"/.local/bin/"$launcher2del"*
fi
fi
done
grep -q "^Exec=/media/\|^^Exec=/mnt/\|^^Exec=/run/media/" "$DATADIR"/applications/AppImages/* && mountpoint_enabled=1
[ -z "$mountpoint_enabled" ] && cd "$HOME"/.local/bin && find . -xtype l -delete
echo ' ✔ Removed orphaned launchers produced with the "--launcher" option'
rmdir "$DATADIR"/applications/AppImages
else
cd "$HOME"/.local/bin && find . -xtype l -delete
fi
}

Expand Down
6 changes: 5 additions & 1 deletion modules/management.am
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ function _launcher_appimage_integration() {

function _launcher_appimage_bin() {
mkdir -p "$HOME"/.local/bin
_check_if_home_local_bin_is_not_in_path
if ! echo "$PATH" | grep "$BINDIR" >/dev/null 2>&1; then
echo "$DIVIDING_LINE"
echo "WARNING: \"$BINDIR\" is not in PATH, apps may not run from command line." | fold -sw 77 | sed 's/^/ /g'
echo "$DIVIDING_LINE"
fi
read -r -p " Write a custom command to launch the app, or leave blank: " response
if [ -z "$response" ]; then
appimage_cmd=$(echo "$appimage" | tr '[:upper:]' '[:lower:]')
Expand Down

0 comments on commit 1a97b59

Please sign in to comment.