2015-10-09 12:29:32 +00:00
|
|
|
#! /bin/bash
|
|
|
|
# vim: set tabstop=4 shiftwidth=4 expandtab filetype=sh:
|
2015-10-04 09:20:54 +00:00
|
|
|
|
|
|
|
# afpsync: updates .AppleDouble components of files on shared volumes
|
|
|
|
|
|
|
|
# this must be used if any files are copied to the shared volume via
|
|
|
|
# non-AFP methods (directly, via Samba, etc).
|
|
|
|
|
|
|
|
# usage:
|
|
|
|
# afpsync [-v] [shared volume path]
|
|
|
|
#
|
|
|
|
# -v will silently create a .volinfo file if none exists.
|
|
|
|
# If a path is specified, only that volume is synced; otherwise, all
|
|
|
|
# all paths in /media which appear in
|
|
|
|
# /usr/local/etc/netatalk/AppleVolumes.default are synced.
|
|
|
|
|
|
|
|
processPath () {
|
|
|
|
if [[ ! -d $sharepath ]]; then
|
|
|
|
echo "$sharepath does not exist."
|
|
|
|
else
|
|
|
|
volinfo="$sharepath/.AppleDesktop/.volinfo"
|
|
|
|
if [[ ! -f $volinfo ]]; then
|
|
|
|
if [[ ! $force ]]; then
|
|
|
|
echo "Cannot update AppleDouble files for volume $sharepath,"
|
|
|
|
echo "because its .volinfo file does not exist. To create it, log"
|
|
|
|
echo "into the volume from an Apple II or Mac client computer,"
|
|
|
|
echo "or use \"afpsync -v\"."
|
|
|
|
else
|
|
|
|
if (( $1 )); then
|
|
|
|
mkvolinfo -f -c $sharepath
|
|
|
|
else
|
|
|
|
mkvolinfo -f $sharepath
|
|
|
|
fi
|
|
|
|
$0 $sharepath
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
IFS=''
|
|
|
|
result=$(sudo dbd -r $sharepath | grep encoding)
|
|
|
|
f=$(echo $result | wc -l)
|
|
|
|
[[ $(echo $result | wc -w) == 0 ]] && f=0
|
|
|
|
[[ f -eq 1 && $(echo $result | grep APPLEDESKTOP) && $(grep MTOULOWER $sharepath/.AppleDesktop/.volinfo) ]] && (( f-- ))
|
|
|
|
if (( f == 0 )); then
|
|
|
|
echo "AppleDouble files have been updated for volume $sharepath."
|
|
|
|
else
|
|
|
|
[[ ! $renameLower ]] && echo "Could not update all files on volume $sharepath."
|
|
|
|
[[ ! $renameLower ]] && echo "Ensure filenames are all caps on volume $sharepath."
|
|
|
|
if [[ $showerrors ]]; then
|
|
|
|
echo $result \
|
2015-10-09 12:29:32 +00:00
|
|
|
| while read LINE; do
|
2015-10-04 09:20:54 +00:00
|
|
|
[[ ! $(echo $LINE | grep APPLEDESKTOP) ]] && echo $LINE
|
|
|
|
done
|
|
|
|
elif [[ $renameLower ]]; then
|
|
|
|
echo $result \
|
2015-10-09 12:29:32 +00:00
|
|
|
| while read LINE; do
|
2015-10-04 09:20:54 +00:00
|
|
|
if [[ ! $(echo $LINE | grep APPLEDESKTOP) ]]; then
|
|
|
|
filepath=$(echo $LINE | sed "s/^Bad\ encoding\ for\ '//" | sed s/\'//)
|
|
|
|
filename=${filepath##*/}
|
|
|
|
filedir=${filepath%/*}
|
|
|
|
mv $filepath $filedir/${filename^^}
|
|
|
|
echo "Renamed $filedir/${filename^^}."
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
$0 $sharepath
|
|
|
|
else
|
|
|
|
echo "Use afpsync -e to see error details."
|
|
|
|
echo "Use afpsync -r to rename lowercase names to uppercase."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
unset IFS
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
while [[ $1 == "-r" || $1 == "-e" || $1 = "-v" ]]; do
|
|
|
|
|
|
|
|
if [[ $1 == "-v" ]]; then
|
|
|
|
force=1
|
|
|
|
shift
|
|
|
|
fi
|
2015-10-09 12:29:32 +00:00
|
|
|
|
2015-10-04 09:20:54 +00:00
|
|
|
if [[ $1 == "-e" ]]; then
|
|
|
|
showerrors=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $1 == "-r" ]]; then
|
|
|
|
renameLower=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ ${1:0:1} == "-" ]]; then
|
|
|
|
echo "Usage: afpsync [-e|-r] [-v] [shared volume path]"
|
|
|
|
echo
|
|
|
|
echo "-e: show error details"
|
|
|
|
echo "-r: rename lowercase filenames to uppercase"
|
|
|
|
echo "-v: create .volinfo file if none exists"
|
|
|
|
echo "If no directory is specified, all found in"
|
|
|
|
echo " /usr/local/etc/netatalk/AppleVolumes.default are processed."
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
sudo true
|
|
|
|
if [[ $1 ]]; then
|
|
|
|
sharepath=$(readlink -m $1)
|
|
|
|
processPath
|
2015-10-09 12:29:32 +00:00
|
|
|
else
|
2015-10-04 09:20:54 +00:00
|
|
|
grep ^/media /usr/local/etc/netatalk/AppleVolumes.default | \
|
2015-10-09 12:29:32 +00:00
|
|
|
while read line; do
|
2015-10-04 09:20:54 +00:00
|
|
|
[[ $(echo $line | grep toupper) ]]; nocasefold=$?
|
|
|
|
sharepath=$(echo $line | cut -d" " -f1)
|
|
|
|
processPath nocasefold
|
|
|
|
done
|
|
|
|
fi
|
2015-10-09 12:29:32 +00:00
|
|
|
fi
|