Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
🎨 Better name the arguments on setup-* scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieconnolly committed Jan 2, 2017
1 parent 116c082 commit 2bc896a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 7 additions & 9 deletions libexec/handles-setup-dotenv
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
17 changes: 10 additions & 7 deletions libexec/handles-setup-nginx-conf
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#!/bin/bash
# Usage: handles-setup-nginx-conf <project_name> [<source_file>]
# Usage: handles-setup-nginx-conf <project_name> [<input_file>]
# Summary: Generate an nginx server configuration file

set -e
cd "$(git rev-parse --show-toplevel)"

INPUT_FILE="${2-"nginx.conf.erb"}"
OUTPUT_FILE="${PWD}/${INPUT_FILE//.erb}"
PROJECT_NAME="$1"
SOURCE_FILE="${2-"nginx.conf.erb"}"

if [ -z "$PROJECT_NAME" ] || [ -z "$SOURCE_FILE" ]; then
if [ -z "$PROJECT_NAME" ] || [ -z "$INPUT_FILE" ]; then
handles help setup-nginx-conf >&2
exit 1
elif [ ! -f "$SOURCE_FILE" ] || [[ "$SOURCE_FILE" != *.erb ]]; then
echo "!!! Error: invalid source file: ${SOURCE_FILE}" >&2
elif [ ! -f "$INPUT_FILE" ] || [[ "$INPUT_FILE" != *.erb ]]; then
echo "!!! Error: invalid input file: ${INPUT_FILE}" >&2
exit 1
elif ! command -v nginx &>/dev/null; then
echo "!!! Error: nginx is not installed" >&2
exit 1
fi

OUTPUT_FILE="${PWD}/${SOURCE_FILE//.erb}"
erb $SOURCE_FILE > $OUTPUT_FILE
if ! erb $INPUT_FILE > $OUTPUT_FILE; then
echo "!!! Error: failed to generate nginx configuration file" >&2
exit 1
fi

if [ "$(uname -s)" = "Darwin" ]; then
PREFIX="$(brew --prefix)"
Expand Down

0 comments on commit 2bc896a

Please sign in to comment.