Martin,

On 12/11/20 15:52, Martin Grigorov wrote:
On Fri, Dec 11, 2020, 21:34 Christopher Schultz <
ch...@christopherschultz.net> wrote:

Rainer,

On 12/11/20 14:19, Rainer Jung wrote:
Hi Chris,

Am 11.12.2020 um 19:53 schrieb Christopher Schultz:
Rainer,

On 12/11/20 06:19, Rainer Jung wrote:
Am 11.12.2020 um 09:49 schrieb Martin Grigorov:
On Fri, Dec 11, 2020 at 10:41 AM Martin Grigorov <
mgrigo...@apache.org>
wrote:

Hi Rainer,

On Fri, Dec 11, 2020 at 10:37 AM Rainer Jung <
rainer.j...@kippdata.de>
wrote:

Am 11.12.2020 um 08:25 schrieb mgrigo...@apache.org:
This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git


The following commit(s) were added to refs/heads/master by this
push:
        new 000c876  Make migrate.sh usable from any directory
000c876 is described below

commit 000c876ea3a1e700df2fffef70b29d9c3a9dfef2
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
AuthorDate: Fri Dec 11 09:22:22 2020 +0200

       Make migrate.sh usable from any directory

       Until now one has to `cd` to the bin/ folder to be able to
execute
migrate.sh, otherwise lib/ folder won't be found
---
    src/main/scripts/migrate.sh | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/scripts/migrate.sh
b/src/main/scripts/migrate.sh
index c2b941c..3d3f34c 100755
--- a/src/main/scripts/migrate.sh
+++ b/src/main/scripts/migrate.sh
@@ -1,4 +1,6 @@
    #!/bin/sh

+BIN_FOLDER=`dirname $PWD/$0`

Does that work if $0 is an absolute path?


Yes, it does. I have tested it!
BIN_FOLDER looks a bit strange: ///some/absolute/path/bin but it
works
just fine on my Ubuntu.
Does it work on Solaris ? :-)



Maybe one could

     cd `dirname $0`


Two issues with this:

1) the script usage is: ./bin/migrate.sh input.war output.war
if we "cd" into bin/ then input.war is not there anymore. Its path
should
be fixed to ../input.war somehow

2) it would be good to leave the user back to the original directory
after
executing the script but pushd/popd are not available for 'sh'. We
will
need to use Bash or another

Solaris check:

apache% cat test.sh
#!/bin/sh

echo `dirname $PWD/$0`

apache% /home/jung/test.sh
/home/jung//home/jung

apache% ./test.sh
/home/jung/.

So the full path case does not work there. Switching to /bin/bash or
/bin/ksh does not help.

I agree with Mark concerning the TC scripts.

Concerning your 2) above: a "cd" in the script does not change the
working diretory of the calling shell. After the end of the script,
the user is still in the same directory where he was before starting
it.

1) is a bit more tricky, because again one would have to handle the
absolute and the relative case.

What might help and should be compatible would be something like

mydir="$PWD"
cd `dirname "$0"`
BIN_FOLDER="$PWD"
cd "$mydir"

I would avoid using "cd" in a script if at all possible. The migration
tool should be able to be run from anywhere with command-line
arguments to anything you need to call (e.g. java -cp).

What risk do you see in the two "cd" uses? How is the ability to be
called from anywhere reduced by teh above construct? It was actually
introduced to myke it callable from anywhere.

The whole script can be:

BIN_FOLDER=$( dirname ${0} )
java -cp "$BIN_FOLDER/../lib/*" org.apache.tomcat.jakartaee.MigrationCLI
"$@"

The "cd" is not necessary at all and IMO is just more complicated.

Note that the "-cp" won't work because the files must be separated by :
on *NIX. Unless I don't know how to build this in Maven (which is weird,
I have no mvnw command to run, so I did "mvn verify" which did build a
.jar file), there won't be any lib directory to include.

Don't we really just want:

BIN_FOLDER=$( dirname ${0} )
java -jar "$BIN_FOLDER/target/jakartaee-migration-0.1.0.jar" \
    org.apache.tomcat.jakartaee.MigrationCLI "$@"

?

Maybe I just don't understand what this script is intended to
accomplish. A shortcut for "java -jar [migration-tool]" or something else?

Every Java-related shell script I ever write looks something like this:

#/bin/sh
BIN_DIR=$( dirname ${0} )


dirname just cuts the parent path segment.
If there is no such then it returns '.'
Play with it and see.

Yes, then you get BIN_DIR=. and:

java -cp ./lib/* [...]

Which is exactly what you want. It works with migrate.sh (no prefix, BIN_DIR=.), ./migrate.sh (BIN_DIR=.), /usr/local/foo/migrate.sh (BIN_DIR=/usr/local/foo), etc.

No 'cd' required at all. 50% reduction in lines of code.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to