Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"AM" 8.1 #894

Merged
merged 45 commits into from
Aug 29, 2024
Merged

"AM" 8.1 #894

merged 45 commits into from
Aug 29, 2024

Conversation

ivan-hc
Copy link
Owner

@ivan-hc ivan-hc commented Aug 28, 2024

  • allow "AppMan" to be installed/used outside "$HOME", by @Samueru-sama
  • allow "AM" support for distro packagers

Samueru-sama and others added 29 commits August 26, 2024 19:47
allow appman to work outside `$HOME` take 2
improve detection of `$BINDIR` APP-MANAGER
fix conversion of old appman config APP-MANAGER
Fix appman mode usage in AM for unprivileged users
@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 28, 2024

The piece that must be changed to made distro packagers bundle "AM" is this

# "AM" CORE VARIABLES
function _am() {
	AMCLI="am"
	AMCLIPATH="$AMCLI"
	if command -v sudo >/dev/null 2>&1; then
		SUDOCMD="sudo"
	elif command -v doas >/dev/null 2>&1; then
		SUDOCMD="doas"
	else
		echo 'ERROR: No sudo or doas found'
		exit 1
	fi
	APPSPATH="/opt"
	AMPATH="$APPSPATH/$AMCLI"
	_create_cache_dir
	MODULES_PATH="$AMPATH/modules"
	mkdir -p "$MODULES_PATH" || exit 1
}

# DETERMINE WHEN TO USE "AM" OR "APPMAN"
if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
	_am
elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
	_am
else
	_appman
fi

The only variable interested to this support is "MODULES_PATH", the one containing the modules.

Note that the change wants you to rename the script APP-MANAGER to "am", if you want to put it in /usr/bin as /usr/bin/am

All depend on how you want to install AM into a distro package.

it would be sufficient to change the above behaviour like this

# "AM" CORE VARIABLES
function _am() {
	AMCLI="am"
	AMCLIPATH="$AMCLI"
	if command -v sudo >/dev/null 2>&1; then
		SUDOCMD="sudo"
	elif command -v doas >/dev/null 2>&1; then
		SUDOCMD="doas"
	else
		echo 'ERROR: No sudo or doas found'
		exit 1
	fi
	APPSPATH="/opt"
	AMPATH="$APPSPATH/$AMCLI"
	_create_cache_dir
}

# DETERMINE WHEN TO USE "AM" OR "APPMAN"
if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
	_am
	MODULES_PATH="$AMPATH/modules"
	mkdir -p "$MODULES_PATH" || exit 1
elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
	_am
	AMPATH="/usr/lib/am"
	MODULES_PATH="$AMPATH/modules"
else
	_appman
fi

what it does is to check if the command "am" is /usr/bin/am

"AMPATH" is needed to determine the directory where also the modules will be installed, at this point I don't know if we still have to determine "MODULES_PATH".

"AMPATH" if available as a non RW directory will prevent the update of AM and the modules. They all will be managed by the package manager you are creating the package for.

According to the above function, this would be the structure of a package:

/usr/bin/am
/usr/lib/am/modules/database.am
/usr/lib/am/modules/install.am
/usr/lib/am/modules/management.am
/usr/lib/am/modules/sandboxes.am
/usr/lib/am/modules/template.am

of course, as suggested by @Samueru-sama , other options for "AMPATH" would be /usr/bin/AM, /usr/lib/AM, /usr/libexec/AM, or /var/lib/AM. Its up to you.

Since this feature was asked by you two first, I'd like to have your opinion @fiftydinar and @vitaly-zdanevich

Let me know.

@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 28, 2024

I think it should solve also #826 then

@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 28, 2024

@Samueru-sama should this be enough also to determine where the modules must be saved?

# "AM" CORE VARIABLES
function _am() {
	AMCLI="am"
	AMCLIPATH="$AMCLI"
	if command -v sudo >/dev/null 2>&1; then
		SUDOCMD="sudo"
	elif command -v doas >/dev/null 2>&1; then
		SUDOCMD="doas"
	else
		echo 'ERROR: No sudo or doas found'
		exit 1
	fi
	APPSPATH="/opt"
	AMPATH="$APPSPATH/$AMCLI"
	_create_cache_dir
	MODULES_PATH="$AMPATH/modules"
}

# DETERMINE WHEN TO USE "AM" OR "APPMAN"
if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
	_am
	mkdir -p "$MODULES_PATH" || exit 1
elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
	_am
	AMPATH="/usr/lib/am"
else
	_appman
fi

EDIT: just tested, nope, I must set again MODULES_PATH="$AMPATH/modules", like this

# "AM" CORE VARIABLES
function _am() {
	AMCLI="am"
	AMCLIPATH="$AMCLI"
	if command -v sudo >/dev/null 2>&1; then
		SUDOCMD="sudo"
	elif command -v doas >/dev/null 2>&1; then
		SUDOCMD="doas"
	else
		echo 'ERROR: No sudo or doas found'
		exit 1
	fi
	APPSPATH="/opt"
	AMPATH="$APPSPATH/$AMCLI"
	_create_cache_dir
	MODULES_PATH="$AMPATH/modules"
}

# DETERMINE WHEN TO USE "AM" OR "APPMAN"
if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
	_am
	mkdir -p "$MODULES_PATH" || exit 1
elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
	_am
	AMPATH="/usr/lib/am"
	MODULES_PATH="$AMPATH/modules"
else
	_appman
fi

@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 28, 2024

also, I noticed that if I don't set a valid RW AMPATH, any option will ask for root password, also in AppMan Mode

so this should be the way to go

# "AM" CORE VARIABLES
function _am() {
	AMCLI="am"
	AMCLIPATH="$AMCLI"
	if command -v sudo >/dev/null 2>&1; then
		SUDOCMD="sudo"
	elif command -v doas >/dev/null 2>&1; then
		SUDOCMD="doas"
	else
		echo 'ERROR: No sudo or doas found'
		exit 1
	fi
	APPSPATH="/opt"
	AMPATH="$APPSPATH/$AMCLI"
	_create_cache_dir
	MODULES_PATH="$AMPATH/modules"
}

# DETERMINE WHEN TO USE "AM" OR "APPMAN"
if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
	_am
	mkdir -p "$MODULES_PATH" || exit 1
elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
	_am
	AMPATH="/usr/lib/am"
	MODULES_PATH="$AMPATH/modules"
else
	_appman
fi

about replacing /usr/lib/am with something else, its up to you @fiftydinar and @vitaly-zdanevich

@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 28, 2024

Maybe I should allow usage of some functions as root (for example, updating the apps) instead of suggesting to use appman mode

@fiftydinar
Copy link
Contributor

fiftydinar commented Aug 28, 2024

/usr/bin/am
/usr/lib/am/modules/database.am
/usr/lib/am/modules/install.am
/usr/lib/am/modules/management.am
/usr/lib/am/modules/sandboxes.am
/usr/lib/am/modules/template.am

I agree with this hierarchy & code looks good

Will test further in my test image how well it works when this gets merged

ivan-hc added a commit to ivan-hc/AppMan that referenced this pull request Aug 28, 2024
...next version 8.1 will allow installation of apps ouside the $HOME directory, see ivan-hc/AM#894
@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 29, 2024

just started tests on a VM of Debian Stable with the following structure

/usr/bin/am
/usr/lib/am/modules/database.am
/usr/lib/am/modules/install.am
/usr/lib/am/modules/management.am
/usr/lib/am/modules/sandboxes.am
/usr/lib/am/modules/template.am

and the obstacle I had was this function

if [ "$AMCLI" = am ]; then
	if test -f "$APPMANCONFIG"/appman-mode; then
		[ ! -f "$APPMANCONFIG"/appman-config ] && echo -e "$APPMAN_MSG"
		_appman
		AMCLIPATH="$(realpath "$0")"
	elif [ ! -w "$AMPATH" ]; then
		read -r -p " \"AM\" is read-only, want to use it in \"AppMan Mode\" (Y,n)? " yn
		if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
			exit 0
		else
			echo -e "$DIVIDING_LINE\n \"AppMan Mode\" enabled! \n$DIVIDING_LINE"
			_use_appman 1>/dev/null
		fi
	fi
fi

that prompts me this

Istantanea_2024-08-29_02-51-19

I had to remove the "elif" to run -f normally

Istantanea_2024-08-29_02-52-10

so now I need a suggestion for that function

"$AMPATH" is already created for "modules", and AM may not exist without it, in "normal mode", same for AppMan
@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 29, 2024

Just finished to test in VM the new behaviour, all works as expected, also AppMan Mode

Some notes:

  1. to allow /usr/bin/am to be used without the warning of rw permissions (see above) I had to set AMPATH to a RW directory, in this case $AMCACHEDIR, i.e. $HOME/.cache/am
# DETERMINE WHEN TO USE "AM" OR "APPMAN"
if [ "$(realpath "$0")" = "/opt/am/APP-MANAGER" ]; then
	_am
	mkdir -p "$MODULES_PATH" || exit 1
elif [ "$(realpath "$0")" = "/usr/bin/am" ]; then
	_am
	AMPATH="$AMCACHEDIR"
	MODULES_PATH="/usr/lib/am/modules"
else
	_appman
fi
  1. what made "AM" installed as /usr/bin/am really different from the normal /opt/am/APP-MANAGER simlinked in /usr/local/bin/am is the fact that can't be updated
function _use_sync() {
	_online_check
	_betatester_message_on
	_sync_installation_scripts
	if [ "$(realpath "$0")" != "/usr/bin/am" ]; then
		_sync_modules
		_sync_amcli
	fi
}

the function "_use_sync" is the function responsible of updating AM and modules, so the command am -s, also included in am -u.

Normally it does three things:

  • compares local copies of the installation scripts of the installed apps with the ones online (to warn users that something is changed in the installation script, maybe the source is changed or a better way to install it has been applied), and the responsible is the sub-function "_sync_installation_scripts", that /usr/bin/am will be still able to use
  • updates modules, sub-function "_sync_modules"
  • updates itself, sub-functions "_sync_amcli"

well, since a package for a distro would be shipped fith its own copies of "AM" and modules, according with the structure above... you don't need to use "_sync_modules" and "_sync_amcli"

if [ "$(realpath "$0")" != "/usr/bin/am" ]; then
	_sync_modules
	_sync_amcli
fi

that said, if it is OK for you, I can merge this to main and release it as AM 8.1

@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 29, 2024

This is a demo video where I test various things... apart Chromium that does not run in sandbox, but AM works also in appman mode.

Note that normal AM shows that can manage also AM among the installed apps shown with -f, while this special version does not list it... so @vitaly-zdanevich this also solves the irrue of am -R am, completelly

simplescreenrecorder-2024-08-29_04.23.37.mkv.mp4

@ivan-hc
Copy link
Owner Author

ivan-hc commented Aug 29, 2024

Time to merge.

@ivan-hc ivan-hc merged commit 18724c2 into main Aug 29, 2024
3 checks passed
@ivan-hc ivan-hc deleted the dev branch August 29, 2024 17:09
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.

3 participants