This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Better name the arguments on setup-* scripts
- Loading branch information
1 parent
116c082
commit 2bc896a
Showing
2 changed files
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
#!/bin/bash | ||
# Usage: handles-setup-dotenv [<source_file>] | ||
# Usage: handles-setup-dotenv [<input_file>] | ||
# Summary: Generate an environment file | ||
|
||
set -e | ||
cd "$(git rev-parse --show-toplevel)" | ||
|
||
SOURCE_FILE="${1-".env.example"}" | ||
INPUT_FILE="${1-".env.example"}" | ||
|
||
if [ -z "$SOURCE_FILE" ]; then | ||
if [ -z "$INPUT_FILE" ]; then | ||
handles help setup-dotenv >&2 | ||
exit 1 | ||
elif [ ! -f "$SOURCE_FILE" ]; then | ||
echo "!!! Error: invalid source file: ${SOURCE_FILE}" >&2 | ||
elif [ ! -f "$INPUT_FILE" ]; then | ||
echo "!!! Error: invalid input file: ${INPUT_FILE}" >&2 | ||
exit 1 | ||
fi | ||
|
||
cp $SOURCE_FILE .env | ||
|
||
SECRET_KEY="$(openssl rand -base64 48)" | ||
sed -i -e "s/^SECRET_KEY=$/SECRET_KEY=$(echo $SECRET_KEY | sed -e 's/[\/&]/\\&/g')/" .env | ||
cp $INPUT_FILE .env | ||
|
||
sed -i -e "s/^SECRET_KEY=$/SECRET_KEY=$(echo $(openssl rand -base64 48) | sed -e 's/[\/&]/\\&/g')/" .env | ||
for var in $(env | sed -ne "s/\([^=]*\)=.*/\1/p" | uniq); do | ||
sed -i -e "s/^$var=$/$var=$(eval echo "\$$var" | sed -e 's/[\/&]/\\&/g')/" .env | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters