create directories and generate passwords

This commit is contained in:
2023-01-07 12:46:59 +01:00
parent efa52f29b5
commit 0da4c1b064

View File

@@ -29,16 +29,43 @@ while read -r -u 3 line; do
else
# split line by '=' into key and value
readarray -d "=" -t currvar<<< "$line"
echo -n "please enter value for ${currvar[0]} [${currvar[1]::-1}]: "
# preset value with default
value=${currvar[1]::-1}
# check if there's a password to generate
if [[ ${currvar[0]} =~ (PASS|PASSWORD|PWD|PASSWD)$ ]]; then
value=$(openssl rand -base64 29 | tr -d "=+/" | cut -c1-25)
fi
# ask for user input
echo -n "please enter value for ${currvar[0]} [$value]: "
read -r userinput
# set userinput as new value
# set userinput as new value if any
if [ -n "$userinput" ]; then
echo "${currvar[0]}=$userinput" >> .env
# keep default value if empty userinput
else
echo "$line" >> .env
value=$userinput
fi
# check if there's a directory to create
if [[ ${currvar[0]} =~ (DIR|DIRECTORY)$ ]]; then
if [[ ! -d $value ]]; then
echo -n "do you want to create the directory? [Y/n]: "
read -r createdir
if [[ $createdir =~ ^([yY]|)$ ]]; then
mkdir -p "$value"
echo "directory created."
fi
else
echo "directory already exists."
if [ -n "$(ls -A "$value")" ]; then
echo "WATCH OUT! the directory is NOT empty. please ensure this is intended."
fi
fi
fi
# now append the line
echo "${currvar[0]}=$value" >> .env
fi
done 3< env.sample