lars
112979b3af
moved python modules to separate packages below src/ renamed "hook" to "event" to avoid confusion
85 lines
2 KiB
Bash
Executable file
85 lines
2 KiB
Bash
Executable file
#!/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/apache2-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" reload
|
|
}
|
|
|
|
# -----------------=-=-=- 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
|
|
|