GithubHelp home page GithubHelp logo

My saga installing Krita about am HOT 63 CLOSED

MauricioLucas avatar MauricioLucas commented on June 16, 2024 1
My saga installing Krita

from am.

Comments (63)

MauricioLucas avatar MauricioLucas commented on June 16, 2024 2

Analyzing the provided script, there are several areas where security and efficiency can be improved. Below are the suggested changes with explanations for each. The focus is on enhancing security measures, code readability, and maintainability.

1. Use More Secure Bash Shebang

Starting with a more precise shebang to ensure the script runs with bash in a more predictable manner.

#!/bin/bash

2. Quote Variables to Prevent Word Splitting and Globbing

Quote variables to handle spaces and special characters more reliably.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

3. Validate External Input

It's crucial to validate any external input to the script, including directories and URLs, to prevent command injection and other vulnerabilities.

4. Use HTTPS Where Possible

Ensure all URLs use HTTPS to secure the data in transit.

export AMCATALOGUEMARKDOWNS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/apps"
export AMCATALOGUEICONS="https://raw.githubusercontent.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/main/icons"

5. Avoid Using sudo Inside Scripts

Using sudo inside scripts can be risky. It's better to instruct the user to run the script with the necessary permissions or to elevate permissions only for specific commands that need it, after careful validation.

6. Check for Dependencies Early

Move the dependency check to the beginning of the script to fail fast if requirements are not met, improving user experience and script reliability.

7. Use More Robust Online Check

Improve the online check function to handle temporary network issues and retry logic more gracefully.

8. Securely Handle Temporary Files

Use system-provided directories for temporary files to avoid potential conflicts or security issues with hardcoded paths.

9. Validate Directories and Filenames

Before using user input for file or directory names, validate them to avoid directory traversal vulnerabilities.

10. Properly Scope Variables

Limit the scope of variables by using local where possible, especially in functions, to avoid unintended side effects.

11. Use Functions for Repeated Logic

Abstract repeated logic into functions to improve code readability and maintainability.

12. Implement Error Handling

Add error handling throughout the script, especially after commands that can fail, to ensure the script exits gracefully or takes corrective action when something goes wrong.

13. Avoid Direct Execution of User Input

If the script executes commands based on user input, ensure the input is strictly validated or use safer alternatives to direct execution.

14. Update and Secure File Permissions

Ensure that any files or directories created by the script have appropriate permissions set to avoid exposing sensitive information.

15. Use More Secure File Download Methods

When downloading files, use curl or wget with options that verify SSL certificates and fail on server errors to ensure secure and reliable downloads.

Example Improvements

Here's an example of how to implement some of these suggestions:

# Improved online check with retries
_online_check() {
    local retries=5
    for ((i=0; i<retries; i++)); do
        if wget -q --tries=3 --timeout=20 --spider https://github.com; then
            return 0
        fi
        sleep 2
    done
    echo -e "\n $AMCLI is offline, please check your internet connection and try again\n"
    exit 1
}

# Use local and quoted variables
function _am() {
    local AMCLI="am"
    local AMCLIPATH="$AMCLI"
    local SUDOCOMMAND=""
    local COMPLETIONPATH="/etc/bash_completion.d"
    local COMPLETIONFILE="am-completion.sh"
    local APPSPATH="/opt"
    local AMPATH="$APPSPATH/$AMCLI"
    mkdir -p "$AMPATH/.cache" "$AMPATH/modules"
}

These suggestions are starting points for improving the script. Depending on the specific requirements and environment, further enhancements may be necessary.

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024 1

After many attempts, I discovered the cause of the problem. I have two other users with sudo permission, and I updated and installed other programs through them. After consolidating everything into just one user:group, I still didn't succeed using the commands, and AM remained outdated. So, I manually removed AM, and 'almost' everything went well, but some errors persist.

I'll take a break, and after resolving them, I'll come back to generate a report.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024 1

@Samueru-sama @MauricioLucas what about adding a warning like this?

# Determine system architecture and current user
export arch="$HOSTTYPE"
export currentuser="$USER"
if [ "$AMCLI" == am ]; then
	ampathowner=$(ls -ld /opt/am | awk 'NR==1 {print $3}')
	if [ "$ampathowner" != "$currentuser" ]; then
		echo ' ๐Ÿ’€ ERROR: you are not the owner of /opt/am, so you cannot use "AM"'
		echo '--------------------------------------------------------------------------'
		echo ' The user that have installed "AM" on this system is "'"$ampathowner"'"'
		echo ' you are only allowed to use the installed apps, not to manage them.'
		echo '--------------------------------------------------------------------------'
		echo ' Please, contact "'"$ampathowner"'" to change the ownership of /opt/am or'
		echo ' consider using "AppMan" instead, see https://github.com/ivan-hc/AppMan'
		echo '--------------------------------------------------------------------------'
		exit
	fi
fi

Istantanea_2024-04-23_12-42-11

from am.

Samueru-sama avatar Samueru-sama commented on June 16, 2024 1

I want to add that I can't make the script for the pre-alpha version of krita because the website says that nightly builds are down.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024 1

@zen0bit in this case we also need to allow only users in "sudo" to edit files installed with AM

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024 1

so... now only the main installer is left. Normal users should not manage the following files and directories:

  • APP-MANAGER
  • remove
  • modules
  • cache

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024 1

I apologize for my delayed response, I was caught up with a significantly overdue task and couldn't devote the same level of attention you extended to me.

I figured out how everything got so complicated. I had changed the automatic login from the user "lucas" to "mao," and even though I was logged in as lucas, when using SUDO in the terminal, the files were created with the user and group "mao." When using sudo, the files were created with the user I had set in /etc/lightdm/lightdm.conf.

When I deleted and reinstalled AM, the new files were owned by user "mao" and group "mao."

After understanding and restoring this, the installation worked correctly.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

hi and thanks, I can't reproduce the issue, is your CLI updated to the last version (am -s or am -u)?

Istantanea_2024-04-22_14-29-07

as you can see, I've no strange outputs and the app is in place (apart the icon, missing in the menu)

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I'm on Debian Testing, I use BASH

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

also, krita acts normally (have you got libfuse2 installed? these old AppImages need this library)

Istantanea_2024-04-22_14-35-51

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I've thested this also with AM instead of AppMan, using the option --debug

am -i --debug krita

I only had the output of "wget" and a error about "mv" that have not found the .desktop file in one of the places the script searches for... but the installation is correct as well

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024
$am -i krita

mv: unable to get status of './tmp/krita': No such file or directory
chmod: cannot access './krita': No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
โ—† "KRITA" INSTALLED (1 MB OF DISK SPACE)
rm: cannot remove '/opt/am/.cache/krita': No such file or directory

these are errors during the installation, it seems that the installation process have not found the installation script "$arg" (in your case is krita)

$ wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL && chmod a+x ./INSTALL && sudo ./INSTALL^C

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

   >>  Enjoy your applications without thinking about anything else   <<   
  
  -----------------------------------------------------------------------

  SITE: https://github.com/IVAN-HC/AM-APPLICATION-MANAGER

what is that "^C" after INSTALL at first line?

$ am -l
grep: /opt/am/x86_64-apps: File or directory not found
cat: /opt/am/x86_64-apps: File or directory not found

 YOU HAVE INSTALLED 30 APPLICATIONS OUT OF  AVAILABLE

 LIST OF THE  APPLICATIONS AVAILABLE IN THE 'AM' REPOSITORY:
(END)
$am -q krita

 SEARCH RESULTS FOR "KRITA" IN THE LIST OF AVAILABLE PROGRAMS:

grep: /opt/am/x86_64-apps: No such file or directory

your errors about "/opt/am/x86_64-apps" are because AM have not a list of applications (that instead should be available in the moment you run -l and -q (you need an internet connection, at least the first time), this is really strange.

All the above look alike a situation in which your PC have no internet connection.

and this is how they should act without internet
Istantanea_2024-04-22_14-53-23

it seems that you have no access to github in general, from your terminal.

I can't say that this is a limit to github APIs access per hour, because scripts and list are direct links, no strange mechanisms to find the URL from github APIs... also Krita is not hosted on github but on another domain.

All this is really strange

from am.

Samueru-sama avatar Samueru-sama commented on June 16, 2024

(apart the icon, missing in the menu)

Fixed.

and a suggestion to also include the pre-alpha version

Will take a look at that later in the day, if it is easy it will be added as well.

EDIT: How do you get the nightly builds? Because the krita website has this message:

image

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

the download of krita during the installation is pretty slow... I think there is something on their website that made it slow, I've seen this also with inkscape until yesterday

from am.

Samueru-sama avatar Samueru-sama commented on June 16, 2024

the download of krita during the installation is pretty slow... I think there is something on their website that made it slow, I've seen this also with inkscape until yesterday

It wasn't slow on my end. It downloaded in like 30 seconds.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I've installed it 3-4 times with both am and appman and sometime the download was 8 MB/s .... sometime 500 KB/s

Always starts slow, then it decides to run fast or slow. This is the disadvantage of downloading from the upstream developer's site sometime... I'm italian, and the slower ones come from China and Japan.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

@MauricioLucas keep me updated if something is changed.

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

hi and thanks, I can't reproduce the issue, is your CLI updated to the last version (am -s or am -u)?

"I've always updated using 'am -u,' and after reading your response, I also used 'am -s,' and this was the output that appeared in the terminal.

lucas@Duvale:~$ am -s
-----------------------------------------------------------------------
 Check for any changes between the installation scripts
 in the repository and those used previously...
/opt/am/.cache/0ad-latest: Permission denied
cat: /opt/am/.cache/0ad-latest: File or directory not found

 The installer of 0ad-latest has been changed! 
 See https://github.com/ivan-hc/AM-Application-Manager/blob/main/programs/x86_64/0ad-latest
/opt/am/.cache/bforartists: Permission denied
cat: /opt/am/.cache/bforartists: File or directory not found

 The installer of bforartists has been changed! 
 See https://github.com/ivan-hc/AM-Application-Manager/blob/main/programs/x86_64/bforartists
... (similar messages for other applications) ...
-----------------------------------------------------------------------

 SYNCHRONIZING "AM" VERSION 5.3-3...

mv: cannot get status of '/opt/am/.cache/APP-MANAGER': File or directory not found
 THE "AM" SCRIPT IS NOW UPDATED TO VERSION 5.3-3! 

That's when I realized that at some point, the AM stopped updating because it's already at version 6.6.2. It was an oversight on my part not to have checked that before reporting the error.

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

also, krita acts normally (have you got libfuse2 installed? these old AppImages need this library)

Yes, I've been using Krita for a long time, and I have 'libfuse2' because many programs use this library. It's a standard part of Linux Mint.

lucas@Duvale:~$ sudo apt install libfuse2
libfuse2 is already the newest version (2.9.9-5ubuntu3).
0 upgraded, 0 newly installed, 0 to remove."

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024
$ wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL && chmod a+x ./INSTALL && sudo ./INSTALL^C

what is that "^C" after INSTALL at first line?

This was an error in the message editing, when you copy text from the terminal using Ctrl+C it does that. Don't worry, I used the command line correctly.

For some reason that I haven't identified, using the installation command doesn't overwrite the files from the previous installation.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I don't really understand why you have messages like this:

/opt/am/.cache/0ad-latest: Permission denied

you should have privileges as normal user in /opt/am (no sudo needed there)

have you installed it using the root shell or something?

All these problems are definitelly related to the fact that you have no permissions in /opt/am, and this is strange.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

in the INSTALL script there is a command

currentuser=$(who | awk '{print $1}')
chown -R $currentuser /opt/am 2> /dev/null

this allows "currentuser" (i.e. you) to have privileges in that directory.

I can only explain this as an attempt to install it without "chown" (that is pretty impossible) or using a different account from the one you are using now.

Have you got the same issue using AppMan? https://github.com/ivan-hc/AppMan

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I've done tests on a VM by adding two accounts and worked, all I had to do is to remove "currentuser" reverences in the INSTALL script an the install.am module.

Since next release you and other users of the same machine will be able to update the AM and all apps, and (if "SUDO" users) also to install the apps.

The installation process will give you and other users all needed permissions to /opt/am

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

sorry, I've just noticed that not all permissions are allowed on this release.

I was able to add files but not to remove them. I was betrayed by some menus on my UI.

There is still some work to do.

I'm really sorry.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I'd like to add permissions to multiple users... but for security reasons, it seems to be more secure not to allow different users to use AM and suggest AppMan instead.

I was working on a function to add to the CLI

# Determine system architecture and current user
export arch="$HOSTTYPE"
export currentuser="$USER"
if [ "$AMCLI" == am ]; then
	ampathowner=$(ls -ld /opt/am | awk 'NR==1 {print $3}')
	if [ "$ampathowner" != "$currentuser" ]; then
		echo ' ๐Ÿ’€ ERROR: you're not the owner of /opt/am, you can't use "AM"'; exit
	fi
fi

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I'm not good in manage permission like this, in my attempt of yesterday evening I've tried with

chmod -R 0777 /opt/am

but I was unable to run simple commands, also on installed apps.

I really need help here.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

@MauricioLucas this is all I can do, sorry

#477

it wasn't exactly what I wanted to do with "AM", but I think for system security reasons it's the best choice to make.

The use of AM and the administration of its installed apps will only be enabled for the user who installed "AM" the first time.

Non-privileged users using the same system will be advised to ask the administrator to change ownership of /opt/am, or at least be advised to use "AppMan" as alternatives.

The use of apps installed with "AM" will be open to everyone, but their updating or any modifications... but also the consultation of the lists... will be entirely at the discretion of the owner of /opt/am or the "root" user ".

Is this a good choice for you?

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

@Samueru-sama I'd like to have your opinion too about #477

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

Hey folks, I've finally managed to made "AM" work for all users of the system:

I've removed the "$currentuser" environment variable, now all directories (in "AM") will belong to "root" but with all permissions read-write for alla users:

  • privileged users are the ones that can install/remove the apps
  • unprivileged users can only update/edit them

However, I've doubts about security issues if unprivileged users can aceede the files of the applications.

How you see all this? @Samueru-sama @MauricioLucas @zen0bit

All changes are in dev:

main...dev

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I've done all tests on a VM of Debian with two privileged accounts and one unprivileged.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I've tested the change in the install.am module also on AppMan, no issues here.

Istantanea_2024-04-23_22-08-32 png

these instead are the permissions of two apps directories seen from the unprivileged account anda directory manually created by the unprivileged user into a directory of an application installed by a privileged one:

Istantanea_2024-04-23_22-13-23 png

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

The unprivileged user can't install/remove the apps, but can update everything and consult the lists:

simplescreenrecorder-2024-04-23_22.17.48.mkv.mp4

I don't know why the AM-updater of deadbeef-appimage (your app, @Samueru-sama ) is always updating.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

But updates are working, also as unprivileged users

simplescreenrecorder-2024-04-23_22.21.36.mkv.mp4

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

Now all depends on you, @MauricioLucas is this update enough to satisfy your request?

@zen0bit @Samueru-sama any tip?

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

Permissions between an app installed with AM in main and the one installed with the new module (anydesk) and one of the files into it (on my machine):

Istantanea_2024-04-23_22-31-08 png

from am.

zen0bit avatar zen0bit commented on June 16, 2024

After short reading here..

I think that apps installed with AM should not be updated by users not in sudo group.

Was thought that AM already install apps for all users.
Not really tried since I am only user...
mistake

PS: I tried to look in update module. But can't get my head wrap around
Tried make indentation consistent and right, but I am still missing something...

from am.

zen0bit avatar zen0bit commented on June 16, 2024

@zen0bit in this case we also need to allow only users in "sudo" to edit files installed with AM

Should be like that no?
I don't see difference between installing/updating (both modify files)

Apps should be usable by all users on system.
Not updatable, for that sudo rights needed

If you don't have rights use appman then... (For installing/updating own apps)
right?

But AM should work without sudo!
Just that part which needs sudo, will ask for password

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

with this commit I've solved, @zen0bit 61e0f3c

  • normal unprivileged users have no perzissions towrite in the apps directories, they are read only for them
  • all users of "sudo" group can install, remove and manage them from admin to admin, with no limits

from am.

Samueru-sama avatar Samueru-sama commented on June 16, 2024

Apps should be usable by all users on system.
Not updatable, for that sudo rights needed

I told @ivan-hc the same thing here but he wants to make it different. ๐Ÿ™ƒ

Well it looks like it works now anyway.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

the APP-MANAGER script cannot be updated due to ownership (root), also if privileged users have RW permissions

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

it seems that a main administrator must exist to update the CLI ๐Ÿ˜ฎโ€๐Ÿ’จ

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

its a mess, I cannot figure out how to solve

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I have to add a main administrator, I should reintroduce "$currentuser"

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

its too much work to do here,when I fix a permission I have issues on another

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I think I'll left AM as an open client for all users, as I've said at #466 (comment) , but updates and permissions on applications will be allowed only for "sudo" users #466 (comment)

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

All these changes are a total failure... also updating all modules, by resetting everything at the "working" comit above, with all screenshots, gave errors.

Its enough.

I've nothing to do bus disable the usage of AM by other users other than the main one.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

Believe me, I've tried in every way, and even the most seemingly feasible solution ended up not succeeding without a hitch.

The only possible and logical solution is to allow a single system administrator to be able to manage "AM" in all ways.

This is also because more system administrators would risk not to be able to have the necessary privileges, for example, to update the CLI to the latest version.

You might as well prevent the use of the CLI by users other than the one who installed "AM". For everything else there is "AppMan", as I had predicted at the beginning.

Istantanea_2024-04-24_03-23-16

Best not to play too much with these admin privileges, folks. This definitive approach will certainly favor the use of "AM" in public facilities, such as schools. All users will be able to use the installed apps, but which ones to install and how to update them will be up to the administrator.

I'm closing.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

#480

# Determine system architecture and current user
export arch="$HOSTTYPE"
export currentuser="$USER"
if [ "$AMCLI" == am ]; then
	ampathowner=$(ls -ld /opt/am | awk 'NR==1 {print $3}')
	if [ "$ampathowner" != "$currentuser" ]; then
		echo ' ๐Ÿ’€ ERROR: you are not the owner of /opt/am, so you cannot use "AM"'
		echo '--------------------------------------------------------------------------'
		echo ' The user that have installed "AM" on this system is "'"$ampathowner"'"'
		echo ' you are only allowed to use the installed apps, not to manage them.'
		echo '--------------------------------------------------------------------------'
		echo ' Please, contact "'"$ampathowner"'" to change the ownership of /opt/am or'
		echo ' consider using "AppMan" instead, see https://github.com/ivan-hc/AppMan'
		echo '--------------------------------------------------------------------------'
		exit
	fi
fi

Istantanea_2024-04-23_12-42-11

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

and a suggestion to also include the pre-alpha version

Will take a look at that later in the day, if it is easy it will be added as well.

EDIT: How do you get the nightly builds? Because the krita website has this message:

The link is this:
https://cdn.kde.org/ci-builds/graphics/krita/master/linux/

And I made this script:

#!/bin/bash

# Define the base URL
base_url="https://cdn.kde.org/ci-builds/graphics/krita/master/linux/"

# Use wget to fetch the listing to stdout and grep to filter the file link
file_url=$(wget -q -O - -T 10 ${base_url} | grep -oP 'href="\Kkrita-.*?-prealpha-.*?-x86_64.appimage(?=")' | sort -V | tail -n 1)

# Check if file_url is not empty
if [[ ! -z "$file_url" ]]; then
    # Complete the URL and download with wget, using -c to continue incomplete downloads and -T 10 to set a timeout
    wget -c -T 10 "${base_url}${file_url}" -O "${file_url}"
else
    echo "Failed to find the file."
fi

from am.

Samueru-sama avatar Samueru-sama commented on June 16, 2024

I will leave this screenshot here so hopefully one day @ivan-hc decides to do the proper fix:

image

Notice how AM-updater didn't ask for my sudo password even though I chown /opt/htop to root, this is because I have samuel ALL=NOPASSWD: /opt/*/AM-updater in sudoers, and you can also see that ./remove did ask for the password since it isn't in sudoers.

Not to mention that this approach fixes a possible issue that is that if the user tires to run ./remove without sudo it will still remove the application in /opt/$APP including the remove itself, but it wont remove the symlink and the .desktop since that needs root privileges.

(If you wonder why I'm using doas in some of the steps, that is because I have sudo configured to not ask for the password once it is entered once during the current terminal session).

(Also I have no idea what that dbus-launch errors is, the app updated anyway).

The link is this:
https://cdn.kde.org/ci-builds/graphics/krita/master/linux/

Thanks for that, will look into adding it.

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

Now:

$am -s
-----------------------------------------------------------------------------
 Checking for changes of the installation scripts in the online database...
 โ—† Changed https://github.com/ivan-hc/AM/blob/main/programs/x86_64/freecad
 โ—† Changed https://github.com/ivan-hc/AM/blob/main/programs/x86_64/scribus
 โ—† Changed https://github.com/ivan-hc/AM/blob/main/programs/x86_64/wine-stable
-----------------------------------------------------------------------------
 Check for updates in modules...
 โ—† Downloading database.am (not previously installed)...
chmod: could not access './database.am': No such file or directory
cat: ./database.am: No such file or directory
 โ—† Updating database.am...
mv: could not obtain status from 'tmp/*.am': No such file or directory
 โ—† Updating install.am...
mv: could not obtain status from 'tmp/*.am': No such file or directory
 โ—† Downloading update.am (not previously installed)...
chmod: could not access './update.am': No such file or directory
cat: ./update.am: No such file or directory
 โ—† Updating update.am...
mv: could not obtain status from 'tmp/*.am': No such file or directory
-----------------------------------------------------------------------------

mv: could not obtain status from '/opt/am/.cache/APP-MANAGER': No such file or directory
 โ—† "AM" IS ALREADY UPDATED, CURRENT VERSION 6.6.2-1

 See https://github.com/ivan-hc/AM/commits/main

Remembering that I kept the already installed packages, I deleted the Am folder and carried out the installation from the clone of the GitHub directory.

It would be interesting to include the option "-T 10" in the connectivity check with github.com. Several times the script got stuck, and I had to terminate it with Ctrl+C; it just sits there, and the user doesn't know if it's working or stopped.
Only then did I use the command am -s.

In the download options, I would use "-c -T 10" as I did in the script I pasted earlier.

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

Logging and Debugging the Installation:

$ sudo ./INSTALL
[sudo] senha para lucas:       
#!/bin/sh -vx

# CREATING THE MAIN FOLDER FOR "AM"
mkdir -p /opt/am/.cache /opt/am/modules
+ mkdir -p /opt/am/.cache /opt/am/modules
cd /opt/am
+ cd /opt/am

# CREATE THE SCRIPT NEEDED TO UNINSTALL "AM"
rm -R -f /opt/am/remove
+ rm -R -f /opt/am/remove
echo "#!/bin/sh
rm -R -f /usr/local/bin/am /opt/am /etc/bash_completion.d/am-completion.sh" >> /opt/am/remove
+ echo #!/bin/sh
rm -R -f /usr/local/bin/am /opt/am /etc/bash_completion.d/am-completion.sh
chmod a+x /opt/am/remove
+ chmod a+x /opt/am/remove

# DOWNLOAD THE MAIN SCRIPT
wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/APP-MANAGER
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/APP-MANAGER
chmod a+x /opt/am/APP-MANAGER
+ chmod a+x /opt/am/APP-MANAGER

# LINK THE MAIN SCRIPT TO A KNOWN PATH
ln -sf /opt/am/APP-MANAGER /usr/local/bin/am
+ ln -sf /opt/am/APP-MANAGER /usr/local/bin/am

# DOWNLOAD THE LIST OF THE AVAILABLE PROGRAMS
arch=$(uname -m)
+ uname -m
+ arch=x86_64
wget ln -s -q "https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/programs/$arch-apps"
+ wget ln -s -q https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/programs/x86_64-apps
/usr/bin/wget: opรงรฃo invรกlida -- โ€œsโ€
Uso: wget [OPร‡รƒO]... [URL]...

Tente "wget --help" para mais opรงรตes.

# DOWNLOAD MODULES
MODULES=$(wget -c -T 10 -q https://api.github.com/repos/ivan-hc/AM/contents/modules -O - | grep download_url | cut -d '"' -f 4)
+ wget -c -T 10 -q https://api.github.com/repos/ivan-hc/AM/contents/modules -O -
+ grep download_url
+ cut -d " -f 4
+ MODULES=https://raw.githubusercontent.com/ivan-hc/AM/main/modules/clean.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/database.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/devtools.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/download.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/files.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/help.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/install.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/launcher.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/no-updates.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/nolibfuse.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/remove.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/rollback.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/sandboxes.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/sync.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/template.am
https://raw.githubusercontent.com/ivan-hc/AM/main/modules/update.am
for module in $MODULES; do
	for v in $module; do
		cd /opt/am/modules
		mkdir tmp
		cd tmp
		wget -c -T 10 -q "$v"
		cd ..
		mv tmp/*.am ./
		chmod a+x ./*.am
		rmdir tmp
	done
done
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/clean.am
+ cd ..
+ mv tmp/clean.am ./
+ chmod a+x ./clean.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/database.am
+ cd ..
+ mv tmp/*.am ./
mv: nรฃo foi possรญvel obter estado de 'tmp/*.am': Arquivo ou diretรณrio inexistente
+ chmod a+x ./clean.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/devtools.am
+ cd ..
+ mv tmp/devtools.am ./
+ chmod a+x ./clean.am ./devtools.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/download.am
+ cd ..
+ mv tmp/download.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/files.am
+ cd ..
+ mv tmp/files.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/help.am
+ cd ..
+ mv tmp/help.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/install.am
+ cd ..
+ mv tmp/install.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/launcher.am
+ cd ..
+ mv tmp/launcher.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/no-updates.am
+ cd ..
+ mv tmp/no-updates.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/nolibfuse.am
+ cd ..
+ mv tmp/nolibfuse.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/remove.am
+ cd ..
+ mv tmp/remove.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am ./remove.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/rollback.am
+ cd ..
+ mv tmp/rollback.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am ./remove.am ./rollback.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/sandboxes.am
+ cd ..
+ mv tmp/sandboxes.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am ./remove.am ./rollback.am ./sandboxes.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/sync.am
+ cd ..
+ mv tmp/sync.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am ./remove.am ./rollback.am ./sandboxes.am ./sync.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/template.am
+ cd ..
+ mv tmp/template.am ./
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am ./remove.am ./rollback.am ./sandboxes.am ./sync.am ./template.am
+ rmdir tmp
+ cd /opt/am/modules
+ mkdir tmp
+ cd tmp
+ wget -c -T 10 -q https://raw.githubusercontent.com/ivan-hc/AM/main/modules/update.am
+ cd ..
+ mv tmp/*.am ./
mv: nรฃo foi possรญvel obter estado de 'tmp/*.am': Arquivo ou diretรณrio inexistente
+ chmod a+x ./clean.am ./devtools.am ./download.am ./files.am ./help.am ./install.am ./launcher.am ./no-updates.am ./nolibfuse.am ./remove.am ./rollback.am ./sandboxes.am ./sync.am ./template.am
+ rmdir tmp

# ENABLE NON-ROOT PERMISSIONS TO THE MAIN FOLDER FOR THE CURRENT USER
currentuser=$(who | awk '{print $1}')
+ who
+ awk {print $1}
+ currentuser=lucas
lucas
chown -R $currentuser /opt/am 2> /dev/null
+ chown -R lucas lucas /opt/am

# ADD THE BASH COMPLETION SCRIPT
echo '#!/usr/bin/env bash' >> /opt/am/am-completion.sh; echo 'complete -W "$(cat /opt/am/list 2>/dev/null)" am' >> /opt/am/am-completion.sh
+ echo #!/usr/bin/env bash
+ echo complete -W "$(cat /opt/am/list 2>/dev/null)" am
chmod a+x /opt/am/am-completion.sh
+ chmod a+x /opt/am/am-completion.sh
rm -R -f /opt/am/remove; echo '#!/bin/sh' >> /opt/am/remove
+ rm -R -f /opt/am/remove
+ echo #!/bin/sh
echo 'rm -R -f /usr/local/bin/am /opt/am /etc/bash_completion.d/am-completion.sh' >> /opt/am/remove
+ echo rm -R -f /usr/local/bin/am /opt/am /etc/bash_completion.d/am-completion.sh
chmod a+x /opt/am/remove; chown -R $currentuser /opt/am/remove 2>/dev/null 
+ chmod a+x /opt/am/remove
+ chown -R lucas lucas /opt/am/remove
if test -f /etc/bash_completion.d; then
	mv /opt/am/am-completion.sh /etc/bash_completion.d/
else
	mkdir -p /etc/bash_completion.d; sudo mv /opt/am/am-completion.sh /etc/bash_completion.d/
fi
+ test -f /etc/bash_completion.d
+ mkdir -p /etc/bash_completion.d
+ sudo mv /opt/am/am-completion.sh /etc/bash_completion.d/

# SHOW THE MESSAGE
echo '

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024
lucas@Duvale:/opt/am$ ls -la
ls -AolF --color=auto
total 40
drwxr-xr-x  4 lucas  4096 abr 23 23:19 ./
drwxrwxrwx 44 root   4096 abr 23 22:22 ../
-rwxr-xr-x  1 lucas 15783 abr 23 22:22 APP-MANAGER*
drwxr-xr-x  2 lucas  4096 abr 23 23:19 .cache/
drwxr-xr-x  2 lucas  4096 abr 23 22:23 modules/
-rw-rw-r--  1 lucas   306 abr 23 23:19 options
-rwxr-xr-x  1 lucas    85 abr 23 22:23 remove*

lucas@Duvale:/opt/am$ ls -la /opt/am/.cache/
ls -AolF --color=auto
total 8
drwxr-xr-x 2 lucas 4096 abr 23 23:49 ./
drwxrwxrwx 4 lucas 4096 abr 23 23:49 ../

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

@Samueru-sama @MauricioLucas what about adding a warning like this?

# Determine system architecture and current user
export arch="$HOSTTYPE"
export currentuser="$USER"
if [ "$AMCLI" == am ]; then
	ampathowner=$(ls -ld /opt/am | awk 'NR==1 {print $3}')
	if [ "$ampathowner" != "$currentuser" ]; then
		echo ' ๐Ÿ’€ ERROR: you are not the owner of /opt/am, so you cannot use "AM"'
		echo '--------------------------------------------------------------------------'
		echo ' The user that have installed "AM" on this system is "'"$ampathowner"'"'
		echo ' you are only allowed to use the installed apps, not to manage them.'
		echo '--------------------------------------------------------------------------'
		echo ' Please, contact "'"$ampathowner"'" to change the ownership of /opt/am or'
		echo ' consider using "AppMan" instead, see https://github.com/ivan-hc/AppMan'
		echo '--------------------------------------------------------------------------'
		exit
	fi
fi

You are correct, the installation power should be centralized in just one user. These are the directives of Linux, and differently, it is advisable that the person uses Windows. :-)

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024
$ am -q krita
/opt/am/modules/database.am: Permission denied
chmod: cannot access '/opt/am/modules/database.am': No such file or directory
/usr/local/bin/am: line 311: /opt/am/modules/database.am: No such file or directory
lucas@Duvale:~$ sudo am -u
[sudo] password for lucas:       
 ๐Ÿ’€ ERROR: you are not the owner of /opt/am, so you cannot use "AM"
--------------------------------------------------------------------------
 The user that installed "AM" on this system is "lucas"
 you are only allowed to use the installed apps, not to manage them.
--------------------------------------------------------------------------
 Please, contact "lucas" to change the ownership of /opt/am or
 consider using "AppMan" instead, see https://github.com/ivan-hc/AppMan
--------------------------------------------------------------------------
lucas@Duvale:~$ am -u
/opt/am/modules/update.am: Permission denied
chmod: cannot access '/opt/am/modules/update.am': No such file or directory
/usr/local/bin/am: line 311: /opt/am/modules/update.am: No such file or directory
lucas@Duvale:~$ 
lucas@Duvale:~$ am -i krita
 ############################################################################
 ##                                                                        ##
 ##                  START OF ALL INSTALLATION PROCESSES                   ##
 ##                                                                        ##
 ############################################################################

mv: cannot get status of './tmp/krita': No such file or directory
chmod: cannot access './krita': No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
grep: ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
sed: cannot read ./krita: No such file or directory
 โ—† "KRITA": starting installation script
grep: ./krita: No such file or directory
sudo: ./krita: command not found
 "KRITA" INSTALLED (1 MB OF DISK SPACE)                                   
rm: cannot remove '/opt/am/.cache/krita': No such file or directory
 ____________________________________________________________________________
 ############################################################################

                  END OF ALL INSTALLATION PROCESSES

             The following new programs have been installed:


 ############################################################################

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

Please remove and reinstall AM, also remove the already downloaded "INSTALL" script:

am -R am
wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL && chmod a+x ./INSTALL && sudo ./INSTALL

but remove any other app installed before. If you can't with AM, use the command:

sudo /opt/$appname/remove

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

Please remove and reinstall AM, also remove the already downloaded "INSTALL" script:

am -R am
wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL && chmod a+x ./INSTALL && sudo ./INSTALL

but remove any other app installed before. If you can't with AM, use the command:

sudo /opt/$appname/remove
wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL && chmod a+x ./INSTALL && sudo ./INSTALL
--2024-04-24 11:00:19--  https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8000::154, 2606:50c0:8001::154, 2606:50c0:8002::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8000::154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3824 (3,7K) [text/plain]
Saving to: โ€˜INSTALL.5โ€™

INSTALL.5                100%[===============================>]   3,73K  --.-KB/s    in 0s      

2024-04-24 11:00:20 (41,0 MB/s) - โ€˜INSTALL.5โ€™ saved [3824/3824]

During the execution of INSTALL, the script hung, which is when I realized that INSTALL.5 was what had been saved and that the only one with execution permission was INSTALL from last September. I deleted it, and the installation worked.

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

By ChatGPT 4

It appears you're encountering issues with executing a script that's part of a custom application manager, and the error messages indicate problems accessing necessary directories and files for its operation. The initial error suggests that the current working directory can't be accessed or does not exist, possibly caused by attempting to run the script in a directory that has been removed or moved.

Let's address the correction in two parts: first, adjusting the main script /opt/am/APP-MANAGER to ensure it can handle missing directories more robustly; second, reviewing the module script /opt/am/modules/database.am to identify and correct potential issues.

Corrections in the script /opt/am/APP-MANAGER

Reviewing the APP-MANAGER script shows it to be quite complex, setting up environment variables, checking dependencies, and defining functions. However, the reported error seems to be related to attempts to access directories that do not exist. One approach to mitigate this issue is to ensure all necessary directories exist before attempting to access or write to them.

Suggested Correction:

Before any operation that assumes the existence of specific directories, you could add checks and directory creations as necessary. For example, before attempting to access $AMPATH, ensure it exists:

# Check and create the $AMPATH directory if it does not exist
if [ ! -d "$AMPATH" ]; then
    mkdir -p "$AMPATH"
fi

Include this check at critical points in the script where directories are accessed or modified.

Corrections in the module script /opt/am/modules/database.am

The database.am script appears to be responsible for managing databases of applications and libraries, including listing installed and available apps. The reported error suggests the script attempts to access files or directories that do not exist, such as /opt/am/x86_64-apps.

Suggested Correction:

Ensure all referenced files and directories exist before attempting to read or write to them. For example, before attempting to download the app list to $AMPATH/$arch-apps, check if the $AMPATH directory exists and is accessible:

# At the start of _completion_lists
if [ ! -d "$AMPATH" ]; then
    echo "Directory $AMPATH not found. Creating..."
    mkdir -p "$AMPATH"
fi

Additionally, verify the existence of specific files before attempting operations like cat, grep, or wget that assume their presence:

# Before using files like $AMPATH/$arch-apps
if [ ! -f "$AMPATH/$arch-apps" ]; then
    echo "File $AMPATH/$arch-apps not found. Initializing..."
    # Initialize or download the file as necessary
fi

These corrections should help mitigate issues of non-existent files or directories, ensuring that the script creates or checks for the existence of necessary resources before proceeding with operations dependent on them.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

WOW, did ChatGTP tell you all this? Great!

I will follow the advice.

Is it working now?

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

Given the complexity and the broad nature of the improvements suggested, implementing all of them directly into the script excerpts you've provided would be quite extensive and might not fit into a single response due to the limitations of this format. However, I can illustrate how to start applying some of these improvements to the /opt/am/APP-MANAGER script with comments indicating the changes. This should provide a solid starting point for enhancing the script further along the lines suggested.

Please note, due to the nature of this platform, the following is a conceptual demonstration meant to guide the application of the improvements rather than a complete, ready-to-deploy script.

Example Modifications on /opt/am/APP-MANAGER

#!/usr/bin/env bash

# Improved error messages and input validation
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -z "$DIR" ]; then
    echo "Error: Failed to determine the script's directory."
    exit 1
fi

CLI=$(basename "$0")
AMVERSION="6.6.2-1"

# Improved portability: Use more portable methods for finding directories
SCRIPTDIR="$(if command -v xdg-user-dir &>/dev/null; then xdg-user-dir DESKTOP; else echo $HOME; fi)"

# Modularization: Splitting initialization into its own function
function initialize_dirs() {
    # Check and create directories if they do not exist
    for dir in "$AMPATH/.cache" "$AMPATH/modules"; do
        if [ ! -d "$dir" ]; then
            mkdir -p "$dir" || { echo "Failed to create directory $dir"; exit 1; }
        fi
    done
}

# Calling the new function
initialize_dirs

# Security: Validate directory paths to prevent potential command injection
function validate_directory() {
    local location=$1
    # Simple validation example; consider expanding for robustness
    if [[ "$location" =~ [^a-zA-Z0-9./_-] ]]; then
        echo "Invalid directory name: $location"
        exit 1
    fi
}

# Example use of the validate_directory function
validate_directory "$SOME_DIRECTORY"

# Improved UX: Adding progress indicators for long-running operations
function long_operation_example() {
    echo -n "Processing"
    for i in {1..5}; do
        echo -n "."
        sleep 1 # Simulating a long operation
    done
    echo " Done."
}

# Example use of improved UX function
long_operation_example

# Documentation: Adding help functionality
function print_help() {
    cat << EOF
Usage: $0 [options]

Options:
  -h, --help              Show this help message and exit
  -v, --version           Show version information

Description:
  This script provides a custom application management system.
EOF
}

# Parsing command-line arguments for help
case "$1" in
    -h|--help)
        print_help
        exit 0
        ;;
    -v|--version)
        echo "Version: $AMVERSION"
        exit 0
        ;;
    *)
        # Default case if no options match
        ;;
esac

# This is a conceptual snippet. You would need to integrate and expand these changes throughout your script.

This snippet demonstrates applying some of the suggested improvements:

  • Modularization: I've introduced the initialize_dirs function to encapsulate directory initialization logic.
  • Improved UX: The long_operation_example function simulates adding progress feedback for long operations.
  • Security: The validate_directory function is a basic example of input validation to improve security.
  • Documentation: The print_help function provides a simple help message, improving the script's usability.

To fully implement all the suggested improvements, you would need to systematically apply these principles throughout your entire script, considering the specific functionality and structure of your code.

WOW, did ChatGTP tell you all this? Great!

I will follow the advice.

Is it working now?

I still haven't found the time to test it. Understand that I committed the madness of getting married at 48 and having a child at 52. He is now 6 years old, and the money I always had to spare is now just a memory of the times when I was happy and didn't know it hahahaha.

from am.

ivan-hc avatar ivan-hc commented on June 16, 2024

I still haven't found the time to test it. Understand that I committed the madness of getting married at 48 and having a child at 52. He is now 6 years old, and the money I always had to spare is now just a memory of the times when I was happy and didn't know it hahahaha.

you have all my support, brother (I'm 38, btw)

anyway thanks for these tips, they are really valuable (even the ones about marriage lol). I'm making some changes to APP-MANAGER to make it less complex and more oriented towards security and system administrator use (the latter in "AM" mode).

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

With the help of GPT, I was already fighting with the shell, I hope it will be useful, this had suppressed several errors, but now I will start over doing this in the new installation:

Forgive me if my communication with you is slow, I am doing this in the little free time I have left, and yesterday I went to sleep almost at 4 AM fighting with these errors.

With the help of GPT I was already fighting with the shell:

I already made some changes, I changed this:

function _online_check(){
	if ! wget -q --tries=10 --timeout=20 --spider https://github.com; then
		echo -e "\n $AMCLI is offline, please check your internet connection and try again\n"
		exit
	fi
}	

that's why:

# _online_check Function
function _online_check(){
    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
        echo "Usage: _online_check <max_attempts> <timeout> <url>"
        return 2
    fi

    local max_attempts="$1"
    local timeout="$2"
    local url="$3"
    local attempt=1
    local success=false

    echo "Checking internet connection to $url..."
    while [ "$attempt" -le "$max_attempts" ]; do
        echo "Attempt $attempt of $max_attempts..."
        if wget -q --spider --tries=1 --timeout="$timeout" "$url"; then
            echo "Successfully connected to the internet."
            success=true
            break
        else
            echo "Connection failed, retrying..."
        fi
        ((attempt++))
    done

    if [ "$success" = false ]; then
        echo "Failed to verify internet connection after $max_attempts attempts."
        return 1
    else
        return 0
    fi
}

I added this:

# Another Online Check
if ! _online_check 10 20 "https://github.com"; then
    echo "Please check your internet connection and try again."
    exit 1
fi

I added this to the line 206


if [ -n "$SUDO_USER" ]; then
    currentuser="$SUDO_USER"
fi

replace wget -p with

download_with_retry
if [ -n "$missing_deps" ]; then

# Exit if any essential command is missing
if [ "${#missing_deps[@]}" -ne 0 ]; then
    printf "\nMissing essential commands: %s\nInstall the above and try again\n\n" "${missing_deps[*]}"
    exit 1
    
    ```

from am.

MauricioLucas avatar MauricioLucas commented on June 16, 2024

I believe this has resolved @ivan-hc

/opt/am/modules/sync.am

--- /opt/am/modules/sync.am
+++ /opt/am/modules/sync2.am
@@ -51,30 +51,31 @@
 echo "-----------------------------------------------------------------------------"
 echo -e " Check for updates in modules..."
 function _sync_modules(){
-	MODULES=$(wget -q $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/contents/modules -O - | grep download_url | cut -d '"' -f 4)
-	for v in $MODULES; do
-		cd $AMPATH/modules || return
-		MODULENAME=$(echo "$v" | sed 's:.*/::')
-		if ! test -f ./$MODULENAME; then
-			echo " โ—† Downloading $MODULENAME (not previously installed)..."
-			wget -q "$v"
-			chmod a+x ./$MODULENAME
-		fi
-		CURRENT=$(cat ./$MODULENAME)
-		SOURCE=$(wget -q "$v" -O -)
-		if [ "$CURRENT" == "$SOURCE" ]; then
-			echo -ne "\r" 2> /dev/null
-		else
-			echo " โ—† Updating $MODULENAME..."
-			mkdir tmp
-			cd tmp || return
-			wget -q "$v"
-			cd ..
-			mv tmp/*.am ./
-			chmod a+x ./*.am
-			rmdir tmp
-		fi
-	done
+    TMP_DIR="/tmp/am-modules-tmp"
+    mkdir -p "$TMP_DIR"
+    chmod 755 "$TMP_DIR"
+    
+    MODULES=$(wget -q $HeaderAuthWithGITPAT https://api.github.com/repos/ivan-hc/AM/contents/modules -O - | grep download_url | cut -d '"' -f 4)
+    for v in $MODULES; do
+        MODULENAME=$(echo "$v" | sed 's:.*/::')
+        TMP_FILE="$TMP_DIR/$MODULENAME"
+        wget -q "$v" -O "$TMP_FILE"
+        
+        if [ -f "$TMP_FILE" ]; then
+            if [ ! -f "$AMPATH/modules/$MODULENAME" ] || ! cmp --silent "$AMPATH/modules/$MODULENAME" "$TMP_FILE"; then
+                echo " โ—† Updating $MODULENAME..."
+                mv "$TMP_FILE" "$AMPATH/modules/$MODULENAME"
+            else
+                echo " โ—† $MODULENAME is already up to date."
+                rm "$TMP_FILE"
+            fi
+        else
+            echo "Erro ao criar o arquivo temporรกrio para $MODULENAME"
+        fi
+    done
+    
+# Clear the temporary directory after the operation
+    rm -r "$TMP_DIR"
 }
 
 if [[ "$AMREPO" = *://* ]]; then
@@ -82,20 +83,26 @@
 fi
 
 function _sync_amcli(){
-	echo "-----------------------------------------------------------------------------"
-  	_completion_lists
-	CURRENT_AM_VERSION=$($AMCLIPATH -v)
-	echo -ne '\n โ—† SYNCHRONIZING "'"$(echo $AMCLI | tr a-z A-Z)"'" VERSION '"$CURRENT_AM_VERSION"'...\r'; sleep 1
-  	rm -R -f $AMPATH/.cache/* 1>/dev/null; cd $AMPATH/.cache || return
-  	if [ $AMCLI == am ] 2>/dev/null; then
-  		wget -q $AMREPO/APP-MANAGER && chmod a+x ./APP-MANAGER
-  		cd ..
-  		mv $AMPATH/.cache/APP-MANAGER $AMPATH; chmod 777 $AMPATH
-  	else
-  		wget -q $AMREPO/APP-MANAGER -O appman && chmod a+x ./$AMCLI
-  		cd ..
-  		mv $AMPATH/.cache/$AMCLI $AMCLIPATH
-  	fi
+    echo "-----------------------------------------------------------------------------"
+    _completion_lists
+    CURRENT_AM_VERSION=$($AMCLIPATH -v)
+    echo -ne '\n โ—† SYNCHRONIZING "'"$(echo $AMCLI | tr a-z A-Z)"'" VERSION '"$CURRENT_AM_VERSION"'...\r'; sleep 1
+    rm -R -f $AMPATH/.cache/* 1>/dev/null; cd $AMPATH/.cache || return
+    if [ $AMCLI == am ] 2>/dev/null; then
+        wget -q $AMREPO/APP-MANAGER && chmod a+x ./APP-MANAGER
+        cd ..
+        # Check if the APP-MANAGER file exists before moving
+        if [ -f "$AMPATH/.cache/APP-MANAGER" ]; then
+            mv $AMPATH/.cache/APP-MANAGER $AMPATH; chmod 777 $AMPATH
+        fi
+    else
+        wget -q $AMREPO/APP-MANAGER -O appman && chmod a+x ./$AMCLI
+        cd ..
+        # Check if the APP-MANAGER file exists before moving
+        if [ -f "$AMPATH/.cache/$AMCLI" ]; then
+            mv $AMPATH/.cache/$AMCLI $AMCLIPATH
+        fi
+    fi
   	if [ ! "$CURRENT_AM_VERSION" == "$($AMCLIPATH -v)" ] ; then
  		echo -ne ' A new release of "'"$(echo $AMCLI | tr a-z A-Z)"'" is available, please wait...\r'
  		echo -e ' โ—† "'"$(echo $AMCLI | tr a-z A-Z)"'" IS NOW UPDATED TO THE BRAND NEW '"$($AMCLIPATH -v)"' VERSION!           \n\n  Replacement of version '"$CURRENT_AM_VERSION"' currently in use, COMPLETED!'

from am.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.