Skip to content

Instantly share code, notes, and snippets.

@mmb
Last active Jul 13, 2016
Embed
What would you like to do?
#!/bin/bash
set -e
COPY_PATH=$(mktemp -t add_key)
MOUNT_PATH=/Volumes/mmb
KEY_EXPIRES_AT=$(date -v18H -v0M -v0S +%s)
NOW=$(date +%s)
KEY_LIFETIME=$(($KEY_EXPIRES_AT - $NOW))
if [ "$KEY_LIFETIME" -lt "1" ]; then
KEY_LIFETIME=1h
fi
cat > $COPY_PATH << EOF
#!/bin/bash
set -e
ssh-add -t $KEY_LIFETIME $MOUNT_PATH/id_rsa
diskutil eject $MOUNT_PATH
rm $COPY_PATH
EOF
chmod u+x $COPY_PATH
exec $COPY_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment