diff options
author | Frederick Muriuki Muriithi | 2022-01-31 06:46:50 +0300 |
---|---|---|
committer | zsloan | 2022-02-07 22:57:50 -0600 |
commit | 04203f785e5a8c86509089bc68340e1e01162ffd (patch) | |
tree | 023343e35486fef747e2eec0d3bf7901fd16c3bc | |
parent | b5bf6432dbf3a75e2306c03aced4180b020304c9 (diff) | |
download | genenetwork2-04203f785e5a8c86509089bc68340e1e01162ffd.tar.gz |
Double quote shell variables to prevent globbing and word splitting
-rwxr-xr-x | bin/genenetwork2 | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/bin/genenetwork2 b/bin/genenetwork2 index 1b933e80..a6ba7241 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -53,25 +53,27 @@ # env GN2_PROFILE=~/opt/gn-latest-guix ./bin/genenetwork2 ./etc/default_settings.py -gunicorn "--bind 0.0.0.0:5003 --workers=1 wsgi" SCRIPT=$(realpath "$0") -echo SCRIPT=$SCRIPT -echo GN2_PROFILE=$GN2_PROFILE -GN2_BASE_DIR=$(dirname $(dirname "$SCRIPT")) -GN2_ID=$(cat /etc/hostname):$(basename $GN2_BASE_DIR) +echo SCRIPT="${SCRIPT}" +echo GN2_PROFILE="${GN2_PROFILE}" +GN2_BASE_DIR=$(dirname "$(dirname "${SCRIPT}")") +GN2_ID=$(cat /etc/hostname):$(basename "${GN2_BASE_DIR}") -echo GN2_BASE_DIR=$GN2_BASE_DIR +echo GN2_BASE_DIR="${GN2_BASE_DIR}" GUIX_SITE=$GN2_BASE_DIR/lib/python3.8/site-packages -if [ -d $GUIX_SITE ]; then +if [ -d "${GUIX_SITE}" ]; then echo INFO: GN2 is running from GNU Guix GN2_BASE_DIR=$GUIX_SITE - export GN_VERSION=$GN2_ID:$(cat $GN2_BASE_DIR/etc/VERSION) + GN_VERSION="${GN2_ID}:$(cat "${GN2_BASE_DIR}"/etc/VERSION)" + export GN_VERSION else echo INFO: GN2 is running from a source tree GIT_HASH=$(git rev-parse HEAD) GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) - export GN_VERSION="${GN2_ID}:$(cat ${GN2_BASE_DIR}/etc/VERSION)-${GIT_BRANCH}-$(echo ${GIT_HASH} | cut -c1-9)" + GN_VERSION="${GN2_ID}:$(cat "${GN2_BASE_DIR}"/etc/VERSION)-${GIT_BRANCH}-$(echo "${GIT_HASH}" | cut -c1-9)" + export GN_VERSION fi -echo GN_VERSION=$GN_VERSION +echo GN_VERSION="${GN_VERSION}" if [ "$1" = "-c" -o "$1" = "-gunicorn" ]; then echo "Can not use $1 switch without default settings file" @@ -79,12 +81,12 @@ if [ "$1" = "-c" -o "$1" = "-gunicorn" ]; then fi settings=$1 -if [ -z $settings ]; then +if [ -z "${settings}" ]; then settings=$GN2_BASE_DIR/etc/default_settings.py else shift fi -settings=$(realpath $settings) +settings=$(realpath "${settings}") # ext="${settings##*.}" # if [ "$ext" = "json" -o "$ext" = "JSON" ]; then @@ -93,24 +95,25 @@ settings=$(realpath $settings) # echo $settings # fi -if [ ! -e $settings ]; then +if [ ! -e "${settings}" ]; then echo "ERROR: can not locate settings file - pass it in the command line" exit 1 fi export GN2_SETTINGS=$settings # Python -echo GN2_SETTINGS=$settings +echo GN2_SETTINGS="${settings}" -if [ -z $GN2_PROFILE ] ; then +if [ -z "${GN2_PROFILE}" ] ; then echo "WARNING: GN2_PROFILE has not been set - you need the environment, so I hope you know what you are doing!" - export GN2_PROFILE=$(dirname $(dirname $(which genenetwork2))) - if [ -d $GN2_PROFILE ]; then + GN2_PROFILE=$(dirname $(dirname $(which genenetwork2))) + export GN2_PROFILE + if [ -d "${GN2_PROFILE}" ]; then echo "Best guess is $GN2_PROFILE" fi echo "ERROR: always set GN2_PROFILE" exit 1 fi -if [ -z $GN2_PROFILE ]; then +if [ -z "${GN2_PROFILE}" ]; then read -p "PRESS [ENTER] TO CONTINUE..." else export PATH=$GN2_PROFILE/bin:$PATH @@ -125,21 +128,21 @@ else export GUIX_GENENETWORK_FILES="$GN2_PROFILE/share/genenetwork2" export PLINK_COMMAND="$GN2_PROFILE/bin/plink2" export GEMMA_COMMAND="$GN2_PROFILE/bin/gemma" - if [ -z $GEMMA_WRAPPER_COMMAND ]; then + if [ -z "${GEMMA_WRAPPER_COMMAND}" ]; then export GEMMA_WRAPPER_COMMAND="$GN2_PROFILE/bin/gemma-wrapper" fi while IFS=":" read -ra PPATH; do for PPART in "${PPATH[@]}"; do - if [ ! -d $PPART ] ; then echo "$PPART in PYTHONPATH not valid $PYTHONPATH" ; exit 1 ; fi + if [ ! -d "${PPART}" ] ; then echo "$PPART in PYTHONPATH not valid $PYTHONPATH" ; exit 1 ; fi done done <<< "$PYTHONPATH" - if [ ! -d $R_LIBS_SITE ] ; then echo "R_LIBS_SITE not valid "$R_LIBS_SITE ; exit 1 ; fi + if [ ! -d "${R_LIBS_SITE}" ] ; then echo "R_LIBS_SITE not valid ${R_LIBS_SITE}" ; exit 1 ; fi fi -if [ -z $PYTHONPATH ] ; then +if [ -z "${PYTHONPATH}" ] ; then echo "ERROR PYTHONPATH has not been set - use GN2_PROFILE!" exit 1 fi -if [ ! -d $R_LIBS_SITE ] ; then +if [ ! -d "${R_LIBS_SITE}" ] ; then echo "ERROR R_LIBS_SITE has not been set correctly (we only allow one path) - use GN2_PROFILE!" echo "Paste into your shell the output of (for example)" echo "guix package -p \$GN2_PROFILE --search-paths" @@ -152,60 +155,60 @@ export PYTHONPATH=$PYTHON_GN_PATH:$GN2_BASE_DIR/wqflask:$GN3_PYTHONPATH:$PYTHONP export PYTHONPATH="${GN3_DEV_REPO_PATH:+$GN3_DEV_REPO_PATH:}:${PYTHONPATH}" # Our UNIX TMPDIR defaults to /tmp - change this on a shared server -if [ -z $TMPDIR ]; then +if [ -z "${TMPDIR}" ]; then TMPDIR="/tmp" fi # Show environment settings set|grep guix -set|grep $GN2_PROFILE +set|grep GN2_PROFILE set|grep TMPDIR # Now handle command parameter -c which runs python if [ "$1" = '-c' ] ; then - cd $GN2_BASE_DIR/wqflask + cd "${GN2_BASE_DIR}/wqflask" cmd=${2#wqflask/} - echo PYTHONPATH=$PYTHONPATH + echo PYTHONPATH="${PYTHONPATH}" shift ; shift - echo RUNNING COMMAND $cmd $* + echo "RUNNING COMMAND ${cmd} ${*}" python $cmd $* exit $? fi # Now handle command parameter -cli which runs in bash if [ "$1" = "-cli" ] ; then - cd $GN2_BASE_DIR/wqflask + cd "${GN2_BASE_DIR}/wqflask" cmd=$2 - echo PYTHONPATH=$PYTHONPATH + echo PYTHONPATH="${PYTHONPATH}" shift ; shift - echo RUNNING COMMAND $cmd $* + echo "RUNNING COMMAND ${cmd} ${*}" $cmd $* exit $? fi if [ "$1" = '-gunicorn' ] ; then - cd $GN2_BASE_DIR/wqflask + cd "${GN2_BASE_DIR}/wqflask" cmd=$2 - echo PYTHONPATH=$PYTHONPATH - echo RUNNING gunicorn $cmd + echo PYTHONPATH="${PYTHONPATH}" + echo "RUNNING gunicorn ${cmd}" gunicorn $cmd exit $? fi if [ "$1" = '-gunicorn-dev' ] ; then - cd $GN2_BASE_DIR/wqflask - echo PYTHONPATH=$PYTHONPATH - if [ -z $SERVER_PORT ]; then echo "ERROR: Provide a SERVER_PORT" ; exit 1 ; fi + cd "${GN2_BASE_DIR}/wqflask" + echo PYTHONPATH="${PYTHONPATH}" + if [ -z "${SERVER_PORT}" ]; then echo "ERROR: Provide a SERVER_PORT" ; exit 1 ; fi cmd="--bind 0.0.0.0:$SERVER_PORT --workers=1 --timeout 180 --reload run_gunicorn:app" - echo RUNNING gunicorn $cmd + echo "RUNNING gunicorn ${cmd}" gunicorn $cmd exit $? fi if [ "$1" = '-gunicorn-prod' ] ; then - cd $GN2_BASE_DIR/wqflask - echo PYTHONPATH=$PYTHONPATH - if [ -z $SERVER_PORT ]; then echo "ERROR: Provide a SERVER_PORT" ; exit 1 ; fi + cd "${GN2_BASE_DIR}/wqflask" + echo PYTHONPATH="${PYTHONPATH}" + if [ -z "${SERVER_PORT}" ]; then echo "ERROR: Provide a SERVER_PORT" ; exit 1 ; fi PID=$TMPDIR/gunicorn.$USER.pid cmd="--bind 0.0.0.0:$SERVER_PORT --pid $PID --workers 20 --keep-alive 6000 --max-requests 100 --max-requests-jitter 30 --timeout 1200 wsgi" - echo RUNNING gunicorn $cmd + echo "RUNNING gunicorn ${cmd}" gunicorn $cmd exit $? fi @@ -219,6 +222,6 @@ dbfilename gn2.rdb # export R_LIBS_SITE=$R_LIBS_SITE:$HOME/.Rlibs/das1i1pm54dj6lbdcsw5w0sdwhccyj1a-r-3.3.2/lib/R/lib # Start the flask server running GN2 -cd $GN2_BASE_DIR/wqflask +cd "${GN2_BASE_DIR}/wqflask" echo "Starting with $settings" python runserver.py |