Skip to content

Instantly share code, notes, and snippets.

@jwoffindin
Created August 26, 2013 03:15
Show Gist options
  • Save jwoffindin/6337827 to your computer and use it in GitHub Desktop.
Save jwoffindin/6337827 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
SNAPSHOT_ID=${1-"snap-8faa63bc"}
STAGING_INSTANCE_ID=${2-"i-55538e69"}
ZONE=$(ec2-describe-instance-status ${STAGING_INSTANCE_ID} | awk '$1 == "INSTANCE" { print $3 }')
# REGION=$([[ $EC2_URL =~ /.*ec2\.(.*)\.amazonaws.com/ ]] && echo ${BASH_REMATCH[1]})
# Create volume, wait for it to be available
echo "creating volume"
VOLUME_ID=$(ec2-create-volume --snapshot ${SNAPSHOT_ID} -z ${ZONE} | cut -f 2)
while [[ $(ec2-describe-volumes ${VOLUME_ID} | cut -f 6) != 'available' ]] ; do i
echo waiting
sleep 1
done
# Remember volume-id for later
echo ${VOLUME_ID} > /tmp/staging-volume
# Attach to staging
echo "attaching"
ec2-attach-volume ${VOLUME_ID} --instance ${STAGING_INSTANCE_ID} --device /dev/sdk
while ! $(ec2-describe-instance-attribute $STAGING_INSTANCE_ID --block-device-mapping | grep -q '/dev/sdk') ; do
echo "waiting for attachment"
sleep 1
done
echo "checking device availability"
DEVICE=$(ssh staging.target cat /proc/partitions | awk '$1 ~ /[0-9]+/ && $4 !~ /xvde/ { print $4; exit }')
# ssh staging.target sudo mount ${DEVICE}2 /mnt
echo "*** Device is available under /dev/${DEVICE}"
echo "/dev/${DEVICE}" | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment