Skip to content

Instantly share code, notes, and snippets.

@acidprime
acidprime / validateport.sh
Created January 9, 2012 01:00
Validate Port , Scan a port with stroke from CSV list of servers
#!/bin/bash
# set -xv
# Required commands
declare -x awk="/usr/bin/awk"
declare -x dscl="/usr/bin/dscl"
declare -x defaults="/usr/bin/defaults"
declare -x cat="/bin/cat"
declare -x du="/usr/bin/du"
declare -x id="/usr/bin/id"
declare -x ntpdate="ntpdate"
@acidprime
acidprime / validateserial.sh
Created January 9, 2012 01:00
Validate Software Serial Number for 10.5 Server
#!/bin/bash
[ "$EUID" != 0 ] &&
printf "%s\n" "This script requires root access ($EUID)!" && exit 1
[ -f /System/Library/CoreServices/ServerVersion.plist ] &&
printf "%s\n" "This should not be run on Mac OS X Server!" && exit 1
[ -d /Library/Filesystems/Xsan/ ] &&
printf "%s\n" "You must remove Xsan on this system before using this tool" && exit 1
# Required commands
declare -x awk="/usr/bin/awk"
declare -x cat="/bin/cat"
@acidprime
acidprime / teacherfolders.sh
Created January 9, 2012 01:14
Basic Example of Creating Digital Lockers
#!/bin/bash
# set -xv
declare -x DST_DIR="$1"
declare -x DS_DOMAIN='/Active Directory/All Domains'
declare -x GROUP_ATTR='GroupMembership'
declare -x GROUP_NAME='DPS\teachers.388-wgp.vc - elementary'
declare -x NT_DOMAIN="$(dscl "$DS_DOMAIN" -read / PrimaryNTDomain |
awk '{print $NF}')"
if [ "${#DST_DIR}" -eq 0 ] ; then
echo "You must specify a destination directory"
@acidprime
acidprime / simpleswraid.sh
Created January 9, 2012 01:15
Create Software RAID
#!/bin/bash
declare -x MIRROR_VOL="Server HD"
declare -x RAID_VOL="/Volumes/Server HD"
declare -x RAID_VOL2="/Volumes/Server HD 2"
declare -x diskutil="/usr/sbin/diskutil"
# Name as MirroredVolume for Novice users in disk utility
$diskutil createRAID mirror "ServerRAID" JHFS+ "$RAID_VOL" "$RAID_VOL2"
# Rename to HD Name
$diskutil renameVolume /Volumes/ServerRAID "$MIRROR_VOL"
@acidprime
acidprime / dsimportloop.sh
Created January 9, 2012 01:18
Simple DSImport in for Loop
#!/bin/bash
for DSEXPORT in *.dsimport ; do
dseditgroup -o edit -n /LDAPv3/127.0.0.1 -u diradmin -P foobar -a "${DSEXPORT%%.dsimport}" -t user teachers
done
@acidprime
acidprime / deletekeychainintemplate.sh
Created January 9, 2012 01:22
Example Keychain Deletion Script for User Template
#!/bin/bash
declare -x USER_NAME="$1"
declare -x TEMPLATE_KEYCHAIN="/System/Library/User Template/English.lproj/Library/Keychains/login.keychain"
declare -x USER_KEYCHAIN="/Users/$USER_NAME/Library/Keychains/login.keychain"
# Commands
declare -x rm="/bin/rm"
declare -x mv="/bin/mv"
declare -x logger="/usr/bin/logger"
if [ -f "$TEMPLATE_KEYCHAIN" ] ; then
$rm "$TEMPLATE_KEYCHAIN"
@acidprime
acidprime / uglyass.sh
Created January 9, 2012 01:23
Ugly 10.6 Auto Server Setup Generator
#!/bin/bash
# Required commands
declare -x awk="/usr/bin/awk"
declare -x dscl="/usr/bin/dscl"
declare -x defaults="/usr/bin/defaults"
declare -x dscacheutil="/usr/bin/dscacheutil"
declare -x du="/usr/bin/du"
declare -x id="/usr/bin/id"
declare -x ntpdate="ntpdate"
@acidprime
acidprime / check15.sh
Created January 9, 2012 01:49
Check hostname is less then 15 , Apple Remote Desktop issues with Rename computers option and AD
#!/bin/bash
awk=/usr/bin/awk
ifconfig=/sbin/ifconfig
scutil=/usr/sbin/scutil
COMPUTER_NAME=`$scutil --get ComputerName`
LOCAL_HOST_NAME=`$scutil --get LocalHostName`
MAC_ADDRESS=`$ifconfig en0 ether | $awk '/ether/{gsub(":","",$NF);print $NF}'`
if [ "${#COMPUTER_NAME}" -gt 15 ] ; then
echo "Computer Name is greater then 15!"
if [ "${#LOCAL_HOST_NAME}" -gt 15 ] ; then
@acidprime
acidprime / createhwraid.sh
Created January 9, 2012 01:50
Create Hardware RAID
#!/bin/bash
# configure RAIDs
echo yes | raidutil delete volume -n Vol-RS1
echo yes | raidutil delete volume -n Vol-RS2
echo yes | raidutil delete volume -n Vol-RS3
raidutil delete raidset -n RS1
raidutil delete raidset -n RS2
raidutil delete raidset -n RS3
raidutil createraidset -n "Raid5Set" -d 1,2,3 -r 5
@acidprime
acidprime / fixhomes.sh
Created January 9, 2012 01:51
Fix Home Permissions Example
#!/bin/bash
# Runtime configuration
export SCHOOL_SITE="$(/bin/hostname -s |
/usr/bin/sed 's/ap.s0.//g' | /usr/bin/tr '[:lower:]' '[:upper:]')"
# Overrides for sites
if [ "$SCHOOL_SITE" = "SSC" ] ; then
export SCHOOL_SITE=TSD
fi
if [ "$SCHOOL_SITE" = "ADMIN" ] ; then