So another thing people seemed keen on is my system for setting up appropriate WebDAV realms for iCal publishing automatically for personal web pages on Mac OS X Server. This kind of follows on from the previous entry, but you could easily put the two scripts together.
It assumes:
- ~/Sites for personal web pages.
- The actual file server for home directories is also running Apache for personal web pages. If you instead have personal web pages on another server, you'll have to use the mount in /Network/Servers rather than the local path. If anyone needs to do this instead, post a comment and I'll modify the script for you.
- ~/Sites/calendars already exists, and is where iCal publishes to. See the previous entry on setting up WebDAV areas for how to automatically do this. You could roll both scripts together, but I like to set the ~/Sites permissions more freuently than I set up new WebDAV realms.
- Each user is the only person who can publish to this location.
Again, you'll notice that I'm doing this by looping over the contents of the network home directory sharepoint, rather than collecting users from Directory Services. You might also notice that the actual path that Apache serves out is the mount in /Network/Servers, not the local filesystem path. I like having my staff webpages being served from the same server as my staff home directories, but this isn't a requirement.
To start with, I set up a comment line in the relevant apache config file that will mark off where the WebDAV realms start. You'll find this file in /etc/httpd/sites/, and I use a comment like this:
# Start automatic realms for staff calendars
Then I have this script run, which basically just looks for the comment line, trashes everything below it, and generates the right syntax for WebDAV realms to be appended.
Then I run apachectl configtest, and check the exit status to make sure that Apache is happy with the config. If it isn't happy (which hasn't happened yet, but better safe than sorry), it copies the original config file back, and emails me to let me know that something has gone wrong. If it is happy, it restarts apache with the new config file.
In this example, /Volumes/Homes/staff is the sharepoint, and this is mounted at /Network/Servers/server.domain/Volumes/Homes/staff, so change those to match your setup.
#!/bin/bash
CONFFILE="/etc/httpd/sites/0000_any_443_your.server.apache.config.file.conf"
STARTNUM=$(cat $CONFFILE |grep -n "# Start automatic realms for staff calendars" | sed 's|:.*||g')
STARTNUM=$(expr $STARTNUM - 1 )
rm -f /tmp/site.conf
head -n $STARTNUM $CONFFILE > /tmp/site.conf
echo "# Start automatic realms for staff calendars" >> /tmp/site.conf
cd /Volumes/Homes/staff
for user in $(ls | grep -e "^[a-z]")
do
echo "<Directory \"/Network/Servers/server.domain/Volumes/Homes/staff/$user/Sites/calendars/\">" >> /tmp/site.conf
echo "<IfModule mod_dav.c>" >> /tmp/site.conf
echo "DAV On" >> /tmp/site.conf
echo "</IfModule>" >> /tmp/site.conf
echo " AuthName \"$user\"" >> /tmp/site.conf
echo " <Limit PUT DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>" >> /tmp/site.conf
echo " Require user $user" >> /tmp/site.conf
echo " </Limit>" >> /tmp/site.conf
echo " AuthType Digest" >> /tmp/site.conf
echo "</Directory>" >> /tmp/site.conf
done
echo "# End automatic staff realms" >> /tmp/site.conf
echo "</VirtualHost>" >> /tmp/site.conf
mkdir -p /etc/httpd/backup
cp $CONFFILE /etc/httpd/backup
cp /tmp/site.conf $CONFFILE
/usr/sbin/apachectl configtest
if [ $? -ne 0 ]
then
mv /etc/httpd/backup/*.conf /etc/httpd/sites
echo "Something went wrong with the auto realm script" | mail -s "ERROR: auto realm" your.email@your.domain
else
/usr/sbin/apachectl graceful
fi
So as always, buyer beware, backup your stuff before you try it, and make sure you get the paths right, as that's where Apache serves personal web pages from.