-
-
Save thoughtchad/6b6f198fcc23ac219306b61ad03c29e2 to your computer and use it in GitHub Desktop.
Create and manage a case-sensitive disk-image on macOS (OS X).
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 | |
# take ~/bin && curl https://gist.githubusercontent.com/thoughtchad/6b6f198fcc23ac219306b61ad03c29e2/raw/beb33c03078d9594386d611b31fc5a7209b232cb/workspace.sh > workspace && chmod +x workspace | |
# --------------------------------------------------------- | |
# Customizable Settings | |
# --------------------------------------------------------- | |
MOUNT_POINT="${CASE_SAFE_MOUNT_POINT:-${HOME}/dev}" | |
VOLUME_PATH="${CASE_SAFE_VOLUME_PATH:-${HOME}/.workspace-dev.dmg.sparseimage}" | |
VOLUME_NAME="${CASE_SAFE_VOLUME_NAME:-dev}" | |
VOLUME_SIZE="${CASE_SAFE_VOLUME_SIZE:-60g}" | |
# --------------------------------------------------------- | |
# Functionality | |
# --------------------------------------------------------- | |
create() { | |
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size ${VOLUME_SIZE} -volname ${VOLUME_NAME} ${VOLUME_PATH} | |
} | |
automount() { | |
attach | |
cat << EOF > /tmp/com.workspace.plist | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>Label</key> | |
<string>com.workspace</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>hdiutil</string> | |
<string>attach</string> | |
<string>-notremovable</string> | |
<string>-nobrowse</string> | |
<string>-mountpoint</string> | |
<string>${MOUNT_POINT}</string> | |
<string>${VOLUME_PATH}</string> | |
</array> | |
</dict> | |
</plist> | |
EOF | |
sudo cp /tmp/com.workspace.plist /Library/LaunchDaemons/com.workspace.plist | |
rm /tmp/com.workspace.plist | |
} | |
detach() { | |
m=$(hdiutil info | grep "${MOUNT_POINT}" | cut -f1) | |
if [ ! -z "$m" ]; then | |
sudo hdiutil detach $m | |
fi | |
} | |
attach() { | |
sudo hdiutil attach -notremovable -nobrowse -mountpoint ${MOUNT_POINT} ${VOLUME_PATH} | |
} | |
compact() { | |
detach | |
hdiutil compact ${VOLUME_PATH} -batteryallowed | |
attach | |
} | |
help() { | |
cat <<EOF | |
usage: workspace <command> | |
Possible commands: | |
create Initialize case-sensitive volume (only needed first time) | |
automount Configure macOS to mount the volume automatically on restart | |
mount Attach the case-sensitive volume | |
unmount Detach the case-sensitive volume | |
compact Remove any uneeded reserved space in the volume | |
config Show current configuration and instructions on changing | |
help Display this message | |
EOF | |
} | |
config() { | |
cat <<EOF | |
The behavior of the script may be modified by seting the following environment variables. | |
If not set the script will use sane defaults. | |
CASE_SAFE_MOUNT_POINT | |
Location where case-sensitive volume will be mounted | |
Current effective value: ${MOUNT_POINT} | |
CASE_SAFE_VOLUME_PATH | |
Location where image file should be stored | |
Current effective value: ${VOLUME_PATH} | |
CASE_SAFE_VOLUME_NAME | |
Name of workspace as visible in macOS Finder app | |
Current effective value: ${VOLUME_NAME} | |
CASE_SAFE_VOLUME_SIZE | |
Maximum size of volume (will auto-grow up to this) | |
Current effective value: ${VOLUME_SIZE} | |
EOF | |
} | |
invalid() { | |
printf "workspace: '$1' is not a valid command.\n\n"; | |
help | |
} | |
case "$1" in | |
create) create;; | |
automount) automount;; | |
mount) attach;; | |
unmount) detach;; | |
compact) compact;; | |
config) config;; | |
help) help;; | |
'') help;; | |
*) invalid $1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment