#!/bin/bash # Copyright (C) Wizardry and Steamworks. # Generate afpd mountpoints for applications # containing a non-empty Documents folder # in order to access the application files. APPS_DIRECTORY='/private/var/mobile/Applications' NETATALK_CONFIG_DIRECTORY='/etc/netatalk/' NETATALK_CONFIG_FILE='AppleVolumes.default' # Sanity checks. if [ ! -d $NETATALK_CONFIG_DIRECTORY ] || [ ! -f $NETATALK_CONFIG_DIRECTORY/$NETATALK_CONFIG_FILE ]; then echo "Netatalk configuration not found, cannot proceed." fi # Clean file of previous entries. sed -i'' -n '/Applications/!p' $NETATALK_CONFIG_DIRECTORY/$NETATALK_CONFIG_FILE # Find folders and add to afpd configure file. data=() IFS=$'\n' for UUID in `find $APPS_DIRECTORY/ -name Documents | awk 'BEGIN {FS="/"} { print $6 }'`; do for APP_FOLDER in `ls -d $APPS_DIRECTORY/$UUID/*.app | awk 'BEGIN {FS="/"} { print $7}'`; do if [ "$(ls -A $APPS_DIRECTORY/$UUID/Documents)" ]; then NAME=`echo $APP_FOLDER | awk 'BEGIN { FS = "." } { print $1 }'` data[$[${#data[@]}+1]]="$APPS_DIRECTORY/$UUID/Documents \"$NAME\"" fi done done # Time of surprise to time of rape, that's why. printf "%s\n" "${data[@]}" >> $NETATALK_CONFIG_DIRECTORY/$NETATALK_CONFIG_FILE AFPD_PID=`ps -ax | grep '[a]fpd' | awk '{print $1}'` if [ !-z $APFD_PID ]; then kill -s HUP $AFPD_PID fi