Skip to content

Instantly share code, notes, and snippets.

@jorng
Last active August 29, 2015 14:03
Show Gist options
  • Save jorng/7883f987c8a0cfbe3d79 to your computer and use it in GitHub Desktop.
Save jorng/7883f987c8a0cfbe3d79 to your computer and use it in GitHub Desktop.
A script to enable NetBoot storage settings for a specified volume. Replicates using Server.app to select 'Images & Client Data' for a specified volume. Takes one parameter: the volume to enable. If no parameter is provided, it will enable the root volume for NetBoot.
#!/bin/bash
OSXVersion=$(sw_vers -buildVersion)
if [[ "$OSXVersion" < "12A" ]]; then
ServerAdminPath="/usr/sbin/serveradmin"
else
ServerAdminPath="/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin"
fi
if [ ! -e $ServerAdminPath ]; then
echo "Unable to find 'serveradmin' tool. Is Server.app in the Applications folder?"
exit 1
fi
# Disable NetBoot service.
if ! $ServerAdminPath stop netboot; then
echo "Error trying to disable the NetBoot service."
exit 2
fi
if [ -z "$1" ]; then
storageVolume="/"
else
storageVolume="$1"
fi
# Get index for the volume provided.
netBootStorageIndex=$($ServerAdminPath settings netboot:netBootStorageRecordsArray | grep -e \"$storageVolume\" | awk -F : '{print $(NF-1)}')
# Enable for Images
$ServerAdminPath settings netboot:netBootStorageRecordsArray | sed "s/\($netBootStorageIndex:sharepoint =\) no/\1 yes/g" | $ServerAdminPath settings
# Enable for Client Data
$ServerAdminPath settings netboot:netBootStorageRecordsArray | sed "s/\($netBootStorageIndex:clients =\) no/\1 yes/g" | $ServerAdminPath settings
# Re-enable NetBoot service.
if ! $ServerAdminPath start netboot; then
echo "Error trying to re-enable the NetBoot service."
exit 2
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment