Skip to content

Handle multiple istance of pla-install process - #2716

Open
ivan-hc wants to merge 21 commits into
mainfrom
dev
Open

ivan-hc wants to merge 21 commits into
mainfrom
dev

Conversation

@ivan-hc

@ivan-hc ivan-hc commented Sep 15, 2026

Copy link
Copy Markdown
Owner

fix #2714

@ivan-hc

ivan-hc commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

For now the behavior allow the CLI to recognize installation scripts running in the current AMCACHEDIR in use

_use_pla_installer_check() {
	if find "$CACHEDIR"/"$AMCMD_PLA" -type f -exec grep -Iq '^#!.*\bsh\b' {} \; -print -quit | grep -q .; then
    		echo "Resource is busy, retry later"
    		printf "\n"
		read -p "Press [ENTER] to close this window."
		exit 1
    	fi
}
simplescreenrecorder-2026-09-15_17.32.32.mp4

@kazam0180 @cheack @fiftydinar @vishnu350 @Samueru-sama if you have a better idea, let me know

@kazam0180

Copy link
Copy Markdown
Contributor

This is not the fix for #2714. This is a fix for separate issue: concurrency

@ivan-hc

ivan-hc commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

This is not the fix for #2714. This is a fix for separate issue: concurrency

@kazam0180 what about this?

_use_pla_installer_check() {
	while find "$CACHEDIR"/"$AMCMD_PLA" -type f -exec grep -Iq '^#!.*\bsh\b' {} \; -print -quit | grep -q .; do
		echo "Resource is busy, retrying in 5 seconds..."
		sleep 5
	done
}
simplescreenrecorder-2026-09-16_00.50.01.mp4

@kazam0180

Copy link
Copy Markdown
Contributor

Hmm. Okay yeah that works. Since AM does only download one app at a time, this can be the equivalent

@ivan-hc

ivan-hc commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

This is still not secure enough btw. I noticed this strange bug:

simplescreenrecorder-2026-09-16_01.15.50.mp4

and...

simplescreenrecorder-2026-09-16_01.17.33.mp4

In the first video, if you run an installation immediately, something weird happens because the installation directory get removed.

I have a suspect... I'll check it later.

In the second video, the installation script was not removed from the cache, so the PLA installer was waiting until I removed it.

@ivan-hc

ivan-hc commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

In the first video, if you run an installation immediately, something weird happens because the installation directory get removed.

I have a suspect... I'll check it later.

Fixed in 2e4b99b

This is a check that runs every time you use AM/AppMan, to find not valid apps directories (based on minimal number of files and executable inside). Now if "$PLA_APP" is set, the removal does not run.

@ivan-hc

ivan-hc commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

In the second video, the installation script was not removed from the cache, so the PLA installer was waiting until I removed it.

I think that this can be solved by checking running processes instead.

@kazam0180

kazam0180 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

hmm

Now if "$PLA_APP" is set, the removal does not run.

nice

@ivan-hc

ivan-hc commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

@kazam0180 this is it f6a0dd9

simplescreenrecorder-2026-09-16_16.42.51.mp4

Multiple apps at same time, no conflicts (except AM/AppMan used in a dedicated instance, due to this).

@ivan-hc

ivan-hc commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

Multiple apps at same time, no conflicts (except AM/AppMan used in a dedicated instance, due to this).

I have to fix this to made this PR ready

AM/APP-MANAGER

Lines 503 to 521 in f6a0dd9

# Detect directories with less than 4 elements
for a in $ARGPATHS; do
if ! echo "$a" | grep -q "/am$" && [ "$(ls "$a" | wc -l)" -lt 4 ]; then
# Find and hide directories with less than 3 executables
if [ "$(find "$a" -type f -executable 2>/dev/null | wc -l)" -lt 3 ]; then
# Determine if the directory is related to a library
if ! sort "$a"/remove | grep -q "usr/local/lib"; then
items_2_del=$(sort "$a"/remove | tr ' ' '\n' | grep "^/" 2>/dev/null | xargs)
for i in $items_2_del; do
if ! echo "$i" | grep -q "local/share/applications/.*AM.desktop\|$BINDIR\|$a"; then
sed -i "\|$i|s|^|#|" "$a"/remove 2>/dev/null
fi
done
[ -z "$PLA_APP" ] && "$a"/remove 1>/dev/null && printf "\n Removed %b\n" "$a"
ARGPATHS=$(echo "$ARGPATHS" | grep -v "$a")
fi
fi
fi
done

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

471c139

This was introduced due to scripts with APP different from script name (for example, metapackages). Now the logic is obsolete.

a22d696

The above is a fix, since external apps have different argument name (using extensions for example).

I need to check -e btw, but it should work good.

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

I need to check -e btw, but it should work good.

Checked, works great.

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author
    LASTDIR=$(echo "$APPSPATH/$pure_arg" | sed 's:.*/::')

I know that I could use $pure_arg directly, but right now its not time to refactor the code. I'll do it later, when I will be less busy.

My priority now is to fix parallel PLA installations.

And who knows if we will be have the opportunity to do the same for normal installations, in parallel, like to updates.

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

I have yet another step to do before leaving it to testing: get rid of grep messages when using -f (or other options) while installations are running.

Istantanea_2026-09-17_15-25-49

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

bc64a66

The error was given by version check. Now it sets version as "pending".

simplescreenrecorder-2026-09-17_15.44.52.mp4

I think I have solved.

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

@vishnu350 @cheack @kazam0180 @fiftydinar I need your feedback too.

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

I know that I could use $pure_arg directly, but right now its not time to refactor the code. I'll do it later, when I will be less busy.

Too late, just done 2daff9b

@ivan-hc

ivan-hc commented Sep 17, 2026

Copy link
Copy Markdown
Owner Author

In brief, each instance creates its own $AMCACHEDIR directory in cache, the ones starting with "PLA_" in the name.

Such directories, if present, will avoid AM from cleaning $APPSPATH (the directory of all installed apps, for example /opt in AM, in AppMan is the one you choose). Such directories will be removed when PLA installations will be finished.

In case a PLA_ directory remains, it is necessary to run am -c to clean unneeded files and directories. But this would be not necessary. All should work well.

I need tests for this.

Starting from now, I will have the whole weekend busy with my job. This is why I need your help.

If all goes well, this will be AM 10.6

By entering developer mode (am --devmode-enable && am -s), you will be able to do your tests.

Thanks in advance.

@ivan-hc

ivan-hc commented Sep 18, 2026

Copy link
Copy Markdown
Owner Author

bc64a66

The error was given by version check. Now it sets version as "pending".
simplescreenrecorder-2026-09-17_15.44.52.mp4

I think I have solved.

In brief, each instance creates its own $AMCACHEDIR directory in cache, the ones starting with "PLA_" in the name.

Such directories, if present, will avoid AM from cleaning $APPSPATH (the directory of all installed apps, for example /opt in AM, in AppMan is the one you choose). Such directories will be removed when PLA installations will be finished.

In case a PLA_ directory remains, it is necessary to run am -c to clean unneeded files and directories. But this would be not necessary. All should work well.

I need tests for this.

Starting from now, I will have the whole weekend busy with my job. This is why I need your help.

If all goes well, this will be AM 10.6

By entering developer mode (am --devmode-enable && am -s), you will be able to do your tests.

Thanks in advance.

@kazam0180 @cheack @fiftydinar @vishnu350 @Samueru-sama @Shikakiben any thought?

@ivan-hc

ivan-hc commented Sep 18, 2026

Copy link
Copy Markdown
Owner Author

@Shikakiben @fiftydinar this change would help more AM-GUI users that click on multiple Install buttons on the UI at same time.

@vishnu350

Copy link
Copy Markdown
Contributor

@ivan-hc, it seems to work well. No failures in the regressions tests.

But why not just follow the standard mechanism and create a lock file or file-based locks (commonly named with a .lock extension)? When this lock file exists, it signals that another instance of AM is already running. AM should not be allowed to run if another instance is already running.

I think this is also how apt works. You may also recall the mime-update change you made a few weeks back, where you checked for the .lock file before running it.

@ivan-hc

ivan-hc commented Sep 19, 2026

Copy link
Copy Markdown
Owner Author

@vishnu350 this feature is for PLA installations only, to made them run in parallel and without conflicts.

This way, every installation (via PLA) have its own instance. No kind of restriction in this sense.

@vishnu350

Copy link
Copy Markdown
Contributor

this feature is for PLA installations only, to made them run in parallel and without conflicts.

OK sure it seems to work for PLA installs. But doing something like the following may also cause similar issues:

am -i app1 &
am -i app2

Will it not?

@ivan-hc

ivan-hc commented Sep 19, 2026

Copy link
Copy Markdown
Owner Author

this feature is for PLA installations only, to made them run in parallel and without conflicts.

OK sure it seems to work for PLA installs. But doing something like the following may also cause similar issues:

am -i app1 &
am -i app2

Will it not?

This change is for PLA installations only. If you run am -i from another instance, it will use the regular AMCACHEDIR.

This means that you cannot use multiple instances of regular am -i, they will override the others, due to the common AMCACHEDIR.

PLA installations are for people that, by scrolling the web page, want to install multiple apps at each click of the mouse, the same way you would do with a GUI. CLI side is different instead.

@ivan-hc

ivan-hc commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

@vishnu350

14033c6
acc634d

The above commits will not solve...

this feature is for PLA installations only, to made them run in parallel and without conflicts.

OK sure it seems to work for PLA installs. But doing something like the following may also cause similar issues:

am -i app1 &
am -i app2

Will it not?

...but allows to sun multiple terminals to install multiple apps

simplescreenrecorder-2026-09-20_05.10.39.mp4

$AMCACHEDIR will be not wiped when running multiple instances of am -i

@kazam0180 @cheack @fiftydinar @vishnu350 @Samueru-sama @Shikakiben and @alexb3d + @davidhedlund

Want to review this?

@ivan-hc

ivan-hc commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

71ceb0a

I figured out that this change would be simpler than what I tested until now in this pull request.

@ivan-hc

ivan-hc commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

I have found a regression: if you run multiple instances, and you do CTRL+C on the first (not others, just the first), this will cleanup $AMCACHEDIR

@ivan-hc

ivan-hc commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

I have found a regression: if you run multiple instances, and you do CTRL+C on the first (not others, just the first), this will cleanup $AMCACHEDIR

Solved

@ivan-hc

ivan-hc commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

I think it is ready.

As always, i wait for your approval.

Those that are on Discord, can contact me there if they prefer.

@kazam0180

Copy link
Copy Markdown
Contributor

seems working fine

@alexb3d

alexb3d commented Sep 20, 2026

Copy link
Copy Markdown

It's still showing me the conflict...

'am -s' updates to version
◆ "AM" YA ESTÁ ACTUALIZADO, VERSIÓN ACTUAL "10.5-1"
Then I updated everything with 'am -u'

I'm going to try two installations at the same time, am -i adobe-flash-player and am -i ruffle.
Both folders are created in the installation directory.

Ruffle, which is lighter, is installed first and deletes the adobe-flash-player folder.

The Flash installation shows an error, and at the end it says that Ruffle was installed:

lex@home:~$ am -i adobe-flash-player
-----------------------------------------------------------------------------------------------------------------
 "AM" se está ejecutando como "AppMan", use am --system para volver a cambiarlo a "AM"
-----------------------------------------------------------------------------------------------------------------
============================================================================

                  INICIO DE TODOS LOS PROCESOS DE INSTALACIÓN

============================================================================

 ◆ "ADOBE-FLASH-PLAYER": iniciando script de instalación

Adobe_Flash_Player_Standalon 100%[==============================================>]  35,02M   294KB/s    en 2m 38s  
./adobe-flash-player: 19: cd: can't cd to ..
mv: no se puede efectuar `stat' sobre './tmp/*mage': No existe el archivo o el directorio
./adobe-flash-player: 23: cannot create ./version: Directory nonexistent
chmod: no se puede acceder a './adobe-flash-player': No existe el archivo o el directorio
 
 Oops! Something went wrong! Integrity check in progress... 

 ✖ La suma de verificación no se puede verificar, discordancia en el nombre del binario. 

 "RUFFLE" INSTALLED (13 MB OF DISK SPACE)
____________________________________________________________________________
============================================================================

                  FIN DE TODOS LOS PROCESOS DE INSTALACIÓN

             Los siguientes programas nuevos han sido instalados:

 ◆ ruffle 2026
 ◆ ruffle 2026✓

============================================================================

Now, I'm going to install and flash one, and on the other I'm going to try to set up the Ruffle portable home:

terminal ruffle:

lex@home:~$ am -H ruffle

 Removed /home/lex/.apps/adobe-flash-player
----------------------------------------------------------------------------------------------
 ✔ $HOME establecido en "/home/lex/.apps/ruffle/ruffle.home" para "ruffle"
----------------------------------------------------------------------------------------------

Two things happen here: if I let Flash finish with errors, it won't install:

lex@home:~$ am -i adobe-flash-player
-----------------------------------------------------------------------------------------------------------------
 "AM" se está ejecutando como "AppMan", use am --system para volver a cambiarlo a "AM"
-----------------------------------------------------------------------------------------------------------------
============================================================================

                  INICIO DE TODOS LOS PROCESOS DE INSTALACIÓN

============================================================================

 ◆ "ADOBE-FLASH-PLAYER": iniciando script de instalación

 
 Oops! Something went wrong! Integrity check in progress... 

 ✖ La suma de verificación no se puede verificar, discordancia en el nombre del binario. 

 "RUFFLE" INSTALLED (13 MB OF DISK SPACE)
____________________________________________________________________________
============================================================================

                  FIN DE TODOS LOS PROCESOS DE INSTALACIÓN

             Los siguientes programas nuevos han sido instalados:

 ◆ ruffle 2026

============================================================================

And if I uninstall it, it removes Ruffle:

lex@home:~$ am -i adobe-flash-player
-----------------------------------------------------------------------------------------------------------------
 "AM" se está ejecutando como "AppMan", use am --system para volver a cambiarlo a "AM"
-----------------------------------------------------------------------------------------------------------------
============================================================================

                  INICIO DE TODOS LOS PROCESOS DE INSTALACIÓN

============================================================================

 ◆ "ADOBE-FLASH-PLAYER": iniciando script de instalación

 
 Oops! Something went wrong! Integrity check in progress... 

^C

 💀 ERROR DURANTE LA INSTALACIÓN, "ADOBE-FLASH-PLAYER" ELIMINADO!
____________________________________________________________________________
============================================================================

                  FIN DE TODOS LOS PROCESOS DE INSTALACIÓN

============================================================================

@ivan-hc

ivan-hc commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

It's still showing me the conflict...

'am -s' updates to version ◆ "AM" YA ESTÁ ACTUALIZADO, VERSIÓN ACTUAL "10.5-1" Then I updated everything with 'am -u'

The current dev branch is v10.5-4

To use it, run

am --devmode-enable
am -s

then do your tests.

To exit developer mode, run

am --devmode-disable

I suggest to exit developer mode once that AM updates to v10.6

@ivan-hc

ivan-hc commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

I noticed a malfunction: I tested am -i on brave and chromium, and for some reason, the first item is not added in $pending_args, set under function _determine_args

This causes the script in ~/.cache/am to be removed and by running am -f I see failed attempts to remove the uncomplete directories

Istantanea_2026-09-21_03-30-10

The rm command runs in the "remove" script, executed under _determine_args

This is the whole function

_determine_args() {
	if [ -d "$APPSPATH" ]; then
		if [ -L "$APPSPATH" ]; then
			ARGPATHS=$(find -L "$APPSPATH" -type f -name 'remove' -executable -print 2>/dev/null | sort -u | sed 's:/[^/]*$::' | grep -v "$APPSPATH/.*/")
		else
			ARGPATHS=$(find "$APPSPATH" -type f -name 'remove' -executable -print 2>/dev/null | sort -u | sed 's:/[^/]*$::' | grep -v "$APPSPATH/.*/")
		fi
		if [ "$AMCLI" = am ]; then
			_detect_appman_apps
			if [ -d "$APPMAN_APPSPATH" ]; then
				if [ -L "$APPMAN_APPSPATH" ]; then
					APPMAN_PATHS=$(find -L "$APPMAN_APPSPATH" -type f -name 'remove' -executable -print 2>/dev/null | sort -u | sed 's:/[^/]*$::' | grep -v "$APPMAN_APPSPATH/.*/")
				else
					APPMAN_PATHS=$(find "$APPMAN_APPSPATH" -type f -name 'remove' -executable -print 2>/dev/null | sort -u | sed 's:/[^/]*$::' | grep -v "$APPMAN_APPSPATH/.*/")
				fi
				ARGPATHS=$(printf "%b\n%b" "$ARGPATHS" "$APPMAN_PATHS")
			fi
		fi
	fi
	# Detect directories with less than 4 elements
	for a in $ARGPATHS; do
		if ! echo "$a" | grep -q "/am$" && [ "$(ls "$a" | wc -l)" -lt 4 ]; then
			# Determine pending args
			argname=$(echo "$a" | sed 's:.*/::')
			if [ -d "$CACHEDIR"/am ] && [ -f "$CACHEDIR"/am/"$argname" ] || [ -d "$CACHEDIR"/appman ] && [ -f "$CACHEDIR"/appman/"$argname" ]; then
				[ -z "$pending_args" ] && pending_args="$argname" || pending_args="$pending_args $argname"
			fi
			# Find and hide directories with less than 3 executables
			if ! echo "$pending_args" | tr ' ' '\n' | grep -q "^$argname$" && [ "$(find "$a" -type f  -executable 2>/dev/null | wc -l)" -lt 3 ]; then
				# Determine if the directory is related to a library
				if ! sort "$a"/remove | grep -q "usr/local/lib"; then
					items_2_del=$(sort "$a"/remove | tr ' ' '\n' | grep "^/" 2>/dev/null | xargs)
					for i in $items_2_del; do
						if ! echo "$i" | grep -q "local/share/applications/.*AM.desktop\|$BINDIR\|$a"; then
							sed -i "\|$i|s|^|#|" "$a"/remove 2>/dev/null
						fi
					done
					"$a"/remove 1>/dev/null && printf "\n Removed %b\n" "$a"
					ARGPATHS=$(echo "$ARGPATHS" | grep -v "$a")
				fi
			fi
		fi
	done
	ARGS=$(echo "$ARGPATHS" | xargs -n 1 basename 2>/dev/null)
	# use "argpath=$(echo "$ARGPATHS" | grep "/$arg$")" to determine the full path of "arg"
}

The above works well for AppMan apps.

@alexb3d

alexb3d commented Sep 21, 2026

Copy link
Copy Markdown

The current dev branch is v10.5-4

To use it, run

Perfect—it's working just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run AM installations from multiple instances (related to the new UI of the catalogue)

4 participants