~mythbuntu/mythbuntu/mythbuntu

37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
1
#! /bin/sh -e
2
#Passes on the information gathered in ubiquity
3
#about mythtv package variable
4
# Copyright (C) 2007 Mario Limonciello
5
# Written by Mario Limonciello <superm1@ubuntu.com>
6
7
. /usr/share/debconf/confmodule
8
9
if [ "$1" ]; then
10
	ROOT="$1"
11
	chroot=chroot
12
	log='log-output -t mythbuntu'
13
else
14
	ROOT=
15
	chroot=
16
	log=
17
fi
18
47 by Mario Limonciello
new theme for gtk
19
#Either way, turn off mysql,mythtv-backend, apache if it running
20
/etc/init.d/mysql stop
21
/etc/init.d/mythtv-backend stop
22
/etc/init.d/apache2 stop
23
24
# Prepare mythtv-common
25
# And copy over env as needed
37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
26
local USER
27
local PASSWORD
28
local DB
29
local HOSTNAME
30
db_get mythtv/mysql_mythtv_user
31
USER="$RET"
47 by Mario Limonciello
new theme for gtk
32
db_get mythtv/mysql_PASSWORD
37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
33
PASSWORD="$RET"
39 by Mario Limonciello
add resultant user to mythtv group
34
if [ -z "$PASSWORD" ]; then
35
	#in case the password screen isn't shown
36
	#or if they forget to enter one
37
	set +e
38
	PASSWORD="$(pwgen -s 8)"
39
	set -e
40
fi
37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
41
db_get mythtv/mysql_mythtv_dbname
42
DB="$RET"
43
db_get mythtv/mysql_host
44
HOSTNAME="$RET"
47 by Mario Limonciello
new theme for gtk
45
if [ -z "$HOSTNAME" ]; then
46
	HOSTNAME="localhost"
47
fi
37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
48
cat <<EOF >$ROOT/tmp/myth_setup
49
#! /bin/sh
50
set -e
51
52
. /usr/share/debconf/confmodule	
53
db_set mythtv/mysql_mythtv_user $USER
47 by Mario Limonciello
new theme for gtk
54
db_set mythtv/mysql_PASSWORD $PASSWORD
37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
55
db_set mythtv/mysql_mythtv_dbname $DB
56
db_set mythtv/mysql_host $HOSTNAME
38 by Mario Limonciello
add the start of seed support
57
58
cat /etc/mythtv/mysql.txt | grep -v 'DBPassword=' | sed -e "
59
s/^\(\(str  *\)\?DBHostName\)=.*$/\1=$HOSTNAME/g;
60
s/^\(\(str  *\)\?DBUserName\)=.*$/\1=$USER/g;
61
s/^\(\(str  *\)\?DBName\)=.*$/\1=$DB/g;" > /etc/mythtv/mysql.txt.dist
62
cat <<EOF2 >> /etc/mythtv/mysql.txt.dist
63
DBPassword=$PASSWORD
64
EOF2
65
mv /etc/mythtv/mysql.txt.dist /etc/mythtv/mysql.txt
66
exit 0
37 by Mario Limonciello
big changes all around ubiquity. we should be able to go through
67
EOF
68
chmod +x $ROOT/tmp/myth_setup
69
$log $chroot $ROOT /tmp/myth_setup
70
rm $ROOT/tmp/myth_setup
71
47 by Mario Limonciello
new theme for gtk
72
#Check for needing to set up a DB too
73
#If so - do it
74
db_get mythbuntu/install_type
75
TYPE="$RET"
76
if [ "$TYPE" = "Master Backend/Frontend" -o "$TYPE" = "Master Backend" ]; then
77
	local ADMINUSER
78
	local ADMINPASS
79
	db_get mythtv/mysql_admin_user
80
	ADMINUSER="$RET"
81
	db_get mythtv/mysql_ADMINPASS
82
	ADMINPASS="$RET"
83
	cat <<DBSETUP >$ROOT/tmp/db_setup
84
#!/bin/sh
85
#Sets up mythtv-database on a new mythbuntu
86
#installation
87
#Copyright (C) 2007 Mario Limonciello
88
89
escape_quotes() {
90
    cat <<EOF | sed -e "s/'/\\\\'/g"
91
$1
92
EOF
93
}
94
95
DoSQL() {
96
    local host="$1"
97
    local ADMINUSER="$2"
98
    local ADMINPASS="$3"
99
    local DB="$4"
100
    local statement="`escape_quotes \"$5\"`"
101
    local tmp=`tempfile -m 600`
102
        cat <<EOF >$tmp
103
$ADMINPASS
104
EOF
105
    perl -e "
106
use DBI;
107
chomp(\$password=<>);
108
@statements=split(/;/, '$statement');
109
\$db = DBI->connect('dbi:mysql:host=$host;DB=$DB',
110
                    '$ADMINUSER', \$password,
111
                    { PrintError => 0 }) || die 'Failed to connect to DB: ' . \$DBI::errstr;
112
for \$s (@statements) { \$db->do(\$s) || die 'Failed to execute SQL: ' . \$s . '\n' . \$DBI::errstr; }
113
" < $tmp
114
    ret=$?
115
    rm -f $tmp
116
    return $ret
117
}
118
119
#Start SQL
120
/etc/init.d/mysql start
121
122
#Set our new defaults that were determined to debconf
123
. /usr/share/debconf/confmodule
124
db_set mythtv/mysql_admin_user $ADMINUSER
125
db_set mythtv/mysql_ADMINPASS $ADMINPASS
126
127
#Setup the mysql server with the new defaults
128
DoSQL "$HOSTNAME" "$ADMINUSER" "$ADMINPASS" "$DB" "SELECT NULL"
129
DoSQL "$HOSTNAME" "$ADMINUSER" "$ADMINPASS" "" "CREATE DATABASE $DB"
130
DoSQL "$HOSTNAME" "$ADMINUSER" "$ADMINPASS" "$DB" "GRANT ALL PRIVILEGES ON $DB.* TO $USER@localhost IDENTIFIED BY '$PASSWORD'"
131
DoSQL "$HOSTNAME" "$ADMINUSER" "$ADMINPASS" "$DB" "GRANT ALL PRIVILEGES ON $DB.* TO $USER@'%' IDENTIFIED BY '$PASSWORD'"
132
133
#Stop SQL
134
/etc/init.d/mysql stop
135
DBSETUP
136
chmod +x $ROOT/tmp/db_setup
137
$log $chroot $ROOT /tmp/db_setup
138
rm $ROOT/tmp/db_setup
139
fi
140
141
exit 0