#! /bin/sh # publish - make a directory available for AppleShare via AUFS # Rex Sanders, US Geological Survey, Fri Nov 29 15:17:49 PST 1991 # US Government work - public domain - no copyright if [ $# -gt 2 ] then echo "Usage: publish [directory] [AppleShare-name]" >&2 exit 1 fi if [ $# -eq 0 ] then echo "Directory:AppleShare-name:" echo "--------- ---------------" cat $HOME/.afpvols exit fi # Directory must be there and writable if test '(' ! -d $1 ')' then echo "publish: Cannot publish $1: No such directory" >&2 exit 3 fi if test '(' ! -w $1 ')' then echo "publish: Cannot publish $1: Permission denied" >&2 exit 3 fi # If directory starts with '/', use that; else expand relative to working dir # (Why not use expr instead of grep - EXPR IS BRAIN-DAMAGED!) if echo "$1" | grep '^/' > /dev/null then dir=$1 else dir=`pwd`/$1 fi # Check directory name for ":" in path if echo "$dir" | grep ':' > /dev/null then echo "publish: Cannot publish $dir - ':' in name" >&2 exit 4 fi # asn -- AppleShare Name, from command line or base of directory name if [ $# -eq 2 ] then asn=$2 else asn=`basename $1` fi if test -f $HOME/.afpvols -a -r $HOME/.afpvols then # Check for asn already in use if fgrep ":${asn}:" $HOME/.afpvols > /dev/null then echo "publish: AppleShare name \"${asn}\" already used" >&2 exit 5 fi # Check for directory overlap if `awk < $HOME/.afpvols \ "BEGIN { dir = \"$dir\"; ld = length(dir); FS = \":\"; good = 1}"' {if (good) { l1 = length($1) if (index($1, dir) == 1) { if (l1 == ld) { print "true"; good = 0 } else if (substr($1, ld + 1, 1) == "/") { print "true"; good = 0 } } if (index(dir, $1) == 1) { if (l1 == ld) { print "true"; good = 0 } else if (substr(dir, l1 + 1, 1) == "/") { print "true"; good = 0 } } } } END { if (good) {print "false"} }'` then echo "publish: Cannot publish \"${dir}\" - overlap with published directory" exit 6 fi fi # Create .afpvols if it doesn't already exist touch $HOME/.afpvols touch $1/.ADeskTop 2>/dev/null touch $1/.IDeskTop 2>/dev/null mkdir $1/.finderinfo 2>/dev/null mkdir $1/.resource 2>/dev/null # Add entry to .afpvols echo "${dir}:${asn}:" >> $HOME/.afpvols