Last active
August 29, 2015 14:01
-
-
Save jacobsalmela/c87a903163c3f2490efe to your computer and use it in GitHub Desktop.
single-user-mode-ids
This file contains 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 | |
#----------VARIABLES--------- | |
# Manually set ethernet device ID | |
ethernetID="en0" | |
# Put static IPv4 with subnet mask here | |
ethernetIP="10.x.x.x 255.x.x.x" | |
# Organization name (reverse-domain plist format) | |
orgName="org.enterprise.casper" | |
# Capture date for storing in custom plist | |
currentDate=$(date "+%Y-%m-%d %H:%M:%S") | |
#----------FUNCTIONS--------- | |
####################### | |
function mountAndLoad() | |
{ | |
/sbin/mount -uw / | |
# Loads daemons needed for networking in SUM | |
launchctl load /System/Library/LaunchDaemons/com.apple.kextd.plist | |
launchctl load /System/Library/LaunchDaemons/com.apple.notifyd.plist | |
launchctl load /System/Library/LaunchDaemons/com.apple.configd.plist | |
sleep 15 | |
# Needed to send messages to the system log | |
launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist | |
} | |
########################## | |
function setWiredAddress() | |
{ | |
ifconfig $ethernetID $ethernetIP | |
#ipconfig set $ethernetID INFORM $ethernetIP | |
} | |
########################## | |
function setPromptCommand() | |
{ | |
# Appends any commands entered into the syslog with the tag SUM-IDS | |
PROMPT_COMMAND='history -a;tail -n1 ~/.sh_history | logger -t SUM-IDS' | |
} | |
########################## | |
function logDateInPlist() | |
{ | |
# Delete previous value if it exits | |
/usr/libexec/PlistBuddy -c "Print :SingleUserModeAccessedOn" /Library/Preferences/"$orgName".plist &>/dev/null | |
# If the last command exited with 0 (meaning the key exists) | |
if [ $? = 0 ];then | |
# Delete previous value and write in the updated date | |
/usr/libexec/PlistBuddy -c "Delete :SingleUserModeAccessedOn" /Library/Preferences/"$orgName".plist &>/dev/null | |
/usr/libexec/PlistBuddy -c "Add :SingleUserModeAccessedOn string '$currentDate'" /Library/Preferences/"$orgName".plist &>/dev/null | |
else | |
# Otherwise, create an entry with the current date | |
/usr/libexec/PlistBuddy -c "Add :SingleUserModeAccessedOn string '$currentDate'" /Library/Preferences/"$orgName".plist &>/dev/null | |
fi | |
} | |
#################### | |
function warnUser() | |
{ | |
echo "Should you really be here? You might not like the consequences." | |
} | |
#---------------------------------# | |
#---------------------------------# | |
#----------SCRIPT BEGINS----------# | |
#---------------------------------# | |
#---------------------------------# | |
if [ $TERM = "vt100" ];then | |
mountAndLoad | |
setWiredAddress | |
setPromptCommand | |
logDateInPlist | |
warnUser | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment