From ca364f783cbb307217bfd82aa0f050ef1fde6e7f Mon Sep 17 00:00:00 2001 From: Sabith Karippullil Soopy Date: Thu, 29 Dec 2016 10:30:24 -0800 Subject: [PATCH] Fix issues reported by shellcheck --- bin/server_package.sh | 82 +++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/bin/server_package.sh b/bin/server_package.sh index 470223505..6174b1239 100755 --- a/bin/server_package.sh +++ b/bin/server_package.sh @@ -1,64 +1,68 @@ -#!/bin/bash +#!/bin/bash -ue # Script for packaging all the job server files to .tar.gz for Mesos or other single-image deploys WORK_DIR=/tmp/job-server -ENV=$1 -if [ -z "$ENV" ]; then - echo "Syntax: $0 " +ENV="${1}" +if [ -z "${ENV}" ]; then + echo "Syntax: ${0} " echo " for a list of environments, ls config/*.sh" exit 0 fi -bin=`dirname "${BASH_SOURCE-$0}"` -bin=`cd "$bin"; pwd` +bin=$(dirname "${BASH_SOURCE-$0}") +bin=$(cd "${bin}"; pwd) -if [ -z "$CONFIG_DIR" ]; then - CONFIG_DIR=`cd "$bin"/../config/; pwd` +if [ -z "${CONFIG_DIR:-}" ]; then + CONFIG_DIR=$(cd "${bin}/../config/"; pwd) fi -configFile="$CONFIG_DIR/$ENV.sh" +configFile="${CONFIG_DIR}/${ENV}.sh" -if [ ! -f "$configFile" ]; then - echo "Could not find $configFile" +if [ ! -f "${configFile}" ]; then + echo "Could not find ${configFile}" exit 1 fi -. $configFile +# shellcheck source=/dev/null +. "${configFile}" majorRegex='([0-9]+\.[0-9]+)\.[0-9]+' -if [[ $SCALA_VERSION =~ $majorRegex ]] +set +u +if [[ "${SCALA_VERSION}" =~ ${majorRegex} ]] then majorVersion="${BASH_REMATCH[1]}" else echo "Please specify SCALA_VERSION in ${configFile}" exit 1 fi +set -u -echo Packaging job-server for environment $ENV... +echo "Packaging job-server for environment ${ENV}..." -cd $(dirname $0)/.. -sbt ++$SCALA_VERSION job-server-extras/assembly -if [ "$?" != "0" ]; then - echo "Assembly failed" - exit 1 -fi +pushd "${bin}/.." > /dev/null + if ! sbt ++"${SCALA_VERSION}" job-server-extras/assembly; then + echo "Assembly failed" + exit 1 + fi + + FILES="job-server-extras/target/scala-$majorVersion/spark-job-server.jar + bin/server_start.sh + bin/server_stop.sh + bin/kill-process-tree.sh + bin/manager_start.sh + bin/setenv.sh + ${CONFIG_DIR}/${ENV}.conf + config/shiro.ini + config/log4j-server.properties" -FILES="job-server-extras/target/scala-$majorVersion/spark-job-server.jar - bin/server_start.sh - bin/server_stop.sh - bin/kill-process-tree.sh - bin/manager_start.sh - bin/setenv.sh - $CONFIG_DIR/$ENV.conf - config/shiro.ini - config/log4j-server.properties" + rm -rf $WORK_DIR + mkdir -p $WORK_DIR + cp ${FILES} "${WORK_DIR}/" + cp "${configFile}" "${WORK_DIR}/settings.sh" +popd > /dev/null -rm -rf $WORK_DIR -mkdir -p $WORK_DIR -cp $FILES $WORK_DIR/ -cp $configFile $WORK_DIR/settings.sh -pushd $WORK_DIR -TAR_FILE=$WORK_DIR/job-server.tar.gz -rm -f $TAR_FILE -tar zcvf $TAR_FILE * -popd +pushd "${WORK_DIR}" > /dev/null + TAR_FILE="${WORK_DIR}/job-server.tar.gz" + rm -f "${TAR_FILE}" + tar zcvf "${TAR_FILE}" ./* +popd > /dev/null -echo "Created distribution at $TAR_FILE" +echo "Created distribution at ${TAR_FILE}"