v0.2 added config file and deploy function
This commit is contained in:
parent
df1999fd4f
commit
5f802c9273
@ -46,6 +46,11 @@ script, so all of the functions defined in modules under the `lib` directory wil
|
||||
|
||||
## Changelog
|
||||
|
||||
__0.2__
|
||||
|
||||
* Added support for deploying (copying) to a (configurable) path
|
||||
* Added configuration
|
||||
|
||||
__0.1__
|
||||
|
||||
* Created the initial script
|
||||
|
||||
@ -11,9 +11,11 @@
|
||||
# Created by bash-script-compiler version BASH_SCRIPT_COMPILER_VERSION
|
||||
|
||||
# set default constants / variables
|
||||
SCRIPT_VERSION="0.1"
|
||||
VERSION="0.2"
|
||||
|
||||
CONFIG_FILE_NAME=BASH_SCRIPT_COMPILER_SCRIPT_NAME.config
|
||||
# TODO implement variable replacement during compilation and use this here instead of the hardcoded value:
|
||||
#CONFIG_FILE_NAME=BASH_SCRIPT_COMPILER_SCRIPT_NAME.config
|
||||
CONFIG_FILE_NAME=bash-script-compiler.config
|
||||
CONFIG_PATH=${HOME}/.config/mmit
|
||||
CONFIG_FILE=${CONFIG_PATH}/${CONFIG_FILE_NAME}
|
||||
ACTION=${1:-"help"}
|
||||
@ -34,6 +36,7 @@ function main() {
|
||||
if [ "function" == "$isParseArgsDefined" ]; then
|
||||
"$parseArgsFunc" "${@:2}"
|
||||
fi
|
||||
configRead
|
||||
"$action" "${@:2}"
|
||||
}
|
||||
|
||||
@ -78,19 +81,90 @@ compile_setTargetFile() {
|
||||
echo "Creating output dir '${TARGET_DIR_NAME}'"
|
||||
mkdir -p ${TARGET_DIR_NAME}
|
||||
fi
|
||||
# we need to add ../ since we will be cd-ing into the src dir inside the PRJ_DIR
|
||||
TARGET_FILE=../${TARGET_DIR_NAME}/$bashScriptName
|
||||
cd $SRC_DIR_NAME
|
||||
}
|
||||
|
||||
compile() {
|
||||
pushd $PRJ_DIR >/dev/null 2>&1
|
||||
compile_setTargetFile
|
||||
cd $SRC_DIR_NAME
|
||||
compile_defineMainFunction
|
||||
compile_addFunctions
|
||||
compile_invokeMainFunction
|
||||
compile_copyCompletionFile
|
||||
echo "Compiled successfully"
|
||||
popd
|
||||
popd >/dev/null 2>&1
|
||||
}
|
||||
configInit() {
|
||||
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||
echo Could not find any config file, creating a file for you to fill in the values in ${CONFIG_FILE}
|
||||
if [ ! -d "${CONFIG_PATH}" ]; then
|
||||
echo "Config directory '${CONFIG_PATH}' does not exist yet, creating..."
|
||||
mkdir -p ${CONFIG_PATH}
|
||||
fi
|
||||
cat <<END >${CONFIG_FILE}
|
||||
# this file was created by bash-script-compiler script by Manuel Manhart
|
||||
# it is now in your hands and will not be changed by scripts anymore
|
||||
|
||||
# the path where a compiled bash script should be copied to (usually a folder in your environment PATH variable)
|
||||
DEPLOY_PATH=~/bin
|
||||
# possible values all, bin
|
||||
COPY=all
|
||||
END
|
||||
fi
|
||||
}
|
||||
|
||||
# reads the configuration file where the docker container names are saved
|
||||
configPrint() {
|
||||
echo ""
|
||||
echo "Configuration file:"
|
||||
cat ${CONFIG_FILE} | while read line
|
||||
do
|
||||
echo "$line"
|
||||
done
|
||||
echo ""
|
||||
echo "Version: $VERSION"
|
||||
}
|
||||
|
||||
# reads the configuration file where the docker container names are saved
|
||||
configRead() {
|
||||
if [ -f "${CONFIG_FILE}" ]; then
|
||||
echo found config file in ${CONFIG_FILE}
|
||||
source ${CONFIG_FILE}
|
||||
fi
|
||||
# as fallback search in script home directory
|
||||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
if [ -f "${SCRIPTPATH}/${CONFIG_FILE_NAME}" ]; then
|
||||
echo "found config file in ${SCRIPTPATH}/${CONFIG_FILE_NAME}"
|
||||
declare $(env -i `cat ${SCRIPTPATH}/${CONFIG_FILE_NAME}` >/dev/null 2>&1)
|
||||
fi
|
||||
}
|
||||
|
||||
deploy() {
|
||||
pushd $PRJ_DIR >/dev/null 2>&1
|
||||
if [ ! -d "${DEPLOY_PATH}" ]; then
|
||||
echo "Deploy path is set to: '${DEPLOY_PATH}', please call the script with configInit first"
|
||||
help configInit
|
||||
fi
|
||||
if [ ! -d "./${TARGET_DIR_NAME}" ]; then
|
||||
echo "Could not find any deployable script, have you compiled successfully?"
|
||||
help deploy
|
||||
fi
|
||||
local bashScriptName=$(basename "$(pwd)")
|
||||
local copySource="${TARGET_DIR_NAME}/*"
|
||||
if [ "$COPY" == "bin" ]; then
|
||||
copySource="${TARGET_DIR_NAME}/${bashScriptName}"
|
||||
fi
|
||||
if [ "$DEBUG" == "true" ]; then
|
||||
echo "DEBUG - pwd: `pwd`"
|
||||
echo "DEBUG - ls: `ls`"
|
||||
echo "DEBUG - buildTargetDir: ${TARGET_DIR_NAME}"
|
||||
echo "DEBUG - deployPath: ${DEPLOY_PATH}"
|
||||
echo "DEBUG: cp -r \"${copySource}\" \"${DEPLOY_PATH}\""
|
||||
fi
|
||||
cp -r $copySource "${DEPLOY_PATH}"
|
||||
popd >/dev/null 2>&1
|
||||
}
|
||||
|
||||
help() {
|
||||
@ -104,15 +178,16 @@ Usage:
|
||||
|
||||
The options are:
|
||||
need a param (you can combine like ubd)
|
||||
config init ... for creating a config file (if none exists yet - automatically checked)
|
||||
config print ... for printing the config file content
|
||||
configInit ... for creating a config file (if none exists yet - automatically checked)
|
||||
configPrint ... for printing the config file content
|
||||
|
||||
compile PRJ_PATH ... compiles the bash project in the given path (./ compiles itself)
|
||||
deploy PRJ_PATH ... deploys a compiled bash project in the configured path
|
||||
new ... initializes a new bash project
|
||||
|
||||
help ... show this page
|
||||
|
||||
Version: $SCRIPT_VERSION
|
||||
Version: $VERSION
|
||||
END
|
||||
|
||||
exit
|
||||
@ -156,6 +231,19 @@ parseArgs_compile() {
|
||||
fi
|
||||
}
|
||||
|
||||
parseArgs_deploy() {
|
||||
if [ -z $1 ]; then
|
||||
echo "Please give a directory to the bash script to deploy"
|
||||
help
|
||||
fi
|
||||
if [ ! -d $1 ]; then
|
||||
echo "$1 is not a directory"
|
||||
help
|
||||
else
|
||||
PRJ_DIR=$1
|
||||
fi
|
||||
}
|
||||
|
||||
parseArgs() {
|
||||
if [ -z $1 ]; then
|
||||
help
|
||||
|
||||
@ -7,5 +7,5 @@ configPrint() {
|
||||
echo "$line"
|
||||
done
|
||||
echo ""
|
||||
echo "Version: $SCRIPT_VERSION"
|
||||
echo "Version: $VERSION"
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ The options are:
|
||||
|
||||
help ... show this page
|
||||
|
||||
Version: $SCRIPT_VERSION
|
||||
Version: $VERSION
|
||||
END
|
||||
|
||||
exit
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
# Created by bash-script-compiler version BASH_SCRIPT_COMPILER_VERSION
|
||||
|
||||
# set default constants / variables
|
||||
SCRIPT_VERSION="0.1"
|
||||
VERSION="0.1"
|
||||
|
||||
# define your global variables here
|
||||
CONFIG_FILE_NAME=BASH_SCRIPT_COMPILER_SCRIPT_NAME.config
|
||||
|
||||
@ -5,11 +5,11 @@ _bash-script-compiler-completion()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
prevPrev="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
opts="compile new help config"
|
||||
opts="compile deploy new help config"
|
||||
config="print set init"
|
||||
|
||||
# TODO check if this is still the most efficient way to list help options
|
||||
HELP_PATH=${BASH_SOURCE%/*}/gt-help
|
||||
HELP_PATH=${BASH_SOURCE%/*}/bash-script-compiler-help
|
||||
help=${opts}
|
||||
#help=`ls $HELP_PATH`
|
||||
|
||||
@ -24,6 +24,8 @@ _bash-script-compiler-completion()
|
||||
return 0
|
||||
elif [ "$prev" == "compile" ] || [ "$prev" == "-c" ]; then
|
||||
createFromDirectory "."
|
||||
elif [ "$prev" == "deploy" ] || [ "$prev" == "-d" ]; then
|
||||
createFromDirectory "."
|
||||
else
|
||||
createFromString "${opts}"
|
||||
fi
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
compile() {
|
||||
pushd $PRJ_DIR >/dev/null 2>&1
|
||||
compile_setTargetFile
|
||||
cd $SRC_DIR_NAME
|
||||
compile_defineMainFunction
|
||||
compile_addFunctions
|
||||
compile_invokeMainFunction
|
||||
compile_copyCompletionFile
|
||||
echo "Compiled successfully"
|
||||
popd
|
||||
popd >/dev/null 2>&1
|
||||
}
|
||||
@ -4,6 +4,6 @@ compile_setTargetFile() {
|
||||
echo "Creating output dir '${TARGET_DIR_NAME}'"
|
||||
mkdir -p ${TARGET_DIR_NAME}
|
||||
fi
|
||||
# we need to add ../ since we will be cd-ing into the src dir inside the PRJ_DIR
|
||||
TARGET_FILE=../${TARGET_DIR_NAME}/$bashScriptName
|
||||
cd $SRC_DIR_NAME
|
||||
}
|
||||
|
||||
@ -1,28 +1,18 @@
|
||||
configInit() {
|
||||
if [ ! -f "${DEV_CONFIG_FILE}" ]; then
|
||||
echo Could not find any config file, creating a file for you to fill in the values in ${DEV_CONFIG_FILE}
|
||||
if [ ! -d "${DEV_CONFIG_FILE_PATH}" ]; then
|
||||
echo "Config directory '${DEV_CONFIG_FILE_PATH}' does not exist yet, creating..."
|
||||
mkdir -p ${DEV_CONFIG_FILE_PATH}
|
||||
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||
echo Could not find any config file, creating a file for you to fill in the values in ${CONFIG_FILE}
|
||||
if [ ! -d "${CONFIG_PATH}" ]; then
|
||||
echo "Config directory '${CONFIG_PATH}' does not exist yet, creating..."
|
||||
mkdir -p ${CONFIG_PATH}
|
||||
fi
|
||||
if [ -f "/IMAGE_NAME" ]; then
|
||||
# || [ `whoami` = 'dev' ]; then
|
||||
MODE=devcontainer
|
||||
GRADLE_DEFAULT=wrapper
|
||||
else
|
||||
MODE=host
|
||||
GRADLE_DEFAULT=normal
|
||||
fi
|
||||
|
||||
cat <<END >${DEV_CONFIG_FILE}
|
||||
# this file was created by dev script by Manuel Manhart
|
||||
cat <<END >${CONFIG_FILE}
|
||||
# this file was created by bash-script-compiler script by Manuel Manhart
|
||||
# it is now in your hands and will not be changed by scripts anymore
|
||||
|
||||
MODE=$MODE
|
||||
LIFERAY_DOCKER=(
|
||||
"TODO" # change this to the real path
|
||||
)
|
||||
# the path where a compiled bash script should be copied to (usually a folder in your environment PATH variable)
|
||||
DEPLOY_PATH=~/bin
|
||||
# possible values all, bin
|
||||
COPY=all
|
||||
END
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
configPrint() {
|
||||
echo ""
|
||||
echo "Configuration file:"
|
||||
cat ${DEV_CONFIG_FILE} | while read line
|
||||
cat ${CONFIG_FILE} | while read line
|
||||
do
|
||||
echo "$line"
|
||||
done
|
||||
echo ""
|
||||
echo "Version: $SCRIPT_VERSION"
|
||||
echo "Version: $VERSION"
|
||||
}
|
||||
|
||||
@ -1,23 +1,13 @@
|
||||
# reads the configuration file where the docker container names are saved
|
||||
configRead() {
|
||||
if [ -f "${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}" ]; then
|
||||
echo found config file in ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}
|
||||
source ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}
|
||||
|
||||
# Read common vars from the config file
|
||||
# the incantation here ensures (by env) that only key=value pairs are present
|
||||
# then declare-ing the result puts those vars in our environment
|
||||
# declare $(env -i `cat ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}` >/dev/null 2>&1) >/dev/null 2>&1
|
||||
|
||||
# IFS=$'\n' read -d '' -r -a LIFERAY_DOCKER < ${DEV_CONFIG_FILE_PATH}/${DEV_CONFIG_FILE_NAME}
|
||||
if [ -f "${CONFIG_FILE}" ]; then
|
||||
echo found config file in ${CONFIG_FILE}
|
||||
source ${CONFIG_FILE}
|
||||
fi
|
||||
# as fallback search in script home directory
|
||||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
if [ -f "${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}" ]; then
|
||||
echo found config file in ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}
|
||||
|
||||
declare $(env -i `cat ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}` >/dev/null 2>&1)
|
||||
# source ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}
|
||||
# IFS=$'\n' read -d '' -r -a LIFERAY_DOCKER < ${SCRIPTPATH}/${DEV_CONFIG_FILE_NAME}
|
||||
if [ -f "${SCRIPTPATH}/${CONFIG_FILE_NAME}" ]; then
|
||||
echo "found config file in ${SCRIPTPATH}/${CONFIG_FILE_NAME}"
|
||||
declare $(env -i `cat ${SCRIPTPATH}/${CONFIG_FILE_NAME}` >/dev/null 2>&1)
|
||||
fi
|
||||
}
|
||||
|
||||
25
src/functions/deploy.sh
Normal file
25
src/functions/deploy.sh
Normal file
@ -0,0 +1,25 @@
|
||||
deploy() {
|
||||
pushd $PRJ_DIR >/dev/null 2>&1
|
||||
if [ ! -d "${DEPLOY_PATH}" ]; then
|
||||
echo "Deploy path is set to: '${DEPLOY_PATH}', please call the script with configInit first"
|
||||
help configInit
|
||||
fi
|
||||
if [ ! -d "./${TARGET_DIR_NAME}" ]; then
|
||||
echo "Could not find any deployable script, have you compiled successfully?"
|
||||
help deploy
|
||||
fi
|
||||
local bashScriptName=$(basename "$(pwd)")
|
||||
local copySource="${TARGET_DIR_NAME}/*"
|
||||
if [ "$COPY" == "bin" ]; then
|
||||
copySource="${TARGET_DIR_NAME}/${bashScriptName}"
|
||||
fi
|
||||
if [ "$DEBUG" == "true" ]; then
|
||||
echo "DEBUG - pwd: `pwd`"
|
||||
echo "DEBUG - ls: `ls`"
|
||||
echo "DEBUG - buildTargetDir: ${TARGET_DIR_NAME}"
|
||||
echo "DEBUG - deployPath: ${DEPLOY_PATH}"
|
||||
echo "DEBUG: cp -r \"${copySource}\" \"${DEPLOY_PATH}\""
|
||||
fi
|
||||
cp -r $copySource "${DEPLOY_PATH}"
|
||||
popd >/dev/null 2>&1
|
||||
}
|
||||
@ -9,15 +9,16 @@ Usage:
|
||||
|
||||
The options are:
|
||||
need a param (you can combine like ubd)
|
||||
config init ... for creating a config file (if none exists yet - automatically checked)
|
||||
config print ... for printing the config file content
|
||||
configInit ... for creating a config file (if none exists yet - automatically checked)
|
||||
configPrint ... for printing the config file content
|
||||
|
||||
compile PRJ_PATH ... compiles the bash project in the given path (./ compiles itself)
|
||||
deploy PRJ_PATH ... deploys a compiled bash project in the configured path
|
||||
new ... initializes a new bash project
|
||||
|
||||
help ... show this page
|
||||
|
||||
Version: $SCRIPT_VERSION
|
||||
Version: $VERSION
|
||||
END
|
||||
|
||||
exit
|
||||
|
||||
12
src/functions/parseArgs_deploy.sh
Normal file
12
src/functions/parseArgs_deploy.sh
Normal file
@ -0,0 +1,12 @@
|
||||
parseArgs_deploy() {
|
||||
if [ -z $1 ]; then
|
||||
echo "Please give a directory to the bash script to deploy"
|
||||
help
|
||||
fi
|
||||
if [ ! -d $1 ]; then
|
||||
echo "$1 is not a directory"
|
||||
help
|
||||
else
|
||||
PRJ_DIR=$1
|
||||
fi
|
||||
}
|
||||
@ -11,9 +11,11 @@
|
||||
# Created by bash-script-compiler version BASH_SCRIPT_COMPILER_VERSION
|
||||
|
||||
# set default constants / variables
|
||||
SCRIPT_VERSION="0.1"
|
||||
VERSION="0.2"
|
||||
|
||||
CONFIG_FILE_NAME=BASH_SCRIPT_COMPILER_SCRIPT_NAME.config
|
||||
# TODO implement variable replacement during compilation and use this here instead of the hardcoded value:
|
||||
#CONFIG_FILE_NAME=BASH_SCRIPT_COMPILER_SCRIPT_NAME.config
|
||||
CONFIG_FILE_NAME=bash-script-compiler.config
|
||||
CONFIG_PATH=${HOME}/.config/mmit
|
||||
CONFIG_FILE=${CONFIG_PATH}/${CONFIG_FILE_NAME}
|
||||
ACTION=${1:-"help"}
|
||||
|
||||
@ -4,4 +4,5 @@ local isParseArgsDefined=$(type -t $parseArgsFunc)
|
||||
if [ "function" == "$isParseArgsDefined" ]; then
|
||||
"$parseArgsFunc" "${@:2}"
|
||||
fi
|
||||
configRead
|
||||
"$action" "${@:2}"
|
||||
Loading…
x
Reference in New Issue
Block a user