[Webapps-common-discuss] webapps-common/dpkg common, 1.3, 1.4 config, 1.1, 1.2 postinst, 1.2, 1.3 postrm, 1.2, 1.3 preinst, NONE, 1.1 prerm, NONE, 1.1

seanius at haydn.debian.org seanius at haydn.debian.org
Wed Aug 17 16:40:44 UTC 2005


Update of /cvsroot/webapps-common/webapps-common/dpkg
In directory haydn:/org/alioth.debian.org/chroot/home/users/seanius/tmp/cvs-serv7055/dpkg

Modified Files:
	common config postinst postrm 
Added Files:
	preinst prerm 
Log Message:
this is a huge chunk of work i did in the past week's offline travelling.
the UI/debconf stuff is mostly sorted out at this point, and now we need
to work out the 'do stuff' side of things, which should be fairly easy since
most of the code is still there.



Index: common
===================================================================
RCS file: /cvsroot/webapps-common/webapps-common/dpkg/common,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- common	3 Aug 2005 04:48:39 -0000	1.3
+++ common	17 Aug 2005 16:40:41 -0000	1.4
@@ -35,7 +35,7 @@
 
 	# standard templates provided by webapps-common, which will have copies
 	# registered with the package in question.
-	wc_standard_templates="webapps_install httpd/website_subdirectory httpd/select_httpd install_error"
+	wc_standard_templates="webapps_install httpd/website_subdirectory httpd/select_httpd install_error httpd/virtualhost httpd/virtualhost_new"
 	wc_register_templates=$wc_standard_templates
 
 	###
@@ -53,7 +53,26 @@
 ### dump global configuration to a config file
 ###
 wc_write_global_config(){
-	true	
+	true
+}
+
+###
+### update the webapps-common apache siteconf file
+###
+wc_update_apache_siteconf(){
+	local tmpconf siteid_dir siteconf
+	tmpconf=`_wc_mktmp`
+
+	siteconf="$wc_confdir/siteids.conf"
+	siteid_dir="$wc_confdir/siteids.d"
+
+	for p in `ls $siteid_dir/*.conf 2>/dev/null`; do
+		grep -vE '[[:space:]]*#' $p |\
+			while read site loc; do
+				echo "SetEnvIf REQUEST_URI '^http://$site/$loc' X_DEBIAN_SITEID=$site/$loc" >> "$tmpconf"
+			done
+	done
+	ucf "$tmpconf" $siteconf
 }
 
 ###
@@ -61,11 +80,8 @@
 ###
 wc_write_package_config(){
 	local tmpconf
-	tmpconf=`mktemp -t`
-	if [ ! -f "$tmpconf" ]; then
-		echo "can't create temp file, error $?" >&2
-		return 1
-	fi
+
+	tmpconf=`_wc_mktmp`
 	chmod 644 "$tmpconf"
 
 	# detect what kind of install this is and copy/merge the correct file
@@ -88,6 +104,7 @@
 	# now perform some substitutions on the file
 	sed -i -e "s,_WC_WEBSITE_SUBDIRECTORY_,$wc_website_subdirectory,g" "$tmpconf"
 	sed -i -e "s,_WC_WEBSITE_DOCUMENTROOT_,$wc_website_documentroot,g" "$tmpconf"
+	sed -i -e "s,_WC_WEBSITE_HOSTNAME_,$wc_website_hostname,g" "$tmpconf"
 
 	# and register it via ucf
 	ucf $tmpconf $wc_package_confdir/apache.conf
@@ -98,17 +115,27 @@
 ### wc_configure_httpds:
 ###	choose the servers for the app
 wc_configure_httpds(){
-	local h httpds chosen_httpds oldchoices
-	httpds=`wc_httpd_installed | paste -s | sed -e 's/\t/, /g'`
+	local h instd_httpds chosen_httpds oldchoices debconf_dest
 
-	db_subst $wc_package/httpd/select_httpd httpds $httpds
-	db_input medium  $wc_package/httpd/select_httpd || true
-	db_go || true
-	db_get $wc_package/httpd/select_httpd
-	chosen_httpds=`echo $RET | sed -e 's/,//g'`
+	if [ "$1" ]; then
+		debconf_dest="$wc_package/vhosts/$1"
+	else
+		debconf_dest="$wc_package"
+	fi
 
-	wc_httpd_apache_include "$wc_package_confdir/apache.conf" "$wc_package" $chosen_httpds
-	wc_httpd_invoke reload $chosen_httpds
+	# create a list of installed httpds
+	instd_httpds=`_wc_list_create \`wc_httpd_installed\``
+	# get a list of previously offered choices of installed httpds
+	db_metaget $debconf_dest/httpd/select_httpd choices && oldchoices="$RET"
+
+	# if the old list was empty or does not match the current list, we need
+	# to ask for the new selection.
+	if [ ! "$oldchoices" -o "$instd_httpds" != "$oldchoices" ]; then
+		db_subst $debconf_dest/httpd/select_httpd httpds $instd_httpds
+		db_input medium  $debconf_dest/httpd/select_httpd || true
+
+		#wc_httpd_apache_include "$wc_package_confdir/apache.conf" "$wc_package" $chosen_httpds
+	fi
 }
 
 ###
@@ -118,6 +145,7 @@
 wc_read_package_debconf(){
 	_wc_sanity_check package || wc_install_error
 	db_get $wc_package/httpd/website_subdirectory && wc_website_subdirectory="$RET"
+	db_get $wc_package/httpd/virtualhost && wc_website_virtualhost="$RET"
 }
 
 ##
@@ -205,12 +233,100 @@
 
 ###
 ### register all the necessary debconf templates
+###	passing an argument to this function registers another copy
+###	of the templates for a vhost identified with said argument
 ###
 wc_register_debconf(){
-	local f
+	local f vhost_id debconf_dest
+	vhost_id="$1"
+
+	if [ ! "$vhost_id" ]; then
+		debconf_dest="$wc_package"	
+	else
+		debconf_dest="$wc_package/vhosts/$vhost_id"
+	fi
+
 	for f in $wc_register_templates; do
 		# perform some basic customizing substitutions
-		db_register webapps-common/$f $wc_package/$f
-		db_subst $wc_package/$f pkg $wc_package
+		if ! db_get "$debconf_dest/$f/httpd/website_subdirectory"; then
+			db_register "webapps-common/$f" "$debconf_dest/$f"
+		fi
+		db_subst "$debconf_dest/$f" pkg "$wc_package"
+		if [ "$vhost_id" ]; then
+			db_subst "$debconf_dest/$f" vhost "$vhost_id"
+		fi
+	done
+	# set some default values
+	db_set "$debconf_dest/httpd/website_subdirectory" "$wc_package"
+}
+
+###
+### unregister all the registered debconf templates
+###
+wc_unregister_debconf(){
+	local f
+	for f in $wc_register_templates; do
+		db_unregister $wc_package/$f
 	done
 }
+
+###
+### dump the vhost/dir combinations for a package to the config file
+###	this should only be called in the preinst i guess
+###
+wc_dump_debconf_siteids(){
+	local tmpconf siteconf vhosts v d httpds debconf_src
+	tmpconf=`_wc_mktmp`
+	siteconf="$wc_confdir/siteids.d/$wc_package.conf"
+	# get the list of selected virtualhosts
+	db_get $wc_package/httpd/virtualhost && vhosts="$RET"
+	for v in `_wc_list_explode "$vhosts"`; do
+		debconf_src="$wc_package/vhosts/$v"
+		db_get $debconf_src/httpd/website_subdirectory && d="$RET"
+		db_get $debconf_src/httpd/select_httpd && httpds="$RET"
+		echo "$v	$d $httpds" >> "$tmpconf"
+	done
+	ucf "$tmpconf" "$siteconf"
+}
+
+###
+### preseed debconf values from the config files on disk
+###	this should only be called in the config script, i guess
+###
+wc_preseed_debconf_siteids(){
+	local siteconf vhost dir httpds debconf_dest choices vhost_list
+	siteconf="/etc/webapps-common/siteids.d/$wc_package.conf"
+	if [ ! -f "$siteconf" ]; then return 0; fi
+
+	# XXX
+	# this is a gross hack.  apparently you can't redirect stdin
+	# when calling debconf get/set/register commands???
+	# we should at least not have to arbitrarily pick an fd
+	(
+	exec 7<$siteconf
+	while read -u7 vhost dir httpds; do
+		debconf_dest="$wc_package/vhosts/$vhost"
+		wc_register_debconf "$vhost"
+		db_set $debconf_dest/httpd/website_subdirectory "$dir"
+		db_set $debconf_dest/httpd/select_httpd "$httpds"
+		db_metaget $wc_package/httpd/virtualhost choices && choices="$RET"
+		db_subst $wc_package/httpd/virtualhost vhosts `_wc_list_add "$choices" "$vhost"`
+		db_get $wc_package/httpd/virtualhost && vhost_list="$RET"
+		db_set $wc_package/httpd/virtualhost `_wc_list_add "$vhost_list" "$vhost"`
+	done 
+	) 
+}
+
+###
+### make a temporary file
+###
+_wc_mktmp(){
+	local tmpconf
+	tmpconf=`mktemp -t`
+	if [ ! -f "$tmpconf" ]; then
+		echo "can't create temp file, error $?" >&2
+		return 1
+	else
+		echo "$tmpconf"
+	fi
+}

Index: config
===================================================================
RCS file: /cvsroot/webapps-common/webapps-common/dpkg/config,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- config	30 Jul 2005 09:37:06 -0000	1.1
+++ config	17 Aug 2005 16:40:41 -0000	1.2
@@ -2,6 +2,7 @@
 # sean finney <seanius at debian.org>
 
 wc_go(){
+	local donewithvhosts vhost_name vhost_new vhost_list v
 	. /usr/share/webapps-common/dpkg/common
 	wc_config $@
 
@@ -14,11 +15,15 @@
 	# register all the debconf templates
 	wc_register_debconf
 
+	# preseed debconf values
+	wc_preseed_debconf_siteids
+
 	# state 1 - ask if they want our help at all
 	if [ "$wc_install" ]; then
 		db_set $wc_package/webapps_install "$wc_install"
 	fi
-	db_input medium $wc_package/webapps_install "$wc_install" || true
+	db_input medium $wc_package/webapps_install || true
+
 
 	# state 2 - check to see if they do
 	db_go || true
@@ -27,11 +32,47 @@
 		return 0;
 	fi
 
-	# state 3 - ask for the site directory
-	if [ "$wc_website_subdirectory" ]; then
-		db_set $wc_package/httpd/website_subdirectory "$wc_website_subdirectory"
-	fi
-	db_input medium $wc_package/httpd/website_subdirectory "$wc_website_subdirectory" || true
+	# state 3 - choose vhosts
+	while [ ! "$donewithvhosts" ]; do
+
+		# state 3.1, fetch the choices, and set the default list if empty
+		db_metaget $wc_package/httpd/virtualhost choices && vhost_list=$RET
+		if [ ! "$vhost_list" ]; then
+			vhost_list="[new vhost]"
+			db_subst $wc_package/httpd/virtualhost vhosts "$vhost_list"
+		fi
+
+		# state 3.2 - ask.
+		db_input high $wc_package/httpd/virtualhost || true
+		db_go || true
+
+		# state 3.3 - if new host, ask for the hostname
+		db_get $wc_package/httpd/virtualhost && vhosts_selected=$RET
+		if _wc_list_is_member "$vhosts_selected" '\[new vhost\]'; then
+			db_input medium $wc_package/httpd/virtualhost_new || true
+			db_go || true
+
+			db_get $wc_package/httpd/virtualhost_new && vhost_new=$RET
+			if [ "$vhost_new" ]; then
+				vhost_list=`_wc_list_add "$vhost_list" "$vhost_new"`
+				vhosts_selected=`_wc_list_add "$vhosts_selected" "$vhost_new"`
+				vhosts_selected=`_wc_list_remove "$vhosts_selected" "\[new vhost\]"`
+				db_subst $wc_package/httpd/virtualhost vhosts "$vhost_list"
+				db_set $wc_package/httpd/virtualhost $vhosts_selected
+				db_set $wc_package/httpd/virtualhost_new ""
+				wc_register_debconf "$vhost_new"
+			fi
+		else
+			donewithvhosts="true"
+		fi
+	done
+
+	# state 4 - ask for the httpds/site directory for each virtualhost
+	for v in `_wc_list_explode "$vhosts_selected"`; do
+		db_input medium $wc_package/vhosts/$v/httpd/website_subdirectory || true
+		wc_configure_httpds "$v"
+		db_input medium $wc_package/vhosts/$v/httpd/select_httpd || true
+	done
 
 	# let's stop here for now.
 	db_go || true

Index: postinst
===================================================================
RCS file: /cvsroot/webapps-common/webapps-common/dpkg/postinst,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- postinst	3 Aug 2005 04:48:39 -0000	1.2
+++ postinst	17 Aug 2005 16:40:41 -0000	1.3
@@ -13,14 +13,11 @@
 		### get all the debconf settings we need
 		###
 
-		wc_write_package_config
-
-		# do they want our help at all?  if so we'll quit after writing the cfg
+		# do they want our help at all?  if so we'll quit
 		db_get $wc_package/webapps_install && wc_install="$RET"
-
-		###
-		### if they don't want our help, quit
-		###
 		if [ "$wc_install" != "true" ]; then return 0; fi
+
+		wc_write_package_config
 	fi
+	#wc_update_apache_siteconf
 }

Index: postrm
===================================================================
RCS file: /cvsroot/webapps-common/webapps-common/dpkg/postrm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- postrm	3 Aug 2005 04:48:39 -0000	1.2
+++ postrm	17 Aug 2005 16:40:41 -0000	1.3
@@ -17,7 +17,7 @@
 		if [ "$deconfigured_httpds" ]; then
 			wc_httpd_apache_uninclude "$wc_package_confdir/apache.conf" "$wc_package"
 			# reload the running web servers
-			wc_httpd_invoke reload `wc_httpd_running $deconfigured_httpds`
+			wc_httpd_invoke reload `wc_httpd_running $deconfigured_httpds` || true
 		fi
 	fi
 
@@ -25,5 +25,7 @@
 	if [ "$wc_command" = "purge" ]; then
 		rm -f $wc_package_confdir/apache.conf || true	
 		ucf -p $wc_package_confdir/apache.conf || true	
+		rm -f $wc_confdir/siteids.d/${wc_package}.conf || true	
+		ucf -p $wc_confdir/siteids.d/${wc_package}.conf || true	
 	fi
 }

--- NEW FILE: preinst ---
# preinst hooks for webapps-common

wc_go(){
	. /usr/share/webapps-common/dpkg/common
	wc_config $@
			  
	wc_dump_debconf_siteids
}

--- NEW FILE: prerm ---
# prerm hook for webapps-common

wc_go(){
	. /usr/share/webapps-common/dpkg/common
	wc_config $@

	if [ "$wc_command" = "purge" ]; then
		wc_unregister_templates
	fi
}




More information about the Webapps-common-discuss mailing list