bancika / diy-layout-creator

multi platform circuit layout and schematic drawing tool
http://diy-fever.com
GNU General Public License v3.0
859 stars 99 forks source link

run.sh only works if run from the app directory #721

Open SpinningVinyl opened 1 year ago

SpinningVinyl commented 1 year ago

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.

peterjosvai commented 1 year ago

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 :)

timsavage commented 1 year ago

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

M0JXD commented 1 month ago

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.