quarkusio / quarkus-buildpacks

9 stars 3 forks source link

bash script fails on macos as realpath command is not found #8

Open cmoulliard opened 3 years ago

cmoulliard commented 3 years ago

Issue

The bash script /build-stack.sh fails on macos as realpath command is not found

./create-buildpacks.sh
---> Building Stacks
---> Building Stack native
 /stacks/build-stack.sh: line 50: realpath: command not found
quintesse commented 3 years ago

Hi @cmoulliard , does it work if you change line 8 of the script to:

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cmoulliard commented 3 years ago

does it work if you change line 8 of the script to:

No as error occurs here IMAGE_DIR=$(realpath "${STACK_DIR}"). The command realpath don t exist on macos

quintesse commented 3 years ago

Sorry, was looking at the wrong code.

So we'd have to decide if we just tell people on Mac OS to install realpath, eg by running:

brew install coreutils

or that we add the following to the bash script:

realpath() {
  OURPWD=$PWD
  cd "$(dirname "$1")"
  LINK=$(readlink "$(basename "$1")")
  while [ "$LINK" ]; do
    cd "$(dirname "$LINK")"
    LINK=$(readlink "$(basename "$1")")
  done
  REALPATH="$PWD/$(basename "$1")"
  cd "$OURPWD"
  echo "$REALPATH"
}
cmoulliard commented 3 years ago

or that we add the following to the bash script:

I prefer this second option :-). Nevertheless it will only work if you create also a function for readlink as this is also a package installed through coreutils @quintesse

quintesse commented 3 years ago

Are you sure about that @cmoulliard ? Because Jbang uses readlink in its startup script and I have never heard that coreutils is a requirement on Mac. I do know that it doesn't have the some behaviour as GNU readlink (it has no -f option), but that's why the above realpath function is so complex, it's doing what the -f would do on Linux (at least AFAIK).

cmoulliard commented 3 years ago

Yes, I'm sure. See hereafter the lastline

which readlink
/usr/local/bin/readlink

ls -la /usr/local/bin/readlink
lrwxr-xr-x  1 cmoullia  staff  9 Oct 12 16:20 /usr/local/bin/readlink -> greadlink

ls -la /usr/local/bin/greadlink
lrwxr-xr-x  1 cmoullia  staff  38 Mar 30 13:00 /usr/local/bin/greadlink -> ../Cellar/coreutils/8.32/bin/greadlink
maxandersen commented 3 years ago

@cmoulliard you have installed something in addition imo.

default OSX has readlink:

ls -l /usr/bin/readlink
.rwxr-xr-x 105k root  1 Jan  2020 /usr/bin/readlink

realpath I see I have this:

ls -l /usr/local/bin/realpath
lrwxr-xr-x 37 max  9 Aug  2020 /usr/local/bin/realpath -> ../Cellar/coreutils/8.32/bin/realpath
cmoulliard commented 3 years ago

My mistake :-) I removed brew uninstall coreutils and now I can use the default one

which readlink
/usr/bin/readlink

ls -la /usr/bin/readlink
-rwxr-xr-x  1 root  wheel  105344 Jan  1  2020 /usr/bin/readlink
quintesse commented 3 years ago

Ok, good to know. That would at least mean that it would be possible to use that script.

So now to decide if it's worth it :-) Given the fact that this script is (supposedly) only necessary for people that want to help out developing this buildpack I wonder if it's not reasonable to expect them to have the coreutils installed? The end goal is of course to have the buildpack built and published so any users can just use the buildpack without having to build it themselves.

cmoulliard commented 3 years ago

wonder if it's not reasonable to expect them to have the coreutils installed?

+100. Just mention part of the README file that the macos builder should have installed brew install coreutils and fix the script with the function proposed

quintesse commented 3 years ago

and fix the script with the function proposed

Not sure I understand completely @cmoulliard ... coreutils includes realpath, right? So AFAIU the function would only be necessary for people on vanilla MacOS. So if we tell them to install coreutils the script should just work, right?

maxandersen commented 3 years ago

Readline seems to be better choice imo.

quintesse commented 3 years ago

@maxandersen can you explain why?

maxandersen commented 3 years ago

Sorry. Bad autocorrect! Readlink seem to be the better choice as it is there wether or not you installed coreutils or not.

cmoulliard commented 3 years ago

So if we tell them to install coreutils the script should just work, right?

Yes but that should be better to improve this project, to avoid to have to install coreutls for macusers and that you enrich the existing bash scripts with a functions such as realpath ;-)

quintesse commented 3 years ago

Well... it's more work for something I can't test because I don't have a Mac. While it's only necessary for people who want to develop on this buildpack, not for people that want to use it. That's why I asked if it's too much to ask for a Mac dev wanting to develop on this buildpack to install coreutils. But I will accept a PR that implements this :-)

cmoulliard commented 3 years ago

That works on macos (without installing coreutils) if you declare within the bash script this function

realpath() {
  OURPWD=$PWD
  cd "$(dirname "$1")"
  LINK=$(readlink "$(basename "$1")")
  while [ "$LINK" ]; do
    cd "$(dirname "$LINK")"
    LINK=$(readlink "$(basename "$1")")
  done
  REALPATH="$PWD/$(basename "$1")"
  cd "$OURPWD"
  echo "$REALPATH"
}
maxandersen commented 3 years ago

Ah. I thought this was about users building :) then don't mind me.