Commit | Line | Data |
---|---|---|
6855525e JL |
1 | #!/bin/bash -e |
2 | ||
3 | RANDOMDEVICE=/dev/urandom | |
4 | allowed=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./ | |
5 | declare -a RVAL | |
6 | ||
7 | second () { | |
8 | echo $2 | |
9 | } | |
10 | ||
11 | create-random-pw() { | |
12 | if ! read -n 0 < $RANDOMDEVICE ; then | |
13 | echo 1>&2 "Warning, no random device found, password might be insecure" | |
14 | for i in 0 1 2 3 4 5 6 7; do | |
15 | RVAL[i]=$RANDOM | |
16 | done | |
17 | else | |
18 | for i in 0 1 2 3 4 5 6 7; do | |
19 | RVAL[i]=$(second $(od -N 1 -t d $RANDOMDEVICE)) | |
20 | done | |
21 | fi | |
22 | ||
23 | PW="" | |
24 | for i in 0 1 2 3 4 5 6 7; do | |
25 | idx=$((${RVAL[i]} & 0x3F)) | |
26 | PW="${PW}${allowed:$idx:1}" | |
27 | done | |
28 | ||
29 | printf "%s" $PW | |
30 | } | |
31 | ||
32 | # this function comes from wwwconfig-common's apache.func script | |
33 | getwwwoption() { | |
34 | getwwwoption="" | |
35 | if [ -f $2 ] ; then | |
36 | if grep $1 $2 | grep -v "#" > /dev/null 2>&1 ; then | |
37 | getwwwoption=$(sed -ne "/^[[:space:]]*$1[[:space:]]\+/ s|[[:space:]]*$1[[:space:]]\+\([^[:space:]]\+\)[[:space:]]*$|\1|pg;" < $2) | |
38 | fi | |
39 | fi | |
40 | } | |
41 | ||
42 | ||
43 | # Use debconf baby | |
44 | . /usr/share/debconf/confmodule | |
45 | db_version 2.0 | |
46 | db_title Diogenes | |
47 | ||
48 | db_input "low" "diogenes/welcome" || true | |
49 | db_go | |
50 | db_input "high" "diogenes/purge_removes_data" || true | |
51 | db_go | |
52 | ||
53 | ### Required options no matter what ### | |
54 | db_input "high" "diogenes/webservers" || true | |
55 | db_go | |
56 | db_get "diogenes/webservers" | |
57 | webservers="$RET" | |
58 | ||
59 | # if a single webserver is selected, | |
60 | # try to get the user and group the webserver runs as | |
61 | nbsrv=0 | |
62 | for i in $webservers ; do nbsrv=`expr $nbsrv + 1`; done | |
63 | ||
64 | if [ $nbsrv == 1 ]; then | |
65 | server=$(echo $webservers | sed 's/,$//') | |
66 | if [ -f /etc/$server/httpd.conf ]; then | |
67 | getwwwoption User /etc/$server/httpd.conf | |
68 | webuser=$(echo "$getwwwoption" | sed -e "q") | |
69 | getwwwoption Group /etc/$server/httpd.conf | |
70 | webgroup=$(echo "$getwwwoption" | sed -e "q") | |
71 | fi | |
72 | fi | |
73 | ||
74 | if [ -z "$webuser" ]; then | |
75 | db_input "high" "diogenes/webuser" || true | |
76 | db_go | |
77 | else | |
78 | db_set "diogenes/webuser" "$webuser" | |
79 | fi | |
80 | if [ -z "$webgroup" ]; then | |
81 | db_input "high" "diogenes/webgroup" || true | |
82 | db_go | |
83 | else | |
84 | db_set "diogenes/webgroup" "$webgroup" | |
85 | fi | |
86 | ||
87 | db_input "high" "diogenes/databasemgr_type" || true | |
88 | db_go | |
89 | db_get "diogenes/databasemgr_type" | |
90 | dbtype="$RET" | |
91 | ||
92 | if [ "$dbtype" = "Automatic" ] ; then | |
93 | db_input "high" "diogenes/databasemgr_server" || true | |
94 | db_go | |
95 | db_input "high" "diogenes/dbmyadmin" || true | |
96 | db_go | |
97 | db_input "critical" "diogenes/dbadmpass" || true | |
98 | db_go | |
99 | db_input "medium" "diogenes/database_name" || true | |
100 | db_go | |
101 | db_input "medium" "diogenes/database_user" || true | |
102 | db_go | |
103 | db_input "medium" "diogenes/database_pass" || true | |
104 | db_go | |
105 | db_get "diogenes/database_pass" | |
106 | dbpass="$RET" | |
107 | if [ "$dbpass" = "auto" ]; then | |
108 | dbpass=$(create-random-pw) | |
109 | elif [ "$dbpass" = "none" ]; then | |
110 | dbpass="" | |
111 | fi | |
112 | db_set "diogenes/database_pass" "$dbpass" | |
113 | ||
114 | fi |