Correct problems with using Keychain for backup drive credentials

This commit is contained in:
Andrew Miner
2017-08-10 08:16:43 -07:00
parent 306e87c38d
commit b9cee5300e
4 changed files with 20 additions and 23 deletions
+7 -9
View File
@@ -1,21 +1,19 @@
#!/bin/bash
#!/bin/bash -x
function die {
echo $*; exit 1
}
LOCAL_MOUNT="$HOME/.backup-drive"
HOST=$(security find-generic-password -a $USER -s backup-host -w)
SHARE=$(security find-generic-password -a $USER -s backup-share -w)
USERNAME=$(security find-generic-password -a $USER -s backup-username -w)
PASSWORD=$(security find-generic-password -a $USER -s backup-password -w)
DRIVE="afp://$USERNAME:$PASSWORD@$HOST/$SHARE"
DRIVE=$(cat ~/.backup-cred)
if ! mount | grep -q "$HOME/$LOCAL_MOUNT"; then
[[ "$DRIVE" == "" ]] && die "[$(date)] Could not find ~/.backup-cred"
if ! mount | grep -q "$LOCAL_MOUNT"; then
if [[ -e "$LOCAL_MOUNT" ]]; then
rm -rf "$LOCAL_MOUNT" || die "Could not mount to $LOCAL_MOUNT"
rmdir "$LOCAL_MOUNT" >/dev/null &2>1 || die "[$(date)] Could not mount to $LOCAL_MOUNT"
fi
mkdir -p "$LOCAL_MOUNT"
mount -t afp "$DRIVE" "$LOCAL_MOUNT" || die "Could not mount from $DRIVE"
mount -t afp "$DRIVE" "$LOCAL_MOUNT" || die "[$(date)] Could not mount backup drive"
fi