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

Several syntax errors on bash versions shipped in many distros #5

Open
lj3954 opened this issue Feb 5, 2024 · 8 comments
Open

Several syntax errors on bash versions shipped in many distros #5

lj3954 opened this issue Feb 5, 2024 · 8 comments

Comments

@lj3954
Copy link

lj3954 commented Feb 5, 2024

I currently have an Ubuntu 22.04-based system, with Bash 5.1.16 installed.

Line 13 causes the first issue. I'm not sure The formatting leaves BASE_DIR with a blank string regardless of where it's run from, so unless you're already within the quickget directory, the command will fail. Instead, $(dirname "${0}") could be used to find the directory quickget is stored in. Changing directories also should not be used unless absolutely necessary, as it could cause other unforeseen issues. Instead, each specific command should call the directory. Rather than running 'ls' after changing into the ${PLUGINS} directory, for example, you should use ls ${PLUGINS}.

All of the plugins are completely broken on Bash 5.1.16, but they do work on Bash 5.2.26. The error specifically is with the lines using the @k operator on an array. Here's the error a bash shell prior to version 5.2 will throw. ./quickget_plugins/alma.plug: line 48: ${editions[@]@k}: bad substitution. I believe this loop is what you need to achieve the same functionality in other bash versions.
for edition in "${!editions[@]}"; do
echo "${edition} ${editions[$edition]}"
done

I would like to see these issues fixed before I start to re-implement the OS and architecture support I've been working on. The original quickget requires a bash version of 4.0, this must at least work on bash versions prior to the very newest 5.2 to be able to replace it.

@lj3954
Copy link
Author

lj3954 commented Feb 5, 2024

There's also many misspellings, including at least one command. Line 306: sensible-brownser. I'm not sure exactly how that happened, since that specific function is ripped straight out of the original quickget.

@lj3954
Copy link
Author

lj3954 commented Feb 5, 2024

Temporary files should be created with mktemp, a temp directory is entirely unnecessary.

@zen0bit
Copy link

zen0bit commented Feb 5, 2024

Temporary files should be created with mktemp, a temp directory is entirely unnecessary.

Thanks for mktemp mention 👍

@lj3954
Copy link
Author

lj3954 commented Feb 5, 2024

I've provided what I believe to be a fix. Are lines 156-158 of quickget just for debug? It looks that way, as it just prints out the URL, hash, etc, which doesn't need to be presented to the end user.

@dabrown645
Copy link
Owner

My intent by creating a TMPDIR in quickget was to provide a consistent place for any temporary files and the guaranty that they will get deleted no matter how the script is ended. I agree using mktemp for the directory is a better solution but just making temporary files that don;t get deleted is not.

Looks like you method of passing associative arrays back from a function works with less bash restrictions than the way I did it. Thanks

@TuxVinyards
Copy link

I notice that your refactor still has a test for Bash 4+. Version 5 has been circulating for some years now and is fairly standard. Have your tested your refactored code on Bash 4? I wonder if you should consider moving that test to 5+

@dabrown645
Copy link
Owner

I am not opposed to moving to 5+ but I think this should follow quickemu

@TuxVinyards
Copy link

I think it is wrong to test a script on Bash 5 and then just let people on Bash 4 go ahead and use it without any warning.

This is what I originally did with qqX:

if [[ ! "$(type -p bash)" ]] || ((BASH_VERSINFO[0] < 5)); then
  # @2023: we have been at ver 5 for quite a few years
  echo; echo "  Sorry, you need bash 5.0 or newer to run this script."; echo
  echo "  Your version: "; echo
  bash --version
  echo; sleep 10; exit 1
fi

But writing this has made me I think that I want to improve this a bit further, also for myself.

I don't like just telling people to update and kicking them out of the door either.

Basically, I just copy and pasted @ flexiondotorg 's code and gave it a bit more UX info ...

So, on reflection, I am now doing this with qqX for the new release:

if [[ ! "$(type -p bash)" ]] || ((BASH_VERSINFO[0] < 5)); then
  # @2023: we have been at ver 5 for quite a few years
  echo; echo "  Sorry, you probably need Bash 5.0 or newer to run this script."; echo
  echo "  qqX has only been tested on up-to-date versions of Bash ...."; echo
  echo "  Your version: "; echo
  bash --version
  echo
  read -rp "  Press [enter] to try anyway   [e]  to  exit and update  >  "    UpdateBash
  if [[ $UpdateBash ]]; then echo;  exit 1; 
  else  echo; echo "  I understand the risks and have made backups" ; echo ; read -rp "  [enter] to confirm  [e] to exit > " UpdateBash ; fi
  echo
  [[ $UpdateBash ]] &&  exit 1
fi

I think this works better.

Also given that we/you are refactoring/restructuring pretty much most of quickget, we shouldn't ignore this bit just because it is not fixed in quickemu. Two wrongs don't make a right ...

Paste this into a script and set the value to 6. See what you think.

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