-
Notifications
You must be signed in to change notification settings - Fork 34
/
createdb
executable file
·115 lines (98 loc) · 3.07 KB
/
createdb
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
set -e -u
case $(pwd) in
/usr/src/app) ;;
*) echo "$0: this should only be run from the Dockerfile inside the image" >&2
exit 33;;
esac
if [ -d import ]; then
for redis in import/*.rdb.gz; do
if [ -e "$redis" ]; then
echo "$0: importing $redis" >&2
gzip -dc "$redis" >dump.rdb
chmod 644 dump.rdb
# chown redis:redis dump.rdb
rm -f "$redis"
else
echo "$0: No files matching $redis" >&2
exit 124
fi
done
fi
./services
mysql -u root -ppassword <<\____
# Create the metasmoke database and metasmoke_test database
CREATE DATABASE metasmoke;
CREATE DATABASE metasmoke_test;
CREATE DATABASE metasmoke_production;
# Create the metasmoke user and password.
# This user will only be able to access MySQL locally.
# You should still select a strong password.
# Grant this user privileges on the metasmoke database
CREATE USER 'metasmoke'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON `metasmoke`.* TO `metasmoke`@`localhost`;
GRANT ALL PRIVILEGES ON `metasmoke_test`.* TO `metasmoke`@`localhost`;
GRANT ALL PRIVILEGES ON `metasmoke_production`.* TO `metasmoke`@`localhost`;
FLUSH PRIVILEGES;
____
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
sed '/^development:/!b;x;N;N;x;a\
adapter: mysql2\
database: metasmoke\
encoding: utf8\
username: metasmoke\
password: password\
host: 127.0.0.1\
port: 3306
q' config/database.sample.yml >config/database.yml
sed 's/localhost/127.0.0.1/' config/config.sample.yml >config/config.yml
sed 's/localhost/127.0.0.1/' config/cable.sample.yml >config/cable.yml
rails db:create
rails db:schema:load
rails db:migrate
# rails db:seed
enableregistration=false
localmetasmoke=false
if [ -d import ]; then
if [ -e import/metasmoke@localhost ]; then
localmetasmoke=true
fi
for sql in import/*.sql.gz; do
if [ -e "$sql" ]; then
echo "$0: importing $sql (this takes a long time)" >&2
######## FIXME: yet another hard-coded, easily guessable password
gzip -dc <"$sql" |
sed 's/dump_metasmoke/metasmoke/g' |
mysql -u root -ppassword metasmoke
rm -f "$sql"
else
echo "$0: No files matching $sql" >&2
exit 123
fi
break
done
else
enableregistration=true
localmetasmoke=true
fi
if [ "$localmetasmoke" = true ]; then
echo "$0: creating metasmoke@localhost user" >&2
######## FIXME: yet another hard-coded, easily guessable password
rails c <<\____
u = User.create(
username: 'metasmoke', email: 'metasmoke@localhost', password: 'password')
u.add_role(:admin)
u.add_role(:developer)
u.add_role(:reviewer)
u.add_role(:flagger)
u.add_role(:core)
a = APIKey.create(
user: u, key: "00000000000000000000000000000000", app_name: "test")
____
fi
if [ "$enableregistration" = true ]; then
echo "$0: setting registration_enabled" >&2
rails c <<\____
SiteSetting.create(name: 'registration_enabled', value: 1)
____
fi