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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
#!/bin/sh
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> <new-version>
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see /usr/share/doc/packaging-manual/
#
# quoting from the policy:
# Any necessary prompting should almost always be confined to the
# post-installation script, and should be protected with a conditional
# so that unnecessary prompting doesn't happen if a package's
# installation fails and the `postinst' is called with `abort-upgrade',
# `abort-remove' or `abort-deconfigure'.
set -e
# Use the same order as for mv
replace_file()
{
file_source="$1"
file_dest="$2"
if [ ! -f $file_source ]; then
echo "$file_source has already been moved"
else
if [ ! -f $file_dest ]; then
mv -v $file_source $file_dest || exit 10
else
echo "ucf --debconf-ok $file_source $file_dest"
ucf --debconf-ok $file_source $file_dest || exit 11
fi
chown www-data:www-data $file_dest
fi
}
update_localconfig()
{
sed -r \
-e "s/db_host[[:space:]]*=[[:space:]]*[\"'].*[\"']/db_host = '$dbserver'/g" \
-e "s/db_port[[:space:]]*=[[:space:]]*.*;/db_port = $dbport;/g" \
-e "s/db_name[[:space:]]*=[[:space:]]*[\"'].*[\"']/db_name = '$dbname'/g" \
-e "s/db_user[[:space:]]*=[[:space:]]*[\"'].*[\"']/db_user = '$dbuser'/g" \
-e "s/db_pass[[:space:]]*=[[:space:]]*[\"'].*[\"']/db_pass = '$dbpass'/g" \
-e "s/create_htaccess[[:space:]]*=[[:space:]]*.+;/create_htaccess = 0;/g"
}
create_answerfile()
{
answerfile="$1"
db_get "bugzilla3/bugzilla_admin_name"
bugzilla_admin="$RET"
db_get "bugzilla3/bugzilla_admin_real_name"
bugzilla_name="$RET"
db_get "bugzilla3/bugzilla_admin_pwd"
bugzilla_pwd="$RET"
echo "\$answer{'db_host'} = '$dbserver';" > $answerfile
echo "\$answer{'db_port'} = $dbport;" >> $answerfile
echo "\$answer{'db_name'} = '$dbname';" >> $answerfile
echo "\$answer{'db_user'} = '$dbuser';" >> $answerfile
echo "\$answer{'db_pass'} = q[\$db_pass = '$dbpass';];" >> $answerfile
echo "\$answer{'ADMIN_OK'} = 'Y';" >> $answerfile
echo "\$answer{'ADMIN_EMAIL'} = '$bugzilla_admin';" >> $answerfile
echo "\$answer{'ADMIN_PASSWORD'} = '$bugzilla_pwd';" >> $answerfile
echo "\$answer{'ADMIN_REALNAME'} = '$bugzilla_name';" >> $answerfile
echo "\$ansser{'NO_PAUSE'} = 1;" >> $answerfile
}
init_db_vars()
{
if [ -z "$dbport" ]; then
dbport="3306"
fi
if [ -z "$dbserver" ]; then
dbserver="localhost"
fi
if [ -z "$dbtype" ]; then
dbtype="mysql"
fi
}
get_db_variables()
{
# If dbconfig-common is correctly installed call it
if [ -f /usr/share/dbconfig-common/dpkg/postinst.mysql ]; then
. /usr/share/dbconfig-common/dpkg/postinst.mysql
dbvars_file=/etc/bugzilla3/dbconfig-params
dbc_generate_include=sh:$dbvars_file
dbc_go bugzilla3 $@
. $dbvars_file
echo "init_db_vars ($dbserver, $dbname, $dbuser, $dbpass)"
init_db_vars
# Else, we cannot continue the postinst phase
else
echo "bugzilla: ERROR -- dbconfig-common is not installed, cannot continue the postinstphase." >&2
exit 55
fi
}
cleanup()
{
# Do not remove backup of `params_dest` if new configuration is missing.
if [ -e "$params_backup" ]; then
if [ ! -e "$params_dest" ]; then
mv -f "$params_backup" "$params_dest"
else
rm "$params_backup"
fi
fi
rm -f "$answerfile" "$localconfig_new" "$params_new" /etc/bugzilla3/*.ucf-old
}
if [ "$1" = "configure" ]; then
# Debconf is needed here for the postinst-db.pl script
. /usr/share/debconf/confmodule
trap cleanup EXIT QUIT
params_src="/usr/share/bugzilla3/debian/params"
params_dest="/etc/bugzilla3/params"
params_backup=`mktemp -p /etc/bugzilla3 -t params.XXXXXXXXXX`
params_new="/etc/bugzilla3/params.new"
localconfig_src="/usr/share/bugzilla3/debian/localconfig"
localconfig_dest="/etc/bugzilla3/localconfig"
localconfig_new=`mktemp -p /etc/bugzilla3 -t localconfig.XXXXXXXXXX`
answerfile=`mktemp -p /etc/bugzilla3 -t answerfile.XXXXXXXXXX`
get_db_variables $@
# If there's no $params_dest yet, let's move our package version
# Note that if we upgraded a previous package, we might have already
# moved the previous params file to the right place.
if [ ! -e "$params_dest" ]; then
mkdir -p `dirname $params_dest`
cp -p "$params_src" "$params_dest"
fi
umask 0027
if [ -n "$dbserver" ] && [ -n "$dbuser" ] && [ -n "$dbpass" ]; then
echo "Creating new localconfig ($dbserver, $dbname, $dbuser, $dbpass)"
if [ -e $localconfig ]; then
cat $localconfig_src | update_localconfig > $localconfig_new
fi
# Only if the configuration file does not match the original we ask the user.
if cmp $localconfig_src $localconfig_dest; then
mv -f $localconfig_new $localconfig_dest
else
replace_file $localconfig_new $localconfig_dest || exit 8
rm -f $localconfig_new
fi
fi
# checksetup.pl write the new param file in /etc/bugzilla3/params
mv -f "$params_dest" "$params_backup"
# Call checksetup now that everything is ready
# The params file will then be updated if needed, the resulting file
# will be saved in $params_new
echo "Running checksetup.pl with answer file"
create_answerfile $answerfile
if [ ! -e $answerfile ]; then
echo >&2 "$0: Unable to find the answer file $answerfile for checksetup.pl"
exit 13
fi
$DEBIAN_DEBUG_CHECKSETUP /usr/share/bugzilla3/lib/checksetup.pl $answerfile --verbose | \
sed -e 's,/usr/bin/perl .*install "Template::Plugin::GD::Image".*,apt-get install libtemplate-plugin-gd-perl,g' \
-e 's,/usr/bin/perl .*install "HTML::Scrubber".*,apt-get install libhtml-scrubber-perl,g' \
-e 's,/usr/bin/perl .*install "mod_perl2".*,apt-get install libapache2-mod-perl2,g' \
-e 's,/usr/bin/perl .*install "MIME::Parser".*,apt-get install libmime-tools-perl,g' \
-e 's,/usr/bin/perl .*install "CGI".*,apt-get install libcgi-pm-perl,g' \
-e 's,/usr/bin/perl .*install "SOAP::Lite".*,apt-get install libsoap-lite-perl,g' \
-e 's,/usr/bin/perl .*install "Chart::Base".*,apt-get install libchart-perl,g' \
-e 's,/usr/bin/perl .*install "GD".*,apt-get install libgd-gd2-perl,g' \
-e 's,/usr/bin/perl .*install "GD::Text".*,apt-get install libgd-text-perl,g' \
-e 's,/usr/bin/perl .*install "GD::Graph".*,apt-get install libgd-graph-perl,g' \
-e 's,/usr/bin/perl .*install "XML::Twig".*,apt-get install libxml-twig-perl,g' \
-e 's,/usr/bin/perl .*install "LWP::UserAgent".*,apt-get install libwww-perl,g' \
-e 's,/usr/bin/perl .*install "Image::Magic".*,apt-get install perlmagic,g' \
-e 's,/usr/bin/perl .*install "Net::LDAP".*,apt-get install libnet-ldap-perl,g' \
-e 's,/usr/bin/perl .*install "HTML::Parser".*,apt-get install libhtml-parser-perl,g'
if [ ! -e "$params_dest" ]; then
echo >&2 "$0: Configuration of bugzilla3 failed. Please check if the system requirements are fulfilled."
exit 14
fi
mv -f $params_dest $params_new
# Restore old configuration
mv -f $params_backup $params_dest
# Only if the file does not match the original we ask the user.
if cmp $params_dest $params_src; then
mv -f $params_new $params_dest
else
# Now, let's ask our fellow user if he likes to use it
replace_file $params_new $params_dest
fi
# Let's fix the permissions for the /var/lib directory
datadir=/var/lib/bugzilla3
chown -R www-data:www-data $datadir
chmod -R g+rw $datadir
chmod -R u+rw $datadir
chown -R www-data:www-data /etc/bugzilla3
# fix the permission for the contrib files
if [ -d /usr/share/bugzilla3/contrib ]; then
find /usr/share/bugzilla3/contrib -name '*.pl' -exec chmod a+x {} \;
find /usr/share/bugzilla3/contrib -name '*.sh' -exec chmod a+x {} \;
fi
# update all the bugzilla sites
if [ -d /etc/bugzilla3/sites ]; then
for site in `cd /etc/bugzilla3/sites/ && ls -1`; do
echo "Running checksetup.pl for site: $site"
X_BUGZILLA_SITE="$site" /usr/share/bugzilla3/lib/checksetup.pl
done
fi
cleanup
# Let's close cleanly debconf
db_stop
fi
#DEBHELPER#
|