postinst is in pluxml 5.5-2.
This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.
The actual contents of the file can be viewed below.
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | #!/bin/sh
set -e
# 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>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
# Blog configuration and initial content are writtent by functions which are
# called from the main script, mostly to avoid polluting it with indentation
# violation produced by the uses of `cat << EOF`.
# Generate Apache configuration, managed by ucf
# No dynamic part yet, but there may be, so better use ucf from the beginning
write_apache2_conf()
{
apache2_conf="$(tempfile)"
cat >> "$apache2_conf" <<- EOF
# apache2 configuration file for pluxml
Alias /pluxml /usr/share/pluxml
<Directory /usr/share/pluxml>
<IfModule mod_rewrite.c>
# Uncomment to implement server-side URL rewriting
#RewriteEngine on
#RewriteBase /pluxml
#RewriteRule ^config.php - [L]
#RewriteRule ^core/ - [L]
#RewriteRule ^data/ - [L]
#RewriteRule ^feed.php - [L]
#RewriteRule ^index.php - [L]
#RewriteRule ^plugins/ - [L]
#RewriteRule ^sitemap.php - [L]
#RewriteRule ^themes/ - [L]
#RewriteRule ^update/ - [L]
#RewriteRule ^feed/(.*)$ feed.php?$1 [L]
#RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
</Directory>
<Directory /var/lib/pluxml/data>
Options -Indexes
</Directory>
<DirectoryMatch "^/var/lib/pluxml/data/(articles|commentaires|configuration|statiques)">
Require all denied
</DirectoryMatch>
EOF
# Install file with ucf
ucf --debconf-ok "$apache2_conf" /etc/pluxml/apache2.conf
ucfr pluxml /etc/pluxml/apache2.conf
# Remove temporary file
rm -f "$apache2_conf"
}
# Enable apache2 configuration
enable_apache2_conf()
{
if [ -d /etc/apache2/conf-available -a ! -e /etc/apache2/conf-available/pluxml.conf ]
then
ln -s /etc/pluxml/apache2.conf /etc/apache2/conf-available/pluxml.conf
if [ -e /usr/share/apache2/apache2-maintscript-helper ]
then
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke enconf pluxml
fi
fi
}
# Reload apache2
reload_apache2()
{
# Nothing, since `apache2_invoke enconf` already did what had to be done
:
}
# Write lighttpd configuration, managed by ucf
# No dynamic part yet, but there may be, so better use ucf from the beginning
write_lighttpd_conf()
{
lighttpd_conf="$(tempfile)"
cat >> "$lighttpd_conf" <<- EOF
# lighttpd configuration file for pluxml
alias.url += ("/pluxml" => "/usr/share/pluxml")
EOF
# Install file with ucf
ucf --debconf-ok "$lighttpd_conf" /etc/pluxml/lighttpd.conf
ucfr pluxml /etc/pluxml/lighttpd.conf
# Remove temporary file
rm -f "$lighttpd_conf"
}
# Enable lighttpd configuration
enable_lighttpd_conf()
{
if [ -d /etc/lighttpd/conf-available -a ! -e /etc/lighttpd/conf-available/50-pluxml.conf ]
then
ln -s /etc/pluxml/lighttpd.conf /etc/lighttpd/conf-available/50-pluxml.conf
if command -v lighty-enable-mod >/dev/null 2>/dev/null
then
lighty-enable-mod pluxml
fi
fi
}
# Reload lighttpd
reload_lighttpd()
{
# That may fail if lighttpd is not running: this is not a real problem, so
# ignore it
invoke-rc.d lighttpd reload || true
}
# Generate blog configuration, managed by ucf
write_pluxml_conf()
{
# Install special permissions overrides if requested
db_get pluxml/system/writeconf
writeconf="$RET"
if [ "$writeconf" = "true" ]
then
if ! dpkg-statoverride --list /etc/pluxml >/dev/null 2>&1
then
dpkg-statoverride --update --add root www-data 0775 /etc/pluxml
fi
if ! dpkg-statoverride --list /etc/pluxml/plugins >/dev/null 2>&1
then
dpkg-statoverride --update --add root www-data 0775 /etc/pluxml/plugins
fi
fi
# Creating main configuration file
pluxml_parameters="$(tempfile)"
db_get pluxml/blog/title
title="$RET"
db_get pluxml/blog/description
description="$RET"
db_get pluxml/blog/lang
lang="$RET"
if [ -e /etc/pluxml/adminkey ]
then
clef="$(grep -v '^#' /etc/pluxml/adminkey)"
else
clef="$(cat /dev/urandom| tr -dc A-Za-z | head -c15)"
fi
cat >> "$pluxml_parameters" <<- EOF
<?xml version="1.0" encoding="UTF-8"?>
<document>
<parametre name="title"><![CDATA[$title]]></parametre>
<parametre name="description"><![CDATA[$description]]></parametre>
<parametre name="meta_description"><![CDATA[$description]]></parametre>
<parametre name="meta_keywords"><![CDATA[]]></parametre>
<parametre name="timezone"><![CDATA[localtime]]></parametre>
<parametre name="allow_com">1</parametre>
<parametre name="mod_com">0</parametre>
<parametre name="mod_art">0</parametre>
<parametre name="capcha">1</parametre>
<parametre name="style"><![CDATA[defaut]]></parametre>
<parametre name="clef"><![CDATA[$clef]]></parametre>
<parametre name="bypage">5</parametre>
<parametre name="bypage_archives">5</parametre>
<parametre name="bypage_admin">10</parametre>
<parametre name="bypage_admin_coms">10</parametre>
<parametre name="bypage_feed">8</parametre>
<parametre name="tri"><![CDATA[desc]]></parametre>
<parametre name="tri_coms"><![CDATA[asc]]></parametre>
<parametre name="images_l">800</parametre>
<parametre name="images_h">600</parametre>
<parametre name="miniatures_l">200</parametre>
<parametre name="miniatures_h">100</parametre>
<parametre name="thumbs">1</parametre>
<parametre name="medias"><![CDATA[data/medias/]]></parametre>
<parametre name="documents"><![CDATA[data/documents/]]></parametre>
<parametre name="racine_articles"><![CDATA[../../../var/lib/pluxml/data/articles/]]></parametre>
<parametre name="racine_commentaires"><![CDATA[../../../var/lib/pluxml/data/commentaires/]]></parametre>
<parametre name="racine_statiques"><![CDATA[../../../var/lib/pluxml/data/statiques/]]></parametre>
<parametre name="racine_themes"><![CDATA[themes/]]></parametre>
<parametre name="racine_plugins"><![CDATA[plugins/]]></parametre>
<parametre name="homestatic"><![CDATA[]]></parametre>
<parametre name="hometemplate"><![CDATA[home.php]]></parametre>
<parametre name="urlrewriting">0</parametre>
<parametre name="gzip">0</parametre>
<parametre name="feed_chapo">0</parametre>
<parametre name="feed_footer"><![CDATA[]]></parametre>
<parametre name="version"><![CDATA[5.5]]></parametre>
<parametre name="default_lang"><![CDATA[$lang]]></parametre>
<parametre name="userfolders">0</parametre>
<parametre name="display_empty_cat">0</parametre>
<parametre name="custom_admincss_file"><![CDATA[]]></parametre>
</document>
EOF
# Set correct permissions
chown root:www-data "$pluxml_parameters"
if [ "$writeconf" = "true" ]
then
chmod 664 "$pluxml_parameters"
else
chmod 644 "$pluxml_parameters"
fi
# Install file with ucf
ucf --debconf-ok "$pluxml_parameters" /etc/pluxml/parametres.xml
ucfr pluxml /etc/pluxml/parametres.xml
# Remove temporary file
rm -f "$pluxml_parameters"
keyfile="$(tempfile)"
cat >> "$keyfile" <<- EOF
# Secret string used to restrict access to private RSS feeds such as online and
# offline comments. This key is stored in parametres.xml, parameter name
# "clef". This file exists to save it to keep the pluxml Debian package
# configuration during upgrades.
$clef
EOF
ucf --debconf-ok "$keyfile" /etc/pluxml/adminkey
ucfr pluxml /etc/pluxml/adminkey
# Remove temporary file
rm -f "$keyfile"
# Create user list file
# Do not touch user lists of existing installations unless the user really
# wants to reconfigure (in which case, the password will not be empty)
db_get pluxml/blog/password
password="$RET"
if [ ! -e /etc/pluxml/users.xml -o -n "$password" ]
then
pluxml_users="$(tempfile)"
db_get pluxml/blog/name
name="$RET"
db_get pluxml/blog/login
login="$RET"
db_get pluxml/blog/password
password="$RET"
salt="$(cat /dev/urandom| tr -dc A-Za-z | head -c10)"
password="$(printf '%s' "$password" | md5sum | cut -d' ' -f1)"
password="$(printf '%s%s' "$salt" "$password" | sha1sum | cut -d' ' -f1)"
# Remove password from debconf database
db_set pluxml/blog/password ""
db_set pluxml/blog/confirm ""
cat >> "$pluxml_users" <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<document>
<user number="001" active="1" profil="0" delete="0">
<login><![CDATA[$login]]></login>
<name><![CDATA[$name]]></name>
<infos><![CDATA[]]></infos>
<password><![CDATA[$password]]></password>
<salt><![CDATA[$salt]]></salt>
<email></email>
<lang><![CDATA[$lang]]></lang>
</user>
</document>
EOF
# Set correct permissions
chown root:www-data "$pluxml_users"
if [ "$writeconf" = "true" ]
then
chmod 660 "$pluxml_users"
else
chmod 640 "$pluxml_users"
fi
# Install file with ucf
ucf --debconf-ok "$pluxml_users" /etc/pluxml/users.xml
ucfr pluxml /etc/pluxml/users.xml
# Remove temporary file
rm -f "$pluxml_users"
fi
}
# Generate default blog content, which should be neither part of the package
# files nor managed configuration
write_pluxml_content()
{
if [ ! -e /var/lib/pluxml/data/configuration/plugins.xml ]
then
cat >> /var/lib/pluxml/data/configuration/plugins.xml <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<document>
</document>
EOF
chown www-data:root /var/lib/pluxml/data/configuration/plugins.xml
fi
if [ ! -e /var/lib/pluxml/data/configuration/categories.xml ]
then
cat >> /var/lib/pluxml/data/configuration/categories.xml <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<document>
<categorie number="001" active="1" homepage="1" tri="desc" bypage="5" menu="oui" url="caregory-1" template="categorie.php">
<name><![CDATA[Category 1]]></name>
<description><![CDATA[]]></description>
<meta_description><![CDATA[]]></meta_description>
<meta_keywords><![CDATA[]]></meta_keywords>
<title_htmltag><![CDATA[]]></title_htmltag>
</categorie>
</document>
EOF
chown www-data:root /var/lib/pluxml/data/configuration/categories.xml
fi
if [ ! -e /var/lib/pluxml/data/statiques/001.static-1.php ]
then
cat >> /var/lib/pluxml/data/statiques/001.static-1.php <<- EOF
<p>My first static page!</p>
EOF
chown www-data:root /var/lib/pluxml/data/statiques/001.static-1.php
fi
if [ ! -e /var/lib/pluxml/data/configuration/statiques.xml ]
then
cat >> /var/lib/pluxml/data/configuration/statiques.xml <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<document>
<statique number="001" active="1" menu="oui" url="static-1" template="static.php">
<group><![CDATA[]]></group>
<name><![CDATA[Static 1]]></name>
<meta_description><![CDATA[]]></meta_description>
<meta_keywords><![CDATA[]]></meta_keywords>
<title_htmltag><![CDATA[]]></title_htmltag>
</statique>
</document>
EOF
chown www-data:root /var/lib/pluxml/data/configuration/statiques.xml
fi
date="$(date '+%Y%m%d%H%M')"
if [ -z "$(find /var/lib/pluxml/data/articles -maxdepth 1 -name '0001.001.001.*.first-article.xml' -print -quit)" ]
then
cat >> /var/lib/pluxml/data/articles/"0001.001.001.$date.first-article.xml" <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<document>
<title><![CDATA[First article]]></title>
<allow_com>1</allow_com>
<template><![CDATA[article.php]]></template>
<chapo>
<![CDATA[]]>
</chapo>
<content>
<![CDATA[<p>This article was created during PluXml installation. Edit it from the administration.</p>]]>
</content>
<tags>
<![CDATA[PluXml]]>
</tags>
<meta_description>
<![CDATA[]]>
</meta_description>
<meta_keywords>
<![CDATA[]]>
</meta_keywords>
<title_htmltag>
<![CDATA[]]>
</title_htmltag>
</document>
EOF
chown www-data:root /var/lib/pluxml/data/articles/"0001.001.001.$date.first-article.xml"
fi
if [ ! -e /var/lib/pluxml/data/configuration/tags.xml ]
then
cat >> /var/lib/pluxml/data/configuration/tags.xml <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<document>
<article number="0001" date="$date" active="1"><![CDATA[PluXml]]></article>
</document>
EOF
chown www-data:root /var/lib/pluxml/data/configuration/tags.xml
fi
timestamp="$(date '+%s')"
if [ -z "$(find /var/lib/pluxml/data/commentaires -maxdepth 1 -name '0001.*-1.xml' -print -quit)" ]
then
cat >> /var/lib/pluxml/data/commentaires/"0001.$timestamp-1.xml" <<- EOF
<?xml version="1.0" encoding="UTF-8"?>
<comment>
<author><![CDATA[pluxml]]></author>
<type>normal</type>
<ip>127.0.0.1</ip>
<mail><![CDATA[contact@pluxml.org]]></mail>
<site><![CDATA[http://www.pluxml.org]]></site>
<content><![CDATA[This is a first comment !]]></content>
</comment>
EOF
chown www-data:root /var/lib/pluxml/data/commentaires/"0001.$timestamp-1.xml"
fi
}
upgrade_5_4()
{
# The images directory has been replaced by a medias directory
if [ -d /var/lib/pluxml/data/images ] && \
[ ! -h /var/lib/pluxml/data/images ]
then
# Move images to the new directory
find /var/lib/pluxml/data/images \
-mindepth 1 -maxdepth 1 \
-execdir mv '{}' /var/lib/pluxml/data/medias ';'
rmdir /var/lib/pluxml/data/images
# Change references to these files in articles and static pages
find /var/lib/pluxml/data/articles /var/lib/pluxml/data/statiques \
-type f -a '(' -name '*.xml' -o -name '*.php' ')' \
-execdir sed -i -e 's_src="data/images/_src="data/medias/_g' \
'{}' +
fi
# Update version number in configuration file
sed -ri '/<parametre name="version">/s/5\.[[:digit:]\.]*/5.4/' \
/etc/pluxml/parametres.xml
}
upgrade_5_5()
{
# The comments naming has changed, from:
# ${artid}.${timestamp}-${index}.xml (published comments)
# _${artid}.${timestamp}-${index}.xml (offline comments)
# where ${index} was only increased for possible collisions, to:
# ${artid}.${timestamp}-${index}.xml (published comments)
# _${artid}.${timestamp}-${index}.xml (offline comments)
# where ${index} is now increased for each comment in the same article.
printf > /dev/stderr 'Reindexing comments on /var/lib/pluxml/data/commentaires... '
# Temporary directory to store reindexed comments without colliding to
# non-reindexed ones.
mkdir /var/lib/pluxml/data/commentaires.new
find /var/lib/pluxml/data/commentaires \
-mindepth 1 -maxdepth 1 -regextype posix-extended \
-regex '.*/[[:punct:]]?[[:digit:]]{4}\.[[:digit:]]{10}-[[:digit:]]+\.xml' \
| sort \
| (
current_article='0000'
current_index=0
while read comment
do
comment_info="$(
printf '%s\n' "$comment" \
| sed -r 's/^.*\/([[:punct:]]?)([[:digit:]]{4})\.([[:digit:]]{10})-([[:digit:]])+\.xml$/\1:\2:\3:\4/')"
comment_status="${comment_info%%:*}"
comment_article="${comment_info#$comment_status:}"
comment_article="${comment_article%%:*}"
comment_timestamp="${comment_info#$comment_status:$comment_article:}"
comment_timestamp="${comment_timestamp%%:*}"
comment_index="${comment_info#$comment_status:$comment_article:$comment_timestamp}"
comment_index="${comment_index%.xml}"
if [ "$comment_article" = "$current_article" ]
then
comment_newindex=$(($current_index + 1))
else
current_article="$comment_article"
comment_newindex=1
fi
current_index=$comment_newindex
# Move the comment to the temporary directory with its new reindexed name
comment_new="$(printf '%s/%s%s.%s-%s.xml' \
'/var/lib/pluxml/data/commentaires.new' \
"$comment_status" "$comment_article" \
"$comment_timestamp" "$comment_newindex")"
mv -- "$comment" "$comment_new"
done
)
# Move all reindexed comments back to the comments directory
find /var/lib/pluxml/data/commentaires.new \
-mindepth 1 -maxdepth 1 \
-execdir mv -- '{}' /var/lib/pluxml/data/commentaires ';'
# And remove the now empty temporary reindexed comments directory
rmdir /var/lib/pluxml/data/commentaires.new
printf > /dev/stderr '[done]\n'
# Update version number in configuration file
sed -ri '/<parametre name="version">/s/5\.[[:digit:]\.]*/5.5/' \
/etc/pluxml/parametres.xml
}
# Main script
case "$1" in
configure)
. /usr/share/debconf/confmodule
write_pluxml_conf
write_pluxml_content
case "$2"
in
5.2*|5.3*)
upgrade_5_4
upgrade_5_5
;;
5.4*)
upgrade_5_5
;;
esac
# Write a configuration file for all the supported webservers
write_apache2_conf
write_lighttpd_conf
# Only apply the configuration to the chosen webservers
db_get pluxml/system/webservers
webservers="$RET"
db_get pluxml/system/reload-webserver
reload_webserver="$RET"
for webserver in $webservers
do
webserver=${webserver%,}
enable_${webserver}_conf "$@"
if [ "$reload_webserver" = "true" ]
then
reload_$webserver "$@"
fi
done
db_stop
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
exit 0
|