added env_generator as submodule

This commit is contained in:
asus
2024-02-01 15:30:33 +01:00
parent 0c869a0ade
commit 7bfb84463c
3 changed files with 4 additions and 47 deletions

1
srcs/env_generator Submodule

Submodule srcs/env_generator added at d26a2b2902

View File

@@ -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}