-
-
Save thiagoh/8cbfa1a512acc5b308fffcbd764aac16 to your computer and use it in GitHub Desktop.
Create and manage a case-sensitive disk-image on OSX. This is great when you have a need to work with case-sensitive repos on a mac.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# where to store the sparse-image | |
WORKSPACE=~/Documents/workspace.dmg.sparseimage | |
create() { | |
if [ -f $WORKSPACE ]; then | |
echo "File ${WORKSPACE} already exists"; | |
exit 1; | |
fi | |
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 256g -volname workspace ${WORKSPACE} | |
} | |
detach() { | |
m=$(hdiutil info | grep "/Volumes/workspace" | cut -f1) | |
if [ ! -z "$m" ]; then | |
hdiutil detach $m | |
fi | |
} | |
attach() { | |
if [ ! -f $WORKSPACE ]; then | |
echo "File ${WORKSPACE} does not exist"; | |
exit 2; | |
fi | |
hdiutil attach ${WORKSPACE} | |
} | |
info() { | |
dev=$(hdiutil info | grep "/Volumes/workspace" | cut -f1) | |
hdiutil fsid $dev | |
} | |
compact() { | |
detach | |
hdiutil compact ${WORKSPACE} -batteryallowed | |
attach | |
} | |
show_help() { | |
echo "Usage: disk-utility command" | |
echo -e " -h --help\t\tShow this message" | |
echo -e " -c --create\t\tCreates the volume at ${WORKSPACE}" | |
echo -e " -a --attach\t\tAttaches the volume at /Volumes/workspace" | |
echo -e " -d --detach\t\tDetaches the volume from /Volumes/workspace" | |
echo -e " -i --info\t\tPrints info about /Volumes/workspace" | |
} | |
invalid_input() { | |
echo "Invalid input" >&2 | |
show_help | |
exit 1000 | |
} | |
case "$1" in | |
--create) create;; | |
-c) create;; | |
--attach) attach;; | |
-a) attach;; | |
--info) info;; | |
-i) info;; | |
--detach) detach;; | |
-d) detach;; | |
--compact) compact;; | |
--help) show_help;; | |
-h) show_help;; | |
*) invalid_input;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment