[tilelite] 01/01: Use debconf for configuration management (not finished)

Christopher Baines cbaines-guest at moszumanska.debian.org
Sun Jun 14 17:04:57 UTC 2015


This is an automated email from the git hooks/post-receive script.

cbaines-guest pushed a commit to branch debconf
in repository tilelite.

commit 8fb5c22ec4551dd8d42a307a2905ff72b2905925
Author: Christopher Baines <mail at cbaines.net>
Date:   Sun Apr 26 11:09:30 2015 +0100

    Use debconf for configuration management (not finished)
    
    The aim of this is to give the user the option of having tilelite working once
    the installation is finished.
    
    Currently the menu system is implemented, but the questions asked might not be
    quite right, and the required configuration/user(s) are not created.
    
    When tilelite runs mapnik, it may need to connect to a database (probably
    postgres). This may require running it as a specific user, or a user with
    specific permissions. It may also write out cached files, that should go to the
    appropriate Debian place.
    
    Supporting every possible configuration option is not sensible, however, I
    believe it would be good for a user to be able to simply set up a tileserver
    using tilelite, osm2pgsql and openstreetmap-carto. It might also be good to
    have some other packages, perhaps openstreetmap-database that could help with
    setting up a database with osm2pgsql and openstreetmap-carto, for use with
    tilelite?
---
 debian/config    | 315 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 debian/postinst  | 120 +++++++++++++++++++++
 debian/postrm    |  40 +++++++
 debian/rules     |   1 +
 debian/templates |  85 +++++++++++++++
 5 files changed, 561 insertions(+)

diff --git a/debian/config b/debian/config
new file mode 100755
index 0000000..d38f9b6
--- /dev/null
+++ b/debian/config
@@ -0,0 +1,315 @@
+#!/bin/bash
+set -e
+
+log() {
+	if [ "$DEBCONF_DEBUG" == "developer" ]; then
+		echo "tilelite: $*" 1>&2;
+	fi
+}
+
+log "config \"$*\""
+
+# source debconf
+. /usr/share/debconf/confmodule
+
+db_capb backup
+
+TILESET_QUESTIONS=(processname mapfile url user group)
+
+TILESET_QUESTIONS_WITHOUT_PROCESSNAME=(mapfile url user group)
+
+containsElement() {
+	# https://stackoverflow.com/a/8574392
+	local e
+	for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
+	return 1
+}
+
+add_tileset(){
+	while true; do
+
+		for question in ${TILESET_QUESTIONS[@]}; do
+			db_fset tilelite/${question} seen false
+			db_set tilelite/${question} ""
+			db_input high tilelite/${question} || true
+		done
+
+		if db_go; then
+
+			declare -A answers
+			for question in ${TILESET_QUESTIONS[@]}; do
+				db_get tilelite/${question} && answer="$RET"
+				answers[$question]=$answer
+			done
+
+			for question in ${TILESET_QUESTIONS[@]}; do
+				# if the string is empty
+				if [ ${#answer} -eq 0 ]; then
+					db_input high tilelite/empty_$question || true
+
+					if db_go; then
+						continue
+					else
+						return 0
+					fi
+				fi
+			done
+
+			if containsElement "${answers[processname]}" "${TILESETS[@]}"; then
+				db_subst tilelite/duplicate_processname duplicate_name ${answers[processname]}
+				db_input high tilelite/duplicate_processname
+
+				if db_go; then
+					continue
+				else
+					return 1
+				fi
+			fi
+
+			log "saving tileset details"
+
+			prefix="tilelite/tileset/${answers[processname]}/"
+
+			log "prefix is $prefix"
+
+			for question in ${TILESET_QUESTIONS[@]}; do
+				db_register tilelite/$question "$prefix$question"
+
+				db_set "$prefix$question" "${answers[$question]}"
+			done
+
+			TILESETS+=("${answers[processname]}")
+
+			log "TILESETS ${TILESETS[*]}"
+
+			set_tilesets
+
+			log "tileset details saved"
+
+			return 0
+		else
+			return 1
+		fi
+	done
+}
+
+set_tilesets() {
+	log "setting tilesets to ${TILESETS[*]}"
+
+	joined_tilesets=$(printf " %s" "${TILESETS[@]}")
+	joined_tilesets=${joined_tilesets:1}
+	# https://stackoverflow.com/a/2317171
+
+	log "joined tilesets $joined_tilesets"
+
+	db_set tilelite/tilesets $joined_tilesets
+}
+
+change_tileset() {
+	log "change tileset"
+
+	log "tilesets \"${TILESETS[*]}\""
+
+	if [ "${#TILESETS[@]}" -gt "1" ]; then
+
+		joined_tilesets=$(printf ", %s" "${TILESETS[@]}")
+		joined_tilesets=${joined_tilesets:1}
+
+		db_subst tilelite/change-tileset tilesets $joined_tilesets
+
+		db_fset tilelite/change-tileset seen false
+
+		db_input high tilelite/change-tileset || return 1
+
+		db_go || return 0 # user has canceled
+
+		db_get tilelite/change-tileset && processname="$RET"
+	else
+		processname=${TILESETS[0]}
+
+	fi
+
+	log "changing $processname"
+
+	prefix=tilelite/tileset/$processname/
+
+	db_set tilelite/processname $processname
+
+	db_fset tilelite/processname seen false
+	db_input high tilelite/processname
+
+	for question in ${TILESET_QUESTIONS_WITHOUT_PROCESSNAME[@]}; do
+		db_fset $prefix$question seen false
+		db_input high $prefix${question} || true
+
+	done
+
+	db_go
+
+	db_get tilelite/processname && new_processname="$RET"
+
+	if [ "$new_processname" != "$processname" ]; then
+		# change the name of the tileset
+
+		log "changing processname from \"$processname\" to \"$new_processname\""
+
+		old_prefix=$prefix
+		new_prefix=tilelite/tileset/$new_processname/
+
+		for question in ${TILESET_QUESTIONS_WITHOUT_PROCESSNAME[@]}; do
+			db_register tilelite/$question "$new_prefix$question" || return 1
+
+			db_get "$old_prefix$question" && answer="$RET"
+
+			db_set "$new_prefix$question" "$answer"  || return 1
+
+			db_unregister "$old_prefix$question" || return 1
+		done
+
+		delete=($processname)
+		TILESETS=( "${TILESETS[@]/$delete}" )
+
+		TILESETS+=( $new_processname )
+
+		set_tilesets
+	fi
+}
+
+remove_tileset() {
+	log "removing tileset"
+
+	log "current tilesets \"${TILESETS[*]}\""
+
+	if [ "${#TILESETS[@]}" -gt 1 ]; then
+		log "more than one tileset, so asking which one"
+
+		joined_tilesets=$(printf ", %s" "${TILESETS[@]}")
+		joined_tilesets=${joined_tilesets:1}
+
+		db_subst tilelite/remove-tileset tilesets $joined_tilesets
+
+		db_fset tilelite/remove-tileset seen false
+		db_input high tilelite/remove-tileset || return 1
+
+		db_go || return 0
+
+		db_get tilelite/remove-tileset && processname="$RET"
+	else
+		processname=${TILESETS[0]}
+
+		log "just one tileset, so removing \"$processname\""
+	fi
+
+	db_fset tilelite/confirm-tileset-removal seen false
+
+	db_input high tilelite/confirm-tileset-removal || return 1
+
+	db_go || return 0 # user has canceled
+
+	db_get tilelite/confirm-tileset-removal && confirm_removal="$RET"
+
+	if ! $confirm_removal; then
+		log "user has not confirmed removal, going back"
+		return 0
+	fi
+
+	log "user has confirmed removal"
+
+    prefix=tilelite/tileset/${processname}/
+
+	for question in ${TILESET_QUESTIONS_WITHOUT_PROCESSNAME[@]}; do
+		db_unregister "$prefix$question" || true
+	done
+
+	delete=($processname)
+	TILESETS=( "${TILESETS[@]/$delete}" )
+
+	log "setting tilesets to \"${TILESETS[*]}\""
+	set_tilesets
+
+	# TOOD: Should add to this list
+	db_set tilelite/tilesets-to-remove $processname
+
+	log "finished removing tileset"
+}
+
+select_action() {
+	db_fset tilelite/select-action seen false
+	db_input high tilelite/select-action
+
+	if ! db_go; then
+		return 0 # user has canceled
+	fi
+
+	db_get tilelite/select-action && action="$RET"
+
+	case "$action" in
+		Add) add_tileset || return 1
+		;;
+		Change) change_tileset || return 1
+		;;
+		Remove) remove_tileset || return 1
+		;;
+	esac
+}
+
+configure() {
+	while true; do
+		db_get tilelite/tilesets
+
+		local joined_tilesets="$RET"
+
+		log "joined_tilesets \"$joined_tilesets\""
+
+		declare -a TILESETS='()'
+		IFS=' ' read -a TILESETS <<< "$joined_tilesets"
+
+		log "configure tilesets \"${TILESETS[*]}\" (length ${#TILESETS[@]})"
+
+		if [ "${#TILESETS[@]}" -eq "0" ]; then
+			log "currently 0 tilesets, so skipping the select action"
+
+			db_fset tilelite/add-tileset seen false
+			db_input high tilelite/add-tileset
+
+			db_go
+
+			db_get tilelite/add-tileset && add="$RET"
+			if $add; then
+				add_tileset
+			else
+				break
+			fi
+		else
+			log "1 or more tileset, asking select_action"
+			if ! select_action; then
+				return 1
+			fi
+		fi
+
+		db_fset tilelite/finished seen false
+		db_input high tilelite/finished
+
+		if ! db_go; then
+			return 1
+		fi
+
+		db_get tilelite/finished && finished="$RET"
+
+		if $finished; then
+			break
+		fi
+	done
+}
+
+db_purge || true
+
+if ! configure; then
+	log "an error has occured"
+
+	exit 1
+fi
+
+log "end of config script"
+
+exit 0
diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 0000000..20317c5
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,120 @@
+#!/bin/bash
+set -e
+
+log() {
+	if [ "$DEBCONF_DEBUG" == "developer" ]; then
+		echo "tilelite: $*" 1>&2;
+	fi
+}
+
+log "postinst \"$*\""
+
+# source debconf stuff
+if [ -f /usr/share/debconf/confmodule ]; then
+	. /usr/share/debconf/confmodule
+fi
+
+db_capb backup
+
+create_tileset() {
+	processname=$1
+
+	log "creating \"$processname\""
+
+	db_get tilelite/tileset/$processname/mapfile || return 1
+	mapfile="$RET"
+
+	db_get tilelite/tileset/$processname/url || return 1
+	url="$RET"
+
+	db_get tilelite/tileset/$processname/user || return 1
+	user="$RET"
+
+	db_get tilelite/tileset/$processname/group || return 1
+	group="$RET"
+
+	prefix="tilelite/tileset/$processname"
+
+	# WSGIScriptAlias /tiles /home/mapnik/projects/tilelite/tilelite.wsgi
+	# WSGIDaemonProcess tileliteserver user=www-data group=www-data processes=10 threads=1
+	# WSGIProcessGroup tileliteserver
+
+	wsgi_path_prefix="/etc/tilelite/wsgi/"
+	wsgi_path="$wsgi_path_prefix${processname}.wsgi"
+
+	mkdir -p $wsgi_path_prefix
+
+	cat << EOF > $wsgi_path
+from tilelite import Server
+
+application = Server('$mapfile')
+EOF
+
+	apache_path_prefix="/etc/apache2/conf-available/"
+	apache_path="${apache_path_prefix}tilelite-${processname}.conf"
+
+	mkdir -p $apache_path_prefix
+
+	cat << EOF > $apache_path
+WSGIScriptAlias $url $wsgi
+WSGIDaemonProcess $processname user=$user group=$group processes=10 threads=1
+WSGIProcessGroup $processname
+EOF
+
+	if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+		. /usr/share/apache2/apache2-maintscript-helper
+
+		apache2_invoke enconf "tilelite-${processname}.conf"
+	fi
+}
+
+remove_tileset() {
+	processname=$1
+
+	log "removing tileset \"$processname\""
+
+	# TODO
+}
+
+get_tilesets_to_remove() {
+	db_get tilelite/tilesets-to-remove && tilesets_to_remove="$RET"
+
+	IFS=' ' read -a tilesets_to_remove <<< "$tilesets_to_remove"
+}
+
+if [ "$1" = "configure" ]; then
+	#if ! getent passwd tilelite > /dev/null; then
+	#	adduser --quiet \
+	#	        --system \
+	#	        --group \
+	#	        --no-create-home \
+	#	        --disabled-password \
+	#	        --home /usr/share/tilelite \
+	#	        tilelite
+    #fi
+
+	db_get tilelite/tilesets && joined_tilesets="$RET"
+
+	declare -a tilesets
+	IFS=' ' read -a tilesets <<< "$joined_tilesets"
+
+	log "current tilesets \"${tilesets[*]}\""
+
+	for processname in ${tilesets[@]}; do
+		log "processname $processname"
+
+		create_tileset $processname
+	done
+
+	get_tilesets_to_remove
+
+	log "tilesets to remove \"$tilesets_to_remove\""
+
+	for processname in ${tilesets_to_remove[@]}; do
+		remove_tileset $processname
+	done
+fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/postrm b/debian/postrm
new file mode 100644
index 0000000..d09c501
--- /dev/null
+++ b/debian/postrm
@@ -0,0 +1,40 @@
+#!/bin/bash
+set -e
+
+log() {
+	if [ "$DEBCONF_DEBUG" == "developer" ]; then
+		echo "tilelite: $*" 1>&2;
+	fi
+}
+
+if [ -f /usr/share/debconf/confmodule ]; then
+	. /usr/share/debconf/confmodule
+fi
+
+#DEBHELPER#
+
+# Automatically added by dh_installdebconf
+if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
+	. /usr/share/debconf/confmodule
+
+	log "attempting to actually purge debconf"
+
+	#db_get tilelite/tilesets && tilesets="$RET"
+	#log "tilesets $tilesets"
+
+	db_set tilelite/tilesets "" || true
+	db_set tilelite/tilesets-to-remove "" || true
+
+	#db_get tilelite/tilesets && tilesets="$RET"
+	#log "tilesets $tilesets"
+
+	log "hopefully debconf is now purged"
+fi
+
+if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+	. /usr/share/apache2/apache2-maintscript-helper
+
+	apache2_invoke disconf "tilelite-${processname}.conf"
+fi
+
+exit 0
diff --git a/debian/rules b/debian/rules
index da765df..68495da 100755
--- a/debian/rules
+++ b/debian/rules
@@ -11,6 +11,7 @@ TLDIR=$(CURDIR)/debian/tilelite
 %:
 	dh $@ \
 		--with python2 \
+		--with=apache2 \
 		--buildsystem pybuild
 
 override_dh_auto_install:
diff --git a/debian/templates b/debian/templates
new file mode 100644
index 0000000..42e7489
--- /dev/null
+++ b/debian/templates
@@ -0,0 +1,85 @@
+
+Template: tilelite/tilesets
+Type: string
+Description: Comma seperated list of the process names of each tilesets
+
+Template: tilelite/select-action
+Type: select
+Choices: Add, Change, Remove
+Description: Would you like to change an existing tileset, or add a new one?
+
+Template: tilelite/change-tileset
+Type: select
+Choices: ${tilesets}
+Description: Select the tileset that you want to change.
+
+Template: tilelite/remove-tileset
+Type: select
+Choices: ${tilesets}
+Description: Select the tileset that you want to remove.
+
+Template: tilelite/confirm-tileset-removal
+Type: boolean
+Default: false
+Description: Are you sure you want to remove the tileset?
+
+Template: tilelite/finished
+Type: boolean
+Default: true
+Description: Have you finished configuring tilelite?
+ Note that you can configure the package after it is installed.
+
+Template: tilelite/add-tileset
+Type: boolean
+Description: Would you like to add a tileset?
+
+Template: tilelite/tilesets-to-remove
+Type: boolean
+Description: What tilesets would you like to remove?
+
+Template: tilelite/mapfile
+Type: string
+Description: Full path to the mapfile
+
+Template: tilelite/url
+Type: string
+Description:
+ The url can be either be '/' (to mount the script at http://example.com/) or
+ it can be a path such as '/tiles' to mount the server at
+ http://example.com/tiles
+
+Template: tilelite/processname
+Type: string
+Description: process name can be any unique name like 'tileliteserver':
+
+Template: tilelite/user
+Type: string
+Description: user that has permissions to the 'tilelite.wsgi':
+
+Template: tilelite/group
+Type: string
+Description: a group that has permissions to the 'tilelite.wsgi':
+
+Template: tilelite/empty_processname
+Type: error
+Description: You must enter a value for the process name
+
+Template: tilelite/empty_mapfile
+Type: error
+Description: You must enter a value for the map file
+
+Template: tilelite/empty_url
+Type: error
+Description: You must enter a value for the URL
+
+Template: tilelite/empty_user
+Type: error
+Description: You must enter a value for the user
+
+Template: tilelite/empty_group
+Type: error
+Description: You must enter a value for the group
+
+Template: tilelite/duplicate_processname
+Type: error
+Description: There already exists a tileset with the processname "$(duplicate_name)"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/tilelite.git



More information about the Pkg-grass-devel mailing list