Open davidje13 opened 7 years ago
This has been mostly addressed by 5a8c6499ff951a7f0487b70395c73d93b0d50699, but it would be nice to have it automatic rather than manually entered commands (needs some safety checks and a way to run the code before checking out the repo to the drive).
Here's a first pass at how this could look scripted (but untested)
DEV_VIRT="$(diskutil list external virtual | grep '/dev/' | tail -n1 | cut -f1 -d' ')";
DEV_PHYS="$(diskutil list external physical | grep '/dev/' | tail -n1 | cut -f1 -d' ')";
ORIG_VOLUME="$(mount | grep "$DEV_VIRT" | tail -n1 | cut -f 3 -d' ')";
CHOSEN_NAME="keys"; # todo: make customisable
if [[ -z "$DEV_VIRT" ]] || [[ -z "$DEV_PHYS" ]] || [[ -z "$ORIG_VOLUME" ]]; then
echo "Failed to identify USB drive; have you connected it?";
exit 1;
fi;
echo "Identified external drive: $DEV_VIRT ($DEV_PHYS) at $ORIG_VOLUME";
echo "Is this correct? (CAREFUL! Confirming will erase and reformat the volume)";
read CONFIRMATION;
if ! [[ "$CONFIRMATION" == "y"* ]]; then
echo "Aborting";
exit 1;
fi;
echo "Erasing $ORIG_VOLUME...";
diskutil eraseVolume jhfsx "$CHOSEN_NAME" "$ORIG_VOLUME";
echo "Partitioning $DEV_PHYS...";
diskutil partitionDisk "$DEV_PHYS" GPT JHFS+ "$CHOSEN_NAME" 0b;
echo "Password protecting...";
diskutil cs convert "/Volumes/$CHOSEN_NAME/" -passphrase;
echo "Installing script...";
cd "/Volumes/$CHOSEN_NAME/";
git clone "git@github.com:pivotal/usb-login-scripts.git";
./usb-login-scripts/install.sh;
Setting up a new USB stick requires the following manual process (quoted in the readme):
This could be completed using a few commands which would be simpler to follow when setting up. See for example: http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1
Formatting can be done with:
Need to find out how to apply encryption (and if necessary, how to change partition table type). Also need to ensure safety checks are applied to avoid accidentally reformatting the wrong drive.