Skip to content

Instantly share code, notes, and snippets.

@Naikless
Last active October 3, 2026 21:40
Show Gist options
  • Select an option

  • Save Naikless/b3c9f4d3fecf34f1b1a3b541c9306ab8 to your computer and use it in GitHub Desktop.

Select an option

Save Naikless/b3c9f4d3fecf34f1b1a3b541c9306ab8 to your computer and use it in GitHub Desktop.
Re-enable WebDAV on WD MyCloudEX2Ultra for OS 5
#!/bin/sh
# Define key paths as variables
SETUP_DIR="/usr/local/config/setup_webdav"
APACHE_CONF_DIR="/usr/local/apache2/conf"
SYSTEM_CONF="/usr/local/config/system.conf"
TARGET_HTTPD_CONF="$SETUP_DIR/httpd.conf"
MODS_ENABLED_DIR="$SETUP_DIR/mods-enabled"
# Create necessary directories
mkdir -p "$MODS_ENABLED_DIR"
# Create setup_webdav.sh script
cat << EOF > "$SETUP_DIR/setup_webdav.sh"
#!/bin/sh
cp -f $SETUP_DIR/httpd.conf $APACHE_CONF_DIR/httpd.conf
cp -f $SETUP_DIR/mods-enabled/* $APACHE_CONF_DIR/mods-enabled
cp -f $SETUP_DIR/webdav.passwd $APACHE_CONF_DIR/
mkdir -p /var/lock/apache2/DAVLock
apache restart web
EOF
chmod +x "$SETUP_DIR/setup_webdav.sh"
# Create a copy of the current Apache config with WebDAV settings appended
cp -f "$APACHE_CONF_DIR/httpd.conf" "$TARGET_HTTPD_CONF"
cat << EOF >> "$TARGET_HTTPD_CONF"
# WebDAV config
Alias /webdav /mnt/HD/HD_a2/webdav
DAVLockDB /var/lock/apache2/DAVLock
<Directory /mnt/HD/HD_a2/webdav>
Options Indexes FollowSymLinks
AllowOverride None
DAV On
AuthType Basic
AuthName "WebDAV"
AuthUserFile $APACHE_CONF_DIR/webdav.passwd
Require valid-user
SecRuleEngine Off
</Directory>
EOF
# Prompt for username and create password file
echo "Enter username for WebDAV access:"
read username
htpasswd -c "$SETUP_DIR/webdav.passwd" "$username"
# Create dav.load module configuration
cat << EOF > "$MODS_ENABLED_DIR/dav.load"
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
EOF
chmod +x "$MODS_ENABLED_DIR/dav.load"
# Append WebDAV startup block to system.conf
cat << EOF >> "$SYSTEM_CONF"
# ensure that this file isn't overwritten during startup
(
cp -f $SYSTEM_CONF $SYSTEM_CONF.original
# Wait until system is likely done with startup
sleep 90
# setup and start webdav server
( $SETUP_DIR/setup_webdav.sh ) &
# Restore this version of system.conf
cp -f $SYSTEM_CONF.original $SYSTEM_CONF
) &
EOF
$SETUP_DIR/setup_webdav.sh
echo "✅ WebDAV setup complete. Files under $SETUP_DIR replace their corresponding files in $APACHE_CONF_DIR on reboot."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment