Perl Setup Script

February 25th, 2010 Leave a comment Go to comments

Using Apple’s Package System I built a package to install a variety of software, including apps, printer drivers, etc., to distribute to new or newly imaged systems. I found this a preferable alternative to a full system image, it is MUCH easier to maintain and test a package than it is to maintain and test a full system image that mush be pushed to multiple machines, and Apple Remote Desktop Makes the process of distributing and utilizing packages painless.

This script was the postflight (the last thing to run) script for the above mentioned package. It basically cleaned things up, set a bunch of system settings, and installed printers.

Software Installed by the Package:

  • Firefox
  • Disk Inventory X
  • Quicksilver (for the Admin user only, with a custom default plist so its preconfigured on first run)
  • Custom Wallpaper and LoginWindow.plist file that sets a title and message on the login window
  • Keychain Minder
  • iftop and PlistBuddy to /usr/local/sbin so I had definitive copies on the managed systems
  • Dell 3110cn Drivers
  • Lexmark 935c Drivers (had a separate package/script for setup, since it had a limited user base, but i wanted the drivers to be available to everybody)
  • A few select Shell and AppleScripts that do various things, from mounting network drives to resetting plists and repairing permissions, also a logout script to clear caches, trashes, and temp files as required by our security policy.
  • much, much more.

postflight

#!/usr/bin/perl
# AgComm Setup Script
# Built to run postflight in an installer package to set default printers and settings when setting up a new system for AgComm Use.
#
#
#
# Future: Use sysctl to fetch kernel values such as machine model for more automation.
#
#
#
# Written By: Nick Peelman
# Purdue University Agriculture Communcations Department
# Pieces Parsed from ITaP's Printer Maintenance Scripts
# http://web.ics.purdue.edu/~tjohnson/osxprinterscripts/
# www.purdue.edu
# September 2007

# Set Up Logging
$logfile="/Library/Logs/SetupPackage.log";
$starttime=`date`;
open(LOGFILE,">>$logfile") or die "Can't Open Logfile: $!";
print LOGFILE "#--- Started $starttime" ;

#################################################################
####################### LOGOUT SCRIPT #######################
#################################################################
#Not Necessary, handled by the loaded loginwindow.plist file.

#################################################################
##################### SYSTEM SETUP #########################
#################################################################

# Turn on Network Time Syncing. time.apple.com is the default and is fine.
`/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setusingnetworktime on`;

# Set Display Sleep to 10 Minutes
`/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setdisplaysleep 10`;

# Set Hard Disk Sleep to 30 Minutes
`/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setharddisksleep 30`;

# Turn off Computer Sleeping
`/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setcomputersleep off`;

# Make System Preferences Secure
print LOGFILE "Turning on Secure System Preferences...";
$result = `/usr/local/sbin/PlistBuddy -c "set :rights:system.preferences:shared false" /etc/authorization`;
if ($result == 0) {
print LOGFILE "Done\n";
} else {
print LOGFILE "Failed\n";
}

# Disable IPv6 on all network 802. based interfaces.
$ntwksetup = "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup";
@services=split(/\n/,`$ntwksetup -listallnetworkservices | grep -e Air -e 'Built-in Ether'`);

foreach $service (@services) {
print LOGFILE "Turning off IPv6 for $service...";
$result=`/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setv6off '$service'`;
if ($result == 0){
print LOGFILE "Done\n";
} else {
print LOGFILE "\n*******Error********\n...$result\n\n";
}
}

#################################################################
####################### PRINTERS #########################
#################################################################
# Set Up Department Printers

# But First flush the old ones
# cancel current tasks
print LOGFILE "canceling all printer tasks...";
$result=`cancel -a`;
if ($result == 0){
print LOGFILE "Done\n";
} else {
print LOGFILE "\n*******Error********\n...$result\n\n";
}
# remove exiting printers
@curPrinterList=split(/\n/,`lpstat -p | grep printer | awk '{ print \$2 }'`);
foreach $p (@curPrinterList) {
print LOGFILE "Removing $p...";
$result=`lpadmin -x $p`;
if ($result == 0){
print LOGFILE "Done\n";
} else {
print LOGFILE "\n*******Error********\n$result\n\n";
}
}

// If the Adobe Driver is Present, install the PDF printer, otherwise don't and move on.
if (-e "/Library/Printers/PPDs/Contents/Resources/en.lproj/ADPDF8.PPD")
{
`/bin/mkdir /var/spool/PDFMaker` if (!(-e "/var/spool/PDFMaker"));
`/usr/sbin/chown nobody /var/spool/PDFMaker`;
`/usr/bin/chgrp nobody /var/spool/PDFMaker`;
`/bin/chmod 777 /var/spool/PDFMaker`;
`/usr/sbin/lpadmin -p AdobePDF8 -L "Local Machine" -D "Adobe CS3/Acrobat 8 PDF Printer" -E -v "pdf800://distiller/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/ADPDF8.PPD" && echo "Adobe PDF Printer Successfully Added" >> $logfile`;
}
else
{
print LOGFILE "Adobe PDF Driver Not Present, Adobe PDF Printer Not Installed\n";
}

`/usr/sbin/lpadmin -p AgAD016-HP2420 \
-L "AgAD 016" \
-D "HP 2420 in AGAD 016" \
-E \
-v "socket://10.0.0.93/?bidi" \
-P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 2420.gz" && echo "AgAD 016 HP2420 Added Successfully" >> $logfile || echo "Error Adding AgAD 016" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD206-HP2420 -L "AgAD 206" -D "HP 2420 in AGAD 206 Next to Student Station" -E -v "lpd://10.0.0.143/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 2420.gz" -o HPOption_Duplexer=True -o Resolution=1200x1200dpi -o InstalledMemory=Mem64_79 && echo "AgAD 206 HP2420 Added Successfully" >> $logfile || echo "Error Adding AgAD 206" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD207-HP4050 -L "AgAD 207" -D "HP 4050 in AGAD 207 In News Students Cubicle" -E -v "lpd://10.0.0.28/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 4050 Series.gz" && echo "AgAD 207 HP4050 Added Successfully" >> $logfile || echo "Error Adding AgAD 207" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD207-HP8150 -L "AgAD 207" -D "HP 8150 in AGAD 207 Near DTN" -E -v "lpd://10.0.0.97/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 8150 Series.gz" && echo "AgAD 207 HP8150 Added Successfully" >> $logfile || echo "Error Adding AgAD 207" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD204-HP2420 -L "AgAD 204" -D "HP 2420 in AGAD 204 Near Door" -E -v "lpd://10.0.0.150/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 2420.gz" -o HPOption_Duplexer=True -o Resolution=1200x1200dpi -o InstalledMemory=Mem64_79 && echo "AgAD 204 HP2420 Added Successfully" >> $logfile || echo "Error Adding AgAD 204" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD211-HP2420 -L "AgAD 211" -D "HP 2420 in AGAD 211 Near Door" -E -v "lpd://10.0.0.98/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 2420.gz" && echo "AgAD 211 HP2420 Added Successfully" >> $logfile || echo "Error Adding AgAD 211" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD202-HP5550 -L "AgAD 202" -D "HP 5550 in AgAD 202" -E -v "lpd://10.0.0.151/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP Color LaserJet 5550.gz" -o HPOption_Duplexer=True -o InstalledMemory=416_544 -o HPOption_500_Sheet_Feeder_Tray3=True -o HPOption_500_Sheet_Feeder_Tray4=True -o HPOption_500_Sheet_Feeder_Tray5=True -o HPOption_Disk=HardDisk && echo "AgAD 202 HP5550 Added Successfully" >> $logfile || echo "Error Adding AgAD 202" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD202-HP2420 -L "AgAD 202" -D "HP 2420 in AGAD 202 Near the PC" -E -v "lpd://10.0.0.89/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 2420.gz" -o HPOption_Duplexer=True -o Resolution=1200x1200dpi -o InstalledMemory=Mem64_79 && echo "AgAD 202 HP2420 Added Successfully" >> $logfile || echo "Error Adding AgAD202" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD203-HP2300 -L "AgAD 203" -D "HP 2300 in AGAD 203 Near Door" -E -v "lpd://10.0.0.163/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/hp LaserJet 2300.gz" -o Resolution=1200x1200dpi -o InstalledMemory=48MB && echo "AgAD 203 HP2300 Added Successfully" >> $logfile || echo "Error Adding AgAD203" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD010-HP4000 -L "AgAD 010" -D "HP 4000 in AGAD 010 (mailroom) Near the counter" -E -v "lpd://10.0.0.24/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 4000 Series.gz" && echo "AgAD 010 HP4000 Added Successfully" >> $logfile || echo "Error Adding AgAD010" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD003-HP2420 -L "AgAD 003" -D "HP 2420 in AGAD 003 Next to Dell 3110cn" -E -v "lpd://10.0.0.91/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 2420.gz" -o HPOption_Duplexer=True -o Resolution=1200x1200dpi -o InstalledMemory=Mem64_79 && echo "AgAD 003 HP2420 Added Successfully" >> $logfile || echo "Error Adding AgAD003 HP2420" >> $logfile`;

#################################################################
# The Three Dell Color Lasers
`/usr/sbin/lpadmin -p AgAD003-Dell3110cn -L "AgAD 003" -D "Dell 3110cn in AGAD 003 near Copy Machine" -E -v "socket://10.0.0.27/?bidi" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Dell Color Laser 3110cn.gz" && echo "AgAD 003 Dell Added Successfully" >> $logfile || echo "Error Adding AgAD003 Dell" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD206-Dell3110cn -L "AgAD 206" -D "Dell 3110cn in AGAD 206 Beside the Fax" -E -v "socket://10.0.0.47/?bidi" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Dell Color Laser 3110cn.gz" && echo "AgAD 206 Dell Added Successfully" >> $logfile || echo "Error Adding AgAD206 Dell" >> $logfile`;

`/usr/sbin/lpadmin -p AgAD205-Dell3110cn -L "AgAD 205" -D "Dell 3110cn in AGAD 205 near the door" -E -v "socket://10.0.0.48/?bidi" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Dell Color Laser 3110cn.gz" && echo "AgAD 205 Dell Added Successfully" >> $logfile || echo "Error Adding AgAD 205 Dell" >> $logfile`;

#################################################################
#################################################################
# AIDC Printers

`/usr/sbin/lpadmin -p AIDC-Epson1520 -L "AIDC" -D "Epson Stylus Color 1520" -E -v "lpd://10.0.0.101/" -P "/usr/share/cups/model/gimp-print/5.0/C/stp-escp2-1520.5.0.ppd.gz" && echo "AIDC Epson Added Successfully" >> $logfile || echo "Error Adding AIDC Epson" >> $logfile`;

`/usr/sbin/lpadmin -p AIDC-HP4000 -L "AIDC" -D "HP 4000 at the AIDC" -E -v "lpd://10.0.0.102/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 4000 Series.gz" && echo "AIDC HP4000 Added Successfully" >> $logfile || echo "Error Adding AIDC HP4000" >> $logfile`;

`/usr/sbin/lpadmin -p AIDC-HPDesignJet800PS -L "AIDC" -D "HP DesignJet 800PS at AIDC" -E -v "lpd://10.0.0.101/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP Designjet 800 PS3.gz" && echo "AIDC DesignJet Added Successfully" >> $logfile || echo "Error Adding AIDC DesignJet" >> $logfile`;

`/usr/sbin/lpadmin -p AIDC-HP8150 -L "AIDC" -D "HP 8150 B&W at AIDC" -E -v "lpd://10.0.0.105/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 8150 Series.gz" && echo "AIDC HP8150 Added Successfully" >> $logfile || echo "Error Adding AIDC HP8150" >> $logfile`;

`/usr/sbin/lpadmin -p AIDC-HP8550 -L "AIDC" -D "HP 8550 Color at AIDC" -E -v "lpd://10.0.0.106/" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP Color LaserJet 8550.gz" && echo "AIDC HP8550 Added Successfully" >> $logfile || echo "Error Adding HP8550" >> $logfile`;
#################################################################
#################################################################

# Close Logging and clean up
$endtime = `date`;
print LOGFILE "#--- Completed $endtime";
close LOGFILE;

  1. No comments yet.
  1. No trackbacks yet.
blog comments powered by Disqus