046d5abdd5ef482adc4925380e16bc3d3cdaab3c
[platal.git] / upgrade / inc / pervasive.sh
1 #!/bin/bash
2
3 MYSQL='mysql -u admin '
4
5
6 set -e
7
8 if [ "$UID" != 0 ] && [ "$1" != "-u" ] ; then
9 echo "has to be run as root"
10 exit 1
11 fi
12
13 if [[ -n "${DBPREFIX}" ]]; then
14 echo "Using non-default database ${DBPREFIX}x4dat."
15 fi
16 if [[ -z "${DATABASE}" ]]; then
17 DATABASE="${DBPREFIX}x4dat"
18 fi
19
20 function die() {
21 echo $1
22 exit 1
23 }
24
25 function confirm() {
26 if [[ -n "${NO_CONFIRM}" ]]; then
27 echo "$1"
28 echo "* press ^C to cancel, waiting 5 seconds..."
29 sleep 5
30 else
31 echo "$1"
32 echo "* press ^D to start import (^C to cancel)"
33 cat
34 fi
35 }
36
37 function mysql_pipe() {
38 sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" | $MYSQL $DATABASE
39 }
40
41 function mysql_exec() {
42 echo -n " * executing $1 "
43 if [[ -z "${DRY_RUN}" ]]; then
44 (echo $1 | mysql_pipe) || die "ERROR"
45 fi
46 echo "OK"
47 }
48
49 function mysql_pipe_nodb() {
50 sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" | $MYSQL
51 }
52
53 function mysql_exec_nodb() {
54 echo -n " * executing $1 "
55 if [[ -z "${DRY_RUN}" ]]; then
56 (echo $1 | mysql_pipe_nodb) || die "ERROR"
57 fi
58 echo "OK"
59 }
60
61 function mysql_run() {
62 echo -n " * running $1 "
63 if [[ -z "${DRY_RUN}" ]]; then
64 (cat $1 | mysql_pipe) || die "ERROR"
65 fi
66 echo "OK"
67 }
68
69 function mysql_run_directory() {
70 for sql in $1/*.sql ; do
71 mysql_run $sql
72 done
73 }
74
75 function script_run() {
76 echo -n " * running $1 "
77 if [[ -z "${DRY_RUN}" ]]; then
78 $1 || die "ERROR"
79 fi
80 echo "OK"
81 }
82
83 function mailman_stop() {
84 echo -n " * stops mailman"
85 if [[ -z "${DRY_RUN}" ]]; then
86 /etc/init.d/mailman stop &>/dev/null
87 fi
88 echo .
89 }
90
91 function mailman_templates() {
92 echo -n " * copies new mails templates"
93 if [[ -z "${DRY_RUN}" ]]; then
94 mkdir -p /etc/mailman/xorg
95 cp -f ../../modules/lists/mail_templates/*.txt /etc/mailman/xorg
96 fi
97 echo .
98 }
99
100 function mailman_start() {
101 echo -n " * starts mailman"
102 if [[ -z "${DRY_RUN}" ]]; then
103 /etc/init.d/mailman start &>/dev/null
104 fi
105 echo .
106 }