diy-layout-creator icon indicating copy to clipboard operation
diy-layout-creator copied to clipboard

run.sh only works if run from the app directory

Open SpinningVinyl opened this issue 2 years ago • 3 comments

Hi, the current run.sh script works only if started from the same directory the app is installed to.

For example, in my case it's /home/[Username]/Apps/DIYLC/

If I try to run it from any other directory, e.g. my home folder, it returns a classpath error, because the script uses relative paths.

I came up with the following version of run.sh that works from anywhere:

#!/usr/bin/env bash
JAVA_BIN="$(which java)"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
JAVA_AGENT="${DIR}/lib/jar-loader.jar"
CLASS_PATH="${DIR}/diylc.jar:lib"
exec "$JAVA_BIN" -Xms512m -Xmx2048m -javaagent:"$JAVA_AGENT" -Dorg.diylc.scriptRun=true -Dfile.encoding=UTF-8 -classpath "$CLASS_PATH"  --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.geom=ALL-UNNAMED  org.diylc.DIYLCStarter "$@"

I tested it in Linux and it runs fine, however I have not tested it in macOS.

SpinningVinyl avatar Aug 22 '22 14:08 SpinningVinyl

thank you so much!!!! perhaps you should make it clear that the code goes off the text area.... and we should use the COPY icon instead of selecting with the mouse :)

peterjosvai avatar Sep 05 '22 15:09 peterjosvai

There is a little more to this. Setting a different working directory also causes language translations to fail to load.

timsavage avatar Oct 23 '22 04:10 timsavage

I saw in a separate (closed) issue that some people have been adding a cd at the top of the script to fix this.

Perhaps that could be automated like so:

#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR
exec java -Xms512m -Xmx2048m -javaagent:lib/jar-loader.jar -Dorg.diylc.scriptRun=true -Dfile.encoding=UTF-8 -cp diylc.jar:lib  --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.geom=ALL-UNNAMED  org.diylc.DIYLCStarter "$@"

Based on this stack overflow post: https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script

I've tested this on Linux Mint and it works well.

M0JXD avatar Apr 06 '24 19:04 M0JXD