From be980b17dd8c6a706536ac97788ba6d9177ed6a1 Mon Sep 17 00:00:00 2001 From: lars Date: Thu, 9 Nov 2006 17:43:40 +0000 Subject: [PATCH] added apache2_dav hook script --- hook-scripts/apache2_dav | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 hook-scripts/apache2_dav diff --git a/hook-scripts/apache2_dav b/hook-scripts/apache2_dav new file mode 100755 index 0000000..7f51835 --- /dev/null +++ b/hook-scripts/apache2_dav @@ -0,0 +1,85 @@ +#!/bin/sh +# +# Manage apache webdav +# - after mounting: add the new webdav share +# - before umounting: disable and remove the webdav share +# +# This script assumes, that you added the apache2_dav.conf file +# (/usr/share/doc/cryptobox/conf-examples/) to your apache configuration directory +# (e.g. /etc/apache2/conf.d) +# +# +# Params: $event $volume_name $volume_type $mount_dir +# +# event: premount | postmount | preumount | postumount +# device: name of the device +# volume_name: name of the volume +# volume_type: plain | luks +# mount_dir: mount directory +# + +set -eu + +APACHE_SCRIPT=/etc/init.d/apache2 +APACHE_CONF_DIR=/var/cache/cryptobox/apache2_dav.conf.d +TEMPLATE_CONF_FILE=/etc/cryptobox/apache2_dav-share.conf-template +MAIN_APACHE_CONF_FILE=/etc/cryptobox/apache-include.conf + +# exit if apache2 is not installed +test -e "$APACHE_SCRIPT" || exit 0 + +# create include-file directory +mkdir -p "$APACHE_CONF_DIR" + +# check event argument +if test "$#" -eq 0 + then echo "Syntax: $(basename $0) EVENT [EVENT_INFORMATION]" >&2 + exit 1 + fi + +event=$1 + + +# ------------=-=-=- some functions -=-=-=----------------- + +update_include_conf_file() +{ + ( echo "# this file was automatically generated by the CryptoBox" + echo "# DO NOT EDIT - all changes will get lost!" + find "$APACHE_CONF_DIR" -type f -name "*.conf" | while read fname + do echo "include = $fname" + done ) >"$MAIN_APACHE_CONF_FILE" +} + +send_reload_command() +{ + # reload config files + "$APACHE_SCRIPT" graceful +} + +# -----------------=-=-=- main -=-=-=---------------------- + +case "$event" in + premount|postumount ) + ;; + postmount ) + vol_name=$3 + mount_dir=$5 + sed "s#_SHARE_DIR_#$mount_dir#g; s#_VOLUME_NAME_#$vol_name#g" "$TEMPLATE_CONF_FILE" >"$APACHE_CONF_DIR/${vol_name}.conf" + update_include_conf_file + send_reload_command + ;; + preumount ) + vol_name=$3 + rm "$APACHE_CONF_DIR/${vol_name}.conf" || true + update_include_conf_file + send_reload_command + ;; + * ) + # ignore all events that we do not support + exit 0 + ;; + esac + +exit 0 +