Skip to content

Instantly share code, notes, and snippets.

@calum-github
Created February 9, 2016 22:55
Show Gist options
  • Select an option

  • Save calum-github/4a0256e8d213d4f1678f to your computer and use it in GitHub Desktop.

Select an option

Save calum-github/4a0256e8d213d4f1678f to your computer and use it in GitHub Desktop.
RAM Check - With CD for dialogs
#!/bin/bash
########################################################################
# Author: Calum Hunter #
# Date: 04/02/2016 #
# Version: 0.1 #
# Purpose: Ensure we have atleast 4GB of RAM to play #
# #
########################################################################
# Get the RAM installed in this machine in gigabytes
installed_memory=$(hostinfo | awk -F ': ' '/memory/ {print $2}' | awk -F "." '{print $1}')
# Required minimum installed memory (in Gigabytes)
required_memory="4"
# Path to Cocoa Dialog
CD="/Applications/cocoaDialog.app/Contents/MacOS/cocoaDialog"
display_insufficient_ram(){
not_enough_rams=($($CD msgbox --title "Warning!" --icon computer --text "Insufficient RAM Detected" --no-newline --informative-text "${required_memory}GB of RAM is required.
Only ${installed_memory}GB was detected as being installed in this machine.
If you feel this is in error, please contact IT Support." --button1 "Shutdown" ))
if [ "$not_enough_rams" = "1" ]; then
shutdown -h now
fi
}
# Test to see if we have = to or greater than required_memory
if [ "$installed_memory" -lt "$required_memory" ]; then
display_insufficient_ram
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment