* sed in the webdav event script now works
* share names must not have any whitespaces
This commit is contained in:
parent
2c77ef5ef5
commit
66cf3a013e
|
@ -1,12 +1,12 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# To make this event script work add the apache2_dav.conf file
|
||||||
|
# from /usr/share/doc/cryptobox/conf-examples/ to your apache
|
||||||
|
# configuration directory (e.g. /etc/apache2/conf.d)
|
||||||
#
|
#
|
||||||
# Manage apache webdav
|
# This event script manages apache webdav
|
||||||
# - after mounting: add the new webdav share
|
# - after mounting: add the new webdav share
|
||||||
# - before umounting: disable and remove the 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 $device $volume_name $volume_type $mount_dir
|
# Params: $event $device $volume_name $volume_type $mount_dir
|
||||||
|
@ -24,19 +24,21 @@ set -eu
|
||||||
# adapt this part of the file to your setup
|
# adapt this part of the file to your setup
|
||||||
|
|
||||||
APACHE_SCRIPT=/etc/init.d/apache2
|
APACHE_SCRIPT=/etc/init.d/apache2
|
||||||
APACHE_CONF_DIR=/var/cache/cryptobox/settings/misc/apache2_dav.conf.d
|
APACHE_CONF_DIR=/var/cache/cryptobox-server/settings/misc/apache2_dav.conf.d
|
||||||
|
|
||||||
# this apache config snippet is used for every published volume
|
# this apache config snippet is used for every published volume
|
||||||
# _VOLUME_NAME_ and _SHARE_DIR_ are replaced by their actual values
|
# _VOLUME_NAME_ and _SHARE_DIR_ are replaced by their actual values
|
||||||
APACHE_SHARE_TEMPLATE=$(cat - <<-"EOF"
|
APACHE_SHARE_TEMPLATE=$(cat - <<-"EOF"
|
||||||
# this file is part of the CryptoBox
|
Alias "/cryptonas/_VOLUME_NAME_" "_SHARE_DIR_"
|
||||||
Alias "/cryptobox/_VOLUME_NAME_" "_SHARE_DIR_"
|
# this is an automatically generarted file for the CryptoNAS
|
||||||
<Location "/cryptobox/_VOLUME_NAME_">
|
# please do not change
|
||||||
Dav filesystem
|
<Location "/cryptonas/_VOLUME_NAME_">
|
||||||
|
\tDav filesystem
|
||||||
</Location>
|
</Location>
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# no need for changes from here on..
|
||||||
# -----=-=-=- check arguments and the environment -=-=-=----
|
# -----=-=-=- check arguments and the environment -=-=-=----
|
||||||
|
|
||||||
# exit if apache2 is not installed
|
# exit if apache2 is not installed
|
||||||
|
@ -47,7 +49,11 @@ if test -x "$APACHE_SCRIPT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# create include-file directory
|
# create include-file directory
|
||||||
mkdir -p "$APACHE_CONF_DIR"
|
if test ! -d ${APACHE_CONF_DIR}
|
||||||
|
echo "apache2_dav include-file directory does not exist, creating it" >&2
|
||||||
|
then mkdir -p ${APACHE_CONF_DIR}
|
||||||
|
chmod 775 ${APACHE_CONF_DIR}
|
||||||
|
fi
|
||||||
|
|
||||||
# check event argument
|
# check event argument
|
||||||
if test "$#" -eq 0
|
if test "$#" -eq 0
|
||||||
|
@ -59,9 +65,11 @@ event=$1
|
||||||
|
|
||||||
# ------------=-=-=- some functions -=-=-=-----------------
|
# ------------=-=-=- some functions -=-=-=-----------------
|
||||||
|
|
||||||
# remove invalid config files
|
# keep the include file directory clean
|
||||||
update_include_conf_dir()
|
update_include_conf_dir()
|
||||||
{
|
{
|
||||||
|
# if a webdav alias is given but no corresponding mount dir exists
|
||||||
|
# then remove the includefile
|
||||||
find "$APACHE_CONF_DIR" -type f -name "*.conf" | while read fname
|
find "$APACHE_CONF_DIR" -type f -name "*.conf" | while read fname
|
||||||
do mdir=$(head -1 "$fname" | cut -f 4 -d '"')
|
do mdir=$(head -1 "$fname" | cut -f 4 -d '"')
|
||||||
test ! -d "$mdir" && rm "$fname"
|
test ! -d "$mdir" && rm "$fname"
|
||||||
|
@ -85,16 +93,16 @@ case "$event" in
|
||||||
premount|postumount )
|
premount|postumount )
|
||||||
;;
|
;;
|
||||||
postmount )
|
postmount )
|
||||||
vol_name=$3
|
vol_name="$3"
|
||||||
mount_dir=$5
|
mountdir="$5"
|
||||||
echo "$APACHE_SHARE_TEMPLATE" | sed "s#_SHARE_DIR_#$mount_dir#g; s#_VOLUME_NAME_#$vol_name#g" >"$APACHE_CONF_DIR/${vol_name}.conf"
|
echo "$APACHE_SHARE_TEMPLATE" | sed s\#_SHARE_DIR_\#"$mountdir"\#g | sed s\#_VOLUME_NAME_\#"$vol_name"\#g > ${APACHE_CONF_DIR}/${vol_name}.conf
|
||||||
update_include_conf_dir
|
#update_include_conf_dir
|
||||||
send_reload_command
|
send_reload_command
|
||||||
;;
|
;;
|
||||||
preumount )
|
preumount )
|
||||||
vol_name=$3
|
vol_name="$3"
|
||||||
rm "$APACHE_CONF_DIR/${vol_name}.conf" || true
|
rm "$APACHE_CONF_DIR/${vol_name}.conf" || true
|
||||||
update_include_conf_dir
|
#update_include_conf_dir
|
||||||
send_reload_command
|
send_reload_command
|
||||||
;;
|
;;
|
||||||
shutdown | bootup )
|
shutdown | bootup )
|
||||||
|
|
Loading…
Reference in a new issue