generated from rootstrap/rails_api_base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·75 lines (61 loc) · 1.79 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
die () {
echo >&2 "$@"
exit 1
}
usage() {
cat << EOF
Usage: $0 --name=<project-name> -[vhd]
-h, --help Display help
-n, --name Project name
-d, --for-docker Run bootstrap to run project with Docker
-v, --verbose Run script in verbose mode. Will print out each step of execution.
EOF
}
docker=0
project_name=""
while getopts n:vhd-: OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
n|name)
project_name="$OPTARG"
;;
d|for-docker)
[ -n $(which docker-compose) ] || die "$OPTARG was specified but docker-compose is not installed. Please install docker-compose to run bootstrap for docker"
docker=1
;;
h|help)
usage
exit 0
;;
v|verbose)
set -exu
;;
*)
die "Invalid option: run $0 --help for more information"
;;
esac
done
shift $((OPTIND-1))
if [[ -z $project_name ]]; then
die "Please specify the project name. Run $0 --help for more information"
fi
# generate a .env from the sample file
cp .env.sample .env
# update project name in database.yml
# sed command implementation is different for GNU and macOS
if [[ $OSTYPE == 'darwin'* ]]; then
sed -i '' "s/rails_api_base/${project_name}/g" config/database.yml
else
sed -i "s/rails_api_base/${project_name}/g" config/database.yml
fi
# spin up docker services if flag is specified for the setup to take place inside the containers
if [[ $docker -eq 1 ]]; then
docker-compose up --build --detach
fi
# install ruby gems
bin/setup