forked from closer/step-rails-database-yml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
48 lines (38 loc) · 1.59 KB
/
run.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
template_name=""
if [ -z $WERCKER_RAILS_DATABASE_YML_POSTGRESQL_MIN_MESSAGE ]; then
export WERCKER_RAILS_DATABASE_YML_POSTGRESQL_MIN_MESSAGE="warning"
fi
if [ ! -n "$WERCKER_RAILS_DATABASE_YML_SERVICE" ]; then
debug 'service option not specified, looking for services in the environment'
if [ -n "$WERCKER_MYSQL_HOST" ]; then
info 'mysql service found'
template_name="mysql"
elif [ -n "$WERCKER_POSTGRESQL_HOST" ]; then
info 'postgresql service found'
template_name="postgresql"
elif [ -n "$WERCKER_POSTGRESQL_DATABASE" ]; then
info 'postgresql local service found'
template_name="postgresql-local"
else
fail 'No compatible service defined in wercker.yml.\nSupported service are: mysql and postgresql.\n\nSee: http://devcenter.wercker.com/articles/services/'
fi
else
debug 'service option specified, will load specified template'
template_name="$WERCKER_RAILS_DATABASE_YML_SERVICE"
fi
info "using template $template_name"
template_filename="$WERCKER_STEP_ROOT/templates/$template_name.yml"
if [ ! -f "$template_filename" ]; then
fail "no template found with name $template_name"
else
config_filename="$PWD/config/database.yml"
if [ -f "$config_filename" ]; then
warn 'config/database.yml already exists and will be overwritten'
fi
# cp -f "$template_filename" "$config_filename"
sed \
-e "s;\$WERCKER_RAILS_DATABASE_YML_POSTGRESQL_MIN_MESSAGE;$WERCKER_RAILS_DATABASE_YML_POSTGRESQL_MIN_MESSAGE;g" \
"$template_filename" > "$config_filename";
info "created database.yml in config directory with content:"
info "$(cat "$config_filename")"
fi