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

Add Info screen on terminal when updating any installed package #1106

Closed
Premjit-Developer opened this issue Nov 12, 2024 · 30 comments · Fixed by #1149
Closed

Add Info screen on terminal when updating any installed package #1106

Premjit-Developer opened this issue Nov 12, 2024 · 30 comments · Fixed by #1149

Comments

@Premjit-Developer
Copy link

Is your feature request related to a problem? Please describe.

When updating any installed package it's really difficult to understand how much data is required to update the package or how much data left to update that package.

Describe the solution you'd like

Write here

Describe alternatives you've considered

Write here

@Samueru-sama
Copy link
Contributor

that would be very hard to implement because all the scripts do is parse github to get the latest version and then update.

We would need to figure out of the size of the package before updating, and not to mention this will be different for other sites.

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 12, 2024

This is an interesting issue.

I also find it annoying to have to go and see the download status in the app folder directly, to be honest.

I've been wanting to do something APT or PacMan-style for a long time, regarding updates... but that would require some additional scripting tool that I don't know about.

Currently, it is possible to simply "unsilence" the scripts during the download process... but since the updates happen "in parallel", the information would end up crossing each other, creating confusion.

I need to find a way to create a "fixed" screen where each process continues to run, before continuing the entire update process.

I would like to see the list of updateable programs, and all the progress bars that are going on, and only at the end of all the updates, continue the general update process. Like APT and Pacman do.

Is there a solution that does this?

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 12, 2024

@Premjit-Developer is this what you are looking for?

simplescreenrecorder-2024-11-13_00.46.46.mkv.mp4

It's completely doable, but I'd like to provide a better interface... if I find one.

@xplshn
Copy link
Contributor

xplshn commented Nov 13, 2024

What about using gum?

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 13, 2024

What about using gum?

Adding gum means adding a dependency, while instead I would like to try to have as few dependencies as possible.

I already talked about it with @zen0bit , who is working on a TUI based on gum, see here #175

@xplshn
Copy link
Contributor

xplshn commented Nov 14, 2024

Well, fancy progress bars in pure sh are possible, and in bash it is also common, a quick duckduckgo search shows a stackoverflow with an OK implementation of one: https://github.com/fearside/ProgressBar/blob/master/progressbar.sh

@Premjit-Developer
Copy link
Author

Premjit-Developer commented Nov 16, 2024

@Premjit-Developer is this what you are looking for?
simplescreenrecorder-2024-11-13_00.46.46.mkv.mp4

It's completely doable, but I'd like to provide a better interface... if I find one.

Yes, And also If a user cancels the update, the partially updated program remains in the temp folder. To ensure consistency, the temp folder should be cleared when rechecking for updates.

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

Yes, And also If a user cancels the update, the partially updated program remains in the temp folder. To ensure consistency, the temp folder should be cleared when rechecking for updates.

this is already covered by this function

function _clean_all_tmp_directories_from_appspath() {
	for arg in $ARGPATHS; do
		if test -d "$arg"/tmp; then
			rm -Rf "$arg"/tmp && echo " ✔ Removed $arg/tmp"
		fi
	done
}

this runs also when am -u starts

function _use_update() {
	_online_check
	_update_github_api_key_in_the_updater_files
	_clean_all_tmp_directories_from_appspath >/dev/null
	case $2 in
	''|'--apps')
		_clean_amcachedir
		_update_list_updatable_apps
[ ... ]

this function is also a part of am -c

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

In this example I removed the three >/dev/null 2>&1 references to unsilence sunning the AM-updater scripts and I have updated 3 apps, and two of these (Libreoffice and Kdenlive, the official ones) are old type2 AppImages that I update and convert not to have the libfuse2 dependence (see option nolibfuse).

This is what is happened, with parallel updates

simplescreenrecorder-2024-11-17_02.52.09.mkv.mp4

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

in brief, what you are asking for can be already done... but without the parallel updates

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

The two functions involved for the previous video were these

function _update_updated_app_msg() {
	end=$(date +%s)
	echo " ◆ $APPNAME is updated, $((end - start)) seconds elapsed!"
}

function _update_run_updater() {
	if grep -q "api.github.com" "$argpath"/AM-updater; then
		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
				torsocks "$argpath"/AM-updater >/dev/null 2>&1 && _update_updated_app_msg
			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
			"$argpath"/AM-updater >/dev/null 2>&1 && _update_updated_app_msg
		fi
	else
		"$argpath"/AM-updater >/dev/null 2>&1 && _update_updated_app_msg
	fi
}

changed like this

function _update_updated_app_msg() {
	end=$(date +%s)
	echo "◆ $APPNAME is updated, $((end - start)) seconds elapsed!"
	echo "$DIVIDING_LINE"
}

function _update_run_updater() {
	if grep -q "api.github.com" "$argpath"/AM-updater; then
		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
				torsocks "$argpath"/AM-updater && _update_updated_app_msg
			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
			"$argpath"/AM-updater && _update_updated_app_msg
		fi
	else
		"$argpath"/AM-updater && _update_updated_app_msg
	fi
}

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

the command to run the AM-updater script is "$argpath"/AM-updater, of course, and it is repeated three times in that function, depending if the app is hosted on github or not and if github APIs are reachable

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

and this is the function responfile of running the above function in parallel for all apps installed

function _update_app() {
	APPNAME=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
	start=$(date +%s)
	if [ -w "$argpath"/AM-updater ]; then
		_update_run_updater &
	else
		echo " ✖ $APPNAME is read-only, cannot update it!"
	fi
}

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

Today I installed appimageupdatetool and repeated the test, I have two apps I'm sure will be updated using it, Virtualbox and Bottles, this is the result using the changes above

simplescreenrecorder-2024-11-17_20.42.51.mkv.mp4

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 17, 2024

NOTE, I am posting videos of the tests and the BASH functions involved to get the opinion of people more experienced than me. I honestly have no idea how to start this rework.

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 19, 2024

Just noticed that appimageupdatetool rejects connections via Torsocks @probonopd

WARNING torsocks[...]: [connect] Connection to a local address are denied since it might be a TCP DNS query to a local DNS server. Rejecting it for safety reasons. (in tsocks_connect() at connect.c:...)

where ... is a number

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 19, 2024

I'm working on this issue and this is what I'm able to do for now

simplescreenrecorder-2024-11-19_21.08.33.mkv.mp4

any idea on how to have a linear output instead of the one of wget with "dots" (while for me, with wget 1.x, the output should be with show-progress, so a bar)?

If you have not seen well in the video, I used

"$argpath"/AM-updater 2>&1 | grep "%"

instead of the one you all have now

"$argpath"/AM-updater >/dev/null 2>&1

any suggestion is wellcome

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 19, 2024

in my previous attempt I have tried to use grep to get only % references... same would happen with grep "[0-9]%"

I need a best way to detect only percentages (also for updates via appimageupdatetool)... or only the wget output

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 19, 2024

If you want to know what is the output by removing >/dev/null or 2>&1, this is the answer, in order

simplescreenrecorder-2024-11-19_21.24.40.mkv.mp4

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

I'm working on this issue and this is what I'm able to do for now
simplescreenrecorder-2024-11-19_21.08.33.mkv.mp4

any idea on how to have a linear output instead of the one of wget with "dots" (while for me, with wget 1.x, the output should be with show-progress, so a bar)?

If you have not seen well in the video, I used

"$argpath"/AM-updater 2>&1 | grep "%"

instead of the one you all have now

"$argpath"/AM-updater >/dev/null 2>&1

any suggestion is wellcome

the behaviour changes because wget 1.x is piped against grep, so the output changes to the default one of wget 1.x

for wget the default output/progre status is in "dots", while in wget2 is a bar... I have not tested this in my VM of Fedora 40 (that uses wget as symlink to wget2) because I tested s o many times that I finished API calls to github, and being a VM, it uses host network as native. But I don't think that I would get more progresses for this.

I supose that it would be beter if I add a "flag", like in -i.... maybe the --debug flag to show the output for who wants to see it.

ivan-hc added a commit that referenced this issue Nov 20, 2024
...new flag "--debug" to see the output of the AM-updater scripts when running

fix #1106 (comment)
@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

I added the ability to use the --debug flag to see the output of AM-updater scripts. You will see the full output.

If you want to help me speed up the release, go into developer mode and update AM

am --devmode-enable
am -s

after that, do some test updates, you can also use the --debug flag to update only selected apps. You can also combine it with the --apps flag to update only apps. And of course it can be used with -u and without any other arguments.

To exit developer mode, run this command

am --devmode-disable

IMPORTANT, if you have topgrade installed, test with that as well.

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

This is the behaviour

simplescreenrecorder-2024-11-20_07.28.34.mkv.mp4

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

Just done a quick test with Topgrade, no issues here

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

@Premjit-Developer let me know if this will fix your issue.

ivan-hc added a commit that referenced this issue Nov 20, 2024
* Add flags support for the "-u" or "update" option...

...new flag "--debug" to see the output of the AM-updater scripts when running

fix #1106 (comment)

* Update README.md

* More clean update process
@Premjit-Developer
Copy link
Author

Thank you for your effort in implementing this update feature. However, as I mentioned earlier, when using the update feature on a program for the second time, it does not clear the temporary data of that program. Additionally, why not display the info screen directly without requiring the --debug flag?

update.check.mp4

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

why not display the info screen directly without requiring the --debug flag?

You may not like the answer, but it's purely for aesthetics. I like having a clean and non-invasive output. Unfortunately, from what I know about BASH, putting together aesthetics and parallel updates is difficult. When I had applications that updated one at a time, everything was more pleasant to look at, but since I introduced parallel updates, I couldn't make them coexist with aesthetics, and the messages end up overlapping, as you may have seen in one of the first videos of this issue.

as I mentioned earlier, when using the update feature on a program for the second time, it does not clear the temporary data of that program.

Just found the fix for this

ivan-hc added a commit that referenced this issue Nov 20, 2024
...fix re-updating where an update is broken does not creates the tmp directory

fix #1106 (comment)
@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

this whas happening because of this

Yes, And also If a user cancels the update, the partially updated program remains in the temp folder. To ensure consistency, the temp folder should be cleared when rechecking for updates.

this is already covered by this function

function _clean_all_tmp_directories_from_appspath() {
	for arg in $ARGPATHS; do
		if test -d "$arg"/tmp; then
			rm -Rf "$arg"/tmp && echo " ✔ Removed $arg/tmp"
		fi
	done
}

this runs also when am -u starts

function _use_update() {
	_online_check
	_update_github_api_key_in_the_updater_files
	_clean_all_tmp_directories_from_appspath >/dev/null
	case $2 in
	''|'--apps')
		_clean_amcachedir
		_update_list_updatable_apps
[ ... ]

this function is also a part of am -c

but I not noticed that the function uses _determine_args but only when am -c runs, so I added it in that function, like this

function _clean_all_tmp_directories_from_appspath() {
	_determine_args
	for arg in $ARGPATHS; do
		if test -d "$arg"/tmp; then
			rm -Rf "$arg"/tmp && echo " ✔ Removed $arg/tmp"
		fi
	done
}

run am -s and then retry, this should fix your issue.

And let me know if this works now.

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 20, 2024

You should update to Appman 9.1.2-1

this is what I changed 1f24813

@Premjit-Developer let me know

@Premjit-Developer
Copy link
Author

You should update to Appman 9.1.2-1

this is what I changed 1f24813

@Premjit-Developer let me know

It is working correctly.

@ivan-hc
Copy link
Owner

ivan-hc commented Nov 21, 2024

It is working correctly.

Thanks for reporting this bug, it was a valuable feedback.

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 a pull request may close this issue.

4 participants