-
Notifications
You must be signed in to change notification settings - Fork 14
/
install-merlin.sh.in
executable file
·97 lines (83 loc) · 2.57 KB
/
install-merlin.sh.in
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
#!/bin/bash
# common variables used in default rules:
prefix=@prefix@
exec_prefix=@exec_prefix@
sqldir=@datarootdir@/merlin/sql
db_type=@db_type@
db_name=@db_name@
db_user=@db_user@
db_pass=@db_pass@
abort ()
{
echo "$@"
echo "Aborting."
exit 1
}
db_setup ()
{
mysql="mysql"
if [ -n "$db_user" ]; then
mysql="$mysql -u$db_user"
test -n "$db_pass" && mysql="$mysql -p$db_pass"
fi
case "$db_type" in
mysql)
$(eval "$mysql -e 'use $db_name'")
if [ $? -ne 0 ]; then
echo "Couldn't connect to database, giving up."
echo ""
echo "Make sure there is a $db_type database called '$db_name',"
echo "that $db_user can access it, and that you have provided the correct password"
echo ""
echo "Something similar to the below, depending on your mysql user login, should work:"
echo " mysql -uroot -e \"CREATE DATABASE IF NOT EXISTS $db_name\""
echo " mysql -uroot -e \"GRANT ALL ON $db_name.* TO $db_user@localhost IDENTIFIED BY '<password>'\""
exit 1
fi
test -z "$(eval "$mysql -f $db_name -se \"SHOW TABLES\"")"
new_install=$?
eval "$mysql -f $db_name" < $sqldir/mysql/merlin.sql
# Fetch db_version and do upgrade stuff if/when needed
query="SELECT version FROM db_version"
db_version=$(eval "$mysql $db_name -BNe \"$query\"")
# Check for upgrade scripts
ver=$db_version
if test "$db_version"; then
while true; do
nextver=$((ver+1))
f="$sqldir/update-db-${ver}to${nextver}.sql"
test -f "$f" || break
eval "$mysql $db_name" < $f || abort "Incremental database upgrade from version $ver to version $nextver failed!"
eval "$mysql $db_name -e \"UPDATE db_version SET version=$nextver\"" || abort "Failed to set new database version $nextver!"
ver=$nextver
done
fi
if [ $new_install -eq 0 ]; then
for index in $sqldir/mysql/*-indexes.sql; do
eval "$mysql -f $db_name" < $index
done
else
# only check for indexes in report_data. sloppy, yes, but should be sufficient
idx=$(eval "$mysql $db_name -N -s -e \"SHOW INDEX IN report_data\"" | wc -l);
if [ $idx -eq '1' ]; then
cat <<EOF
***************
*** WARNING ***
***************
Some of your tables lack indexes, which might cause bad performance.
Installing indexes might take quite some time (several hours for big installations), so I'm going
to let you install them when it's convenient for you.
To install them manually, run:
mon db fixindexes
EOF
fi
fi
;;
*)
echo "Unknown database type '$db_type'"
echo "I understand only lower-case database types."
return 0
;;
esac
}
db_setup