added env_generator as submodule
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "srcs/env_generator"]
|
||||||
|
path = srcs/env_generator
|
||||||
|
url = git@bitbucket.org:hugogogo/script_env_generator.git
|
||||||
1
srcs/env_generator
Submodule
1
srcs/env_generator
Submodule
Submodule srcs/env_generator added at d26a2b2902
@@ -1,47 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# - this script creates a .env file in the same directory of the model.env
|
|
||||||
# - the model.env file is given in argument, otherwise it default to current path
|
|
||||||
|
|
||||||
# change to where the script is relatively to where the execution is made
|
|
||||||
#cd $(dirname $0)
|
|
||||||
|
|
||||||
CURRENT_PATH=$(dirname $0)
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
FILE_PATH="${CURRENT_PATH}/model.env"
|
|
||||||
ENV_PATH=${CURRENT_PATH}
|
|
||||||
else
|
|
||||||
FILE_PATH="$1"
|
|
||||||
ENV_PATH=$(dirname $FILE_PATH)
|
|
||||||
fi
|
|
||||||
if [ ! -f "$FILE_PATH" ]; then
|
|
||||||
echo ""
|
|
||||||
echo " no file 'model.env' found"
|
|
||||||
echo ""
|
|
||||||
echo " you need to create one in the same directory of this script,"
|
|
||||||
echo " or to give the path to a valide one in argument"
|
|
||||||
echo ""
|
|
||||||
echo " like './create_env path/to/model.env'"
|
|
||||||
echo " "
|
|
||||||
echo " note that the .env file will be created where the model.env is"
|
|
||||||
echo ""
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
TMP_FILE="tmpfile_3289442091310922474928"
|
|
||||||
TMP_BEFORE="env_before.tmp"
|
|
||||||
TMP_AFTER="env_after.tmp"
|
|
||||||
|
|
||||||
# add lines at beginning and end of a temp env file
|
|
||||||
echo "set | sort > ${TMP_BEFORE}" > ${TMP_FILE}
|
|
||||||
cat ${FILE_PATH} >> ${TMP_FILE}
|
|
||||||
echo "set | sort > ${TMP_AFTER}" >> ${TMP_FILE}
|
|
||||||
|
|
||||||
source ${TMP_FILE}
|
|
||||||
|
|
||||||
# diff between the two set files == the newly created env var
|
|
||||||
NEW_ENV=$(comm -13 ${TMP_BEFORE} ${TMP_AFTER} | grep -v "^_=")
|
|
||||||
echo "${NEW_ENV}" > ${ENV_PATH}/.env
|
|
||||||
|
|
||||||
rm -f ${TMP_BEFORE} ${TMP_AFTER} ${TMP_FILE}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user