Skip to content

Commit

Permalink
"AM" 9.2, improve support to local AppImages giving them updates supp…
Browse files Browse the repository at this point in the history
…ort (appimageupdatetool) and a dedicated table in `-f` (#1172)

* Option -f, show also AppImages integrated using "--launcher"

* Option --launcher, give appimageupdatetool support to AppImages integrated with "--laungher"

* Option `--launcher`, if the command already exists in $BINDIR, choose whether to overwrite

* Option `-c`, cleaning launchers, new method to detect mountpoints and test if its possible to remove dead symlinks / fix cleaning launchers by detecting the correct desktop entry

* Fix symlink creation when broken symlink is in $BINDIR when installing programs
  • Loading branch information
ivan-hc authored Dec 1, 2024
1 parent 101b71c commit f5a1ced
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 45 deletions.
114 changes: 91 additions & 23 deletions APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="9.1.3"
AMVERSION="9.2"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down Expand Up @@ -50,6 +50,11 @@ function _clean_amcachedir() {
[ -d "$CACHEDIR"/appman ] && rm -f "$CACHEDIR"/appman/*
}

# Fit texts to an acceptable width
function _fit() {
fold -sw 77 | sed 's/^/ /g'
}

################################################################################
# AM/APPMAN
################################################################################
Expand All @@ -70,7 +75,7 @@ function _appman_check() {
echo "$DIVIDING_LINE"
[ "$AMCLI" = am ] && echo ">>> Configure AppMan" || echo ">>> Thank you for choosing AppMan!"
echo "$DIVIDING_LINE"
echo "$APPMAN_SETUP_MSG" | fold -sw 77 | sed 's/^/ /g'
echo "$APPMAN_SETUP_MSG" | _fit
echo "$DIVIDING_LINE"
read -r -ep " Write the path or just press enter to use default:$(printf "\n\n ")" location
location="$(echo "$location" | sed 's/[ \t]/-/g; s|^\./||' 2>/dev/null)"
Expand Down Expand Up @@ -282,10 +287,10 @@ function _blacklisted_file() {
echo ""
echo -e " ${RED}💀WARNING! Detected \"$blacklisted_file\"\033[0m"
echo ""
echo "It will prevent \"$AMCLIUPPER\" from working correctly with AppImages, especially when extracting, integrating and updating them." | fold -sw 77 | sed 's/^/ /g'
echo "It will prevent \"$AMCLIUPPER\" from working correctly with AppImages, especially when extracting, integrating and updating them." | _fit
echo ""
if echo "$blacklisted_file" | grep -q appimagelauncherd; then
echo "$appimagelauncher_msg" | fold -sw 77 | sed 's/^/ /g'
echo "$appimagelauncher_msg" | _fit
echo "" && echo " Please remove \"AppImageLauncher\", reboot and retry!"
else
echo " Please remove \"$blacklisted_file\", reboot and retry!"
Expand Down Expand Up @@ -565,7 +570,7 @@ APPMAN_MSG_THINK="$DIVIDING_LINE\nNOTE: You can also choose to simply use \"--us
function _use_appman() {
_online_check
[ "$CLI" = appman ] && echo " This function only works for AM" && exit 0
echo -e "$APPMAN_MSG_THINK" | fold -sw 77 | sed 's/^/ /g'
echo -e "$APPMAN_MSG_THINK" | _fit
read -r -p " Do you wish to enter \"AppMan Mode\" (y,N)?" yn
if ! echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
echo "$DIVIDING_LINE"
Expand Down Expand Up @@ -620,9 +625,10 @@ function _clean_all_tmp_directories_from_appspath() {

function _clean_launchers() {
if test -d "$DATADIR"/applications/AppImages; then
rm -f "$AMCACHEDIR"/mountpoints
for var in "$DATADIR"/applications/AppImages/*.desktop; do
# full path to appimage
appimagename=$(grep "Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/"//g; s/\s.*$//')
appimagename=$(grep "^Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/"//g; s/\s.*$//')
# name of the appimage
launcher2del=$(basename -- "$(echo "$appimagename" | tr '[:upper:]' '[:lower:]')")
# removable mount point where the appimage may be stored
Expand All @@ -638,6 +644,7 @@ function _clean_launchers() {
mountpoint=""
fi
if [ -n "$mountpoint" ] && ! test -d "$mountpoint"; then
echo "$mountpoint" >> "$AMCACHEDIR"/mountpoints
echo " ✖ ERROR: cannot remove \"$(basename "$var")\""
echo " related AppImage is located in an unmounted path of $unmounted_point"
else
Expand All @@ -646,8 +653,14 @@ function _clean_launchers() {
fi
fi
done
grep -q "^Exec=/media/\|^Exec=/mnt/\|^Exec=/run/media/\|^Exec=\"/media/\|^Exec=\"/mnt/\|^Exec=\"/run/media/" "$DATADIR"/applications/AppImages/* && mountpoint_enabled=1
if test -f "$AMCACHEDIR"/mountpoints; then
mountpoints=$(sort "$AMCACHEDIR"/mountpoints)
for m in $mountpoints; do
[ ! -d "$m" ] && mountpoint_enabled=1
done
fi
[ -z "$mountpoint_enabled" ] && [ -n "$BINDIR" ] && cd "$BINDIR" && find . -xtype l -delete
rm -f "$AMCACHEDIR"/mountpoints
echo ' ✔ Removed orphaned launchers produced with the "--launcher" option'
rmdir "$DATADIR"/applications/AppImages
else
Expand Down Expand Up @@ -805,6 +818,13 @@ function _use_sync() {
# UPDATE
################################################################################

function _update_updatable_apps_msg_head() {
printf " \"%b\" CAN MANAGE UPDATES FOR THE FOLLOWING PROGRAMS:\n%b\n\n" "$AMCLIUPPER" "$DIVIDING_LINE"
[ -f "$AMCACHEDIR/updatable-args-list" ] && grep "" "$AMCACHEDIR/updatable-args-list" | sort || echo " None"
printf "\n All self-updatable programs are excluded\n"
echo "$DIVIDING_LINE"
}

function _update_list_updatable_apps() {
_determine_args
_check_version
Expand Down Expand Up @@ -843,16 +863,28 @@ function _update_run_updater() {
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)
if [ -z "$GH_API_ALLOWED" ]; then
if command -v torsocks 1>/dev/null; then
[ -z "$debug_update" ] && torsocks "$argpath"/AM-updater >/dev/null 2>&1 || torsocks "$argpath"/AM-updater
if [ -z "$debug_update" ]; then
torsocks "$argpath"/AM-updater >/dev/null 2>&1
else
torsocks "$argpath"/AM-updater
fi
else
echo "$APPNAME cannot be updated, you have reached GitHub API limit. Install \"torsocks\" from your system package manager and retry!" \
| fold -sw 72 | sed 's/^/ /g; s/ ✖/✖/g'
fi
else
[ -z "$debug_update" ] && "$argpath"/AM-updater >/dev/null 2>&1 || "$argpath"/AM-updater
if [ -z "$debug_update" ]; then
"$argpath"/AM-updater >/dev/null 2>&1
else
"$argpath"/AM-updater
fi
fi
else
[ -z "$debug_update" ] && "$argpath"/AM-updater >/dev/null 2>&1 || "$argpath"/AM-updater
if [ -z "$debug_update" ]; then
"$argpath"/AM-updater >/dev/null 2>&1
else
"$argpath"/AM-updater
fi
fi
end=$(date +%s)
echo "$APPNAME is updated, $((end - start)) seconds elapsed!"
Expand Down Expand Up @@ -884,6 +916,36 @@ function _update_all_apps() {
[ -d "$APPMAN_APPSPATH" ] && rm -Rf "$APPMAN_APPSPATH"/*/tmp
}

function _update_launchers_not_found_msg() {
MISSING_LAUNCHERS_MSG=" No launcher found."
printf "%b\n%b\n%b\n" "$DIVIDING_LINE" "$MISSING_LAUNCHERS_MSG" "$DIVIDING_LINE"
}

function _update_launchers() {
_clean_launchers 2>/dev/null 1>/dev/null
MISSING_LAUNCHERS_MSG="No launcher found, use option \"--launcher\" to create them."
[ ! -d "$DATADIR"/applications/AppImages ] && _update_launchers_not_found_msg && exit 0
[ -d "$DATADIR"/applications/AppImages ] && [ -z "$( ls -A "$DATADIR"/applications/AppImages )" ] && _update_launchers_not_found_msg && exit 0
if ! command -v appimageupdatetool 1>/dev/null; then
update_launchers_error_message=" 💀 ERROR! Missing command \"${RED}appimageupdatetool\033[0m\", install it and retry!"
printf "%b\n%b\n%b\n" "$DIVIDING_LINE" "$update_launchers_error_message" "$DIVIDING_LINE"
else
echo " ◆ Update local AppImages integrated manually"
for var in "$DATADIR"/applications/AppImages/*.desktop; do
appimage_full_path=$(grep "^Exec=" 0<"$var" 2>/dev/null | head -1 | cut -c 6- | sed 's/"//g; s/\s.*$//')
appimagename=$(basename -- "$appimage_full_path")
appimage_path=$(echo "$appimage_full_path" | sed -E 's|/[^/]+$|/|; s/\/*$//g')
printf "%b\n File: %b%b\033[0m\n Path: %b" "$DIVIDING_LINE" "${Green}" "$appimagename" "$appimage_path"
if ! test -f "$appimage_full_path"; then
echo "(unmounted)" | _fit
else
printf "\n\n"
appimageupdatetool -Or "$appimage_full_path"
fi
done
fi
}

function _use_update() {
_online_check
_update_github_api_key_in_the_updater_files
Expand All @@ -897,20 +959,23 @@ function _use_update() {
if [ -z "$ENTRIES" ]; then
_clean_amcachedir
_update_list_updatable_apps
echo -e "$DIVIDING_LINE\n \"$AMCLIUPPER\" CAN MANAGE UPDATES FOR THE FOLLOWING PROGRAMS:\n"
[ -f "$AMCACHEDIR/updatable-args-list" ] && grep "" "$AMCACHEDIR/updatable-args-list" | sort || echo " None"
echo -e "\n All self-updatable programs are excluded"
echo -e "$DIVIDING_LINE\n >> START OF ALL PROCESSES <<\n$DIVIDING_LINE"
_update_all_apps
if ! echo "$FLAGS" | grep -q -- "--apps"; then
echo "$DIVIDING_LINE"
printf "%b\n >> START OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE" "$DIVIDING_LINE"
if echo "$FLAGS" | grep -q -- "--apps"; then
_update_updatable_apps_msg_head
_update_all_apps
elif echo "$FLAGS" | grep -q -- "--launcher"; then
_update_launchers
else
_update_updatable_apps_msg_head
_update_all_apps
_use_sync
echo -e " >> END OF ALL PROCESSES << \n$DIVIDING_LINE"
printf " >> END OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE"
sleep 0.2
exit 0
else
echo "$DIVIDING_LINE"
fi
printf "%b\n >> END OF ALL PROCESSES << \n%b\n" "$DIVIDING_LINE" "$DIVIDING_LINE"
sleep 0.2
exit 0
else
[ -n "$debug_update" ] && echo "$DIVIDING_LINE"
_determine_args
Expand Down Expand Up @@ -1262,9 +1327,10 @@ case "$1" in
${LightBlue}$AMCLI -u --debug
${LightBlue}$AMCLI -u --apps --debug
${LightBlue}$AMCLI -u {PROGRAM}\033[0m
${LightBlue}$AMCLI -u --debug {PROGRAM}\033[0m
${LightBlue}$AMCLI -u --debug {PROGRAM}
${LightBlue}$AMCLI -u --launcher\033[0m
Description: Update everything. Add \"--apps\" to update only the apps or write only the apps you want to update by adding their names. Add the \"--debug\" flag to view the output of AM-updater scripts.
Description: Update everything. Add \"--apps\" to update only the apps or write only the apps you want to update by adding their names. Add the \"--debug\" flag to view the output of AM-updater scripts. Add the \"--launcher\" flag to try to update only local AppImages integrated with the \"--launcher\" option (see \"--launcher\").
${Gold}version, -v\033[0m
Expand Down Expand Up @@ -1314,6 +1380,8 @@ case "$1" in
Description: Drag/drop one or more AppImages in the terminal and embed them in the apps menu and customize a command to use from the CLI.
NOTE that \"--launcher\" can be used as a flag in \"-u\" to try to update the integrated AppImages (see \"-u\"). This works only if \"appimageupdatetool\" is installed and delta updates are supported. This flag does not work miracles, I strongly suggest to use options \"-ia\" and \"-e\" instead.
${Gold}--system\033[0m
${LightBlue}am --system\033[0m
Expand Down Expand Up @@ -1375,7 +1443,7 @@ case "$1" in
https://portable-linux-apps.github.io
\n" | sed 's/^ //g' | fold -sw 77 | sed 's/^/ /g' | less -Ir
\n" | sed 's/^ //g' | _fit | less -Ir
}

if [ -t 1 ]; then _use_help; else _use_help | sed -e 's/\x1b\[[0-9;]*m//g'; fi
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,11 @@ Unlock updates for the selected program (nulls "`lock`").
am -u --apps --debug
am -u {PROGRAM}
am -u --debug {PROGRAM}
am -u --launcher

**Description**:

Update everything. Add "`--apps`" to update only the apps or write only the apps you want to update by adding their names. Add the "`--debug`" flag to view the output of AM-updater scripts.
Update everything. Add "`--apps`" to update only the apps or write only the apps you want to update by adding their names. Add the "`--debug`" flag to view the output of AM-updater scripts. Add the "`--launcher`" flag to try to update only local AppImages integrated with the "`--launcher`" option (see "`--launcher`").

------------------------------------------------------------------------
### `version`, `-v`
Expand Down Expand Up @@ -626,6 +627,8 @@ Downgrades an installed app from pre-release to "latest".

Drag/drop one or more AppImages in the terminal and embed them in the apps menu and customize a command to use from the CLI.

NOTE that "`--launcher`" can be used as a flag in "`-u`" to try to update the integrated AppImages (see "`-u`"). This works only if "appimageupdatetool" is installed and delta updates are supported. This flag does not work miracles, I strongly suggest to use options "`-ia`" and "`-e`" instead.

------------------------------------------------------------------------
### `--system`

Expand Down Expand Up @@ -713,6 +716,7 @@ Below you can access the documentation pages related to the use of "AM", complet
- [How to create a launcher for a local AppImage](docs/guides-and-tutorials/launcher.md#how-to-create-a-launcher-for-a-local-appimage)
- [How to remove the orphan launchers](docs/guides-and-tutorials/launcher.md#how-to-remove-the-orphan-launchers)
- [AppImages from external media](docs/guides-and-tutorials/launcher.md#appimages-from-external-media)
- [Update scattered AppImages](docs/guides-and-tutorials/launcher.md#update-scattered-appimages)
- [Sandbox an AppImage](docs/guides-and-tutorials/sandbox.md)
- [How to enable a sandbox](docs/guides-and-tutorials/sandbox.md#how-to-enable-a-sandbox)
- [How to disable a sandbox](docs/guides-and-tutorials/sandbox.md#how-to-disable-a-sandbox)
Expand Down
50 changes: 46 additions & 4 deletions docs/guides-and-tutorials/launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ The option `--launcher` allows you to drag and drop a local AppImage to create a

This option also allows you to create a symbolic link with the name you prefer, in "`~/.local/bin`". Leave blank to let the option create a shell script that calls your AppImage, with extension ".appimage", lowercased.

##### How to create a launcher for a local AppImage
---------------------------
### How to create a launcher for a local AppImage
```
am --launcher /path/to/File.AppImage
```
Expand All @@ -19,7 +20,8 @@ https://github.com/user-attachments/assets/caa22ab7-b6a4-45c4-bd33-27316251e267

Now the binaries are "two", keep read to see how to remove them using "AM" and "AppMan".

##### How to remove the orphan launchers
---------------------------
### How to remove the orphan launchers
In case you move your AppImages somewhere else or remove them, use the following otion `-c` or `clean` to get rid of all the orphaned launchers and dead symlinks and scripts you created earlier:
```
am -c
Expand All @@ -32,16 +34,56 @@ In this video I'll remove the AppImage, and then I'll remove the launchers and i

https://github.com/user-attachments/assets/2dedf1a9-43c2-455c-8c97-2023bedc4203

##### AppImages from external media
---------------------------
### AppImages from external media
Another peculiarity concerns the use of the `-c` option on launchers created on AppImage packages placed on removable devices:
- if in the .desktop file belongs to an AppImage placed in /mnt or /media and none of the references are mounted, the option `-c` will not be able to remove it until you mount the exact device where it was placed in the moment you have created the launcher;
- if you mount that same device and the AppImage is not where it was when you created the launcher, it will be removed.

This is very useful if you have large AppImage packages that you necessarily need to place in a different partition.

---------------------------
### Update scattered AppImages
If a local AppImage supports delta updates, you need to install `appimageupdatetool`
```
am -i appimageupdatetool
```
or locally, with AM
```
am -i --user appimageupdatetool
```
or AppMan.
```
appman -i appimageupdatetool
```
After that, you can simply run the `-u` option with the `--launcher` flag and vice versa, `--launcher` with the `-u` flag, to try to update them
```
am -u --launcher
```
or
```
am --launcher -u
```
or
```
appman -u --launcher
```
or
```
appman --launcher -u
```

AppImages are not updated directly with `-u` because I believe it is a user choice to keep an AppImage at a specific version or not.

https://github.com/user-attachments/assets/ff6b7a60-7a2a-4684-aeba-8efe227b604a

Again, **these updates only work if the AppImage supports binary deltas**!

If you want to be sure to update all AppImages, rely on the [`-ia`](./install-appimage.md) and [`-e`](./extra.md) options instead.

------------------------------------------------------------------------

| [Back to "Guides and tutorials"](../../README.md#guides-and-tutorials) | [Back to "Main Index"](../../README.md#main-index) | ["Portable Linux Apps"](https://portable-linux-apps.github.io/) | [ "AppMan" ](https://github.com/ivan-hc/AppMan) |
| - | - | - | - |

------------------------------------------------------------------------
------------------------------------------------------------------------
Loading

0 comments on commit f5a1ced

Please sign in to comment.