added setup script, modified README accordingly
This commit is contained in:
44
setup.sh
Executable file
44
setup.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
# env setup script for step-ca docker compose
|
||||
# 2023-01-06 by dede & dany
|
||||
|
||||
echo "step-ca docker compose setup"
|
||||
echo "> env setup for step-ca with docker compose..."
|
||||
|
||||
# check for existing .env file to not break an existing setup
|
||||
if [[ -f .env ]]; then
|
||||
echo "> .env file already exists. setup will not run. either rename or delete it first."
|
||||
exit 1
|
||||
elif [[ ! -f env.sample ]]; then
|
||||
echo "> env.sample file is missing. cannot run."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# create .env file
|
||||
echo -e "# file generated by ${0##*/} on $(date +"%F %H:%M") by $USER\n" > .env
|
||||
|
||||
# step through the list of lines and ask for each key to use default value or set value
|
||||
# for each line in configfile
|
||||
while read -r -u 3 line; do
|
||||
|
||||
# keep blank and comment lines
|
||||
if [[ -z $line ]] || [[ $line == \#* ]]; then
|
||||
echo "$line" >> .env
|
||||
|
||||
# handle variable lines
|
||||
else
|
||||
# split line by '=' into key and value
|
||||
readarray -d "=" -t currvar<<< "$line"
|
||||
echo -n "please enter value for ${currvar[0]} [${currvar[1]::-1}]: "
|
||||
read -r userinput
|
||||
|
||||
# set userinput as new value
|
||||
if [ -n "$userinput" ] ; then
|
||||
echo "${currvar[0]}=$userinput" >> .env
|
||||
|
||||
# keep default value if empty userinput
|
||||
else
|
||||
echo "$line" >> .env
|
||||
fi
|
||||
fi
|
||||
done 3< env.sample
|
||||
Reference in New Issue
Block a user