|
||||||||||||||||
|
Using AppleScript to automate
the installation and upgrade path By Andrew Winter The University of Sydney ABSTRACT |
||||||||||||||||
| The Faculty of Architecture at the University of Sydney runs a world class sophisticated design computing environment, comprising Power Macintoshes, SUN and SGI Unix workstations, and Pentium class PCs running Windows 95 and NT 4.0. Management and support of the computing environment is provided by finite human resources whilst the environment is continually expanding. (We have purchased over 50 new machines in the first half of1998.) Installation and (re)configuration of Macintoshes has been a labour intensive and time-consuming task. Much of the configuration of a Macintosh involves repetition that is ideally suited to an automated solution. An automated solution dramatically decreases the amount of human time required to correctly configure a machine, and minimalises human errors in the installation and configuration process. As well as decreasing the amount of human time, automated solution decreases the amount of real time to install multiple machines, as the installation does not need to wait for the administrator to perform the next task, and multiple machines can be configured simultaneously. AppleScript is the ideal product to help the administrator to automate installations of Macintosh Computers. AppleScript is ideal because:
Before an installation/configuration script can be useful, we need to prepare a System and Application suite to install. In order to provide a standardised user experience across a multitude of machines, a Golden System is created. The ability to create a Universal System Folder is essential in creating a Golden System (try doing this with Win95 or NT). This universal System is updated and configured to contain all extensions, preferences, fonts etc, required by The golden system approach provides the additional advantage of a 'plug and play' environment. If a zip drive or scanner is added or moved to a machine the software required for this hardware is already configured. (additional time is saved, and kudos gained, by pre-empting user demands. I have received dozens of telephone calls along the lines "I want to add a zip drive to my Mac. What software do I need to install?" "The software required to support a zip drive has already been installed on your Mac" or "I need Photoshop installed Once a Golden System and Golden Application Suite have been created, the next step is to install these on a machine, then configure the machine correctly. Previously this copy and configuration was a manual process involving starting The amount of time waiting and the number of steps required by the administrator are dramatically reduced by using AppleScripts to automate these tasks (not to mention the room for error is dramatically reduced). A combination of Boot floppies (where applicable), bootable CD-Rs, and a network fileserver have been created to automate the copy and installation process (Apple's latest release of G3 hardware with internal IDE drives have thrown this process into a twirl. Hopefully Adaptec will have a version of Toast available soon that can create a bootable CD-R for Apple's Internal IDE CR-ROMs). All the administrator has to do is walk up to a machine and insert a CD or floppy, or mount a network volume, run a script and come back when the The script I use to install the software on the local machine is as follows -------------------------------------------------------------------------------------------------------------------- ---- ---- Script to copy and Install a labmac ---- Simplified due to Office 98 ---- ---- Andrew Winter (andy@arch.usyd.edu.au) ---- Faculty of Architecture, University of Sydney ---- ---- Cheaned up 15/4/98. Should run from locked disks. ---- Should work if you didnt boot from Workspace -------------------------------------------------------------------------------------------------------------------- tell application "Finder" activate ---- Turn filesharing off if (file sharing) is not false then set file sharing to false end if ---- Set the name of HD to "Workspace" if disk "Workspace" exists then else try set name of startup disk to "Workspace" on error display dialog "I cant find the HD. Name HD 'Workspace' and try again" buttons "Yessir" return end try end if ---- empty trash set locked of every file of the trash's entire contents to false if the trash is not (empty) then with timeout of 36000 seconds try empty trash without warning on error display dialog "I cant emtpy the trash. Please do it for me" buttons "Consider it done" return end try end timeout end if ---- delete files from the desktop select startup disk try make new alias file to selection at desktop select every file of container window of desktop delete selection on error end try ---- Check for enough HD space and warn user to intervene if necessary if (the (free space of disk "Workspace") / 1024 / 1024) is less than 500 then ----- Drag Applications, Additional Applications, and Communications to trash and empty if folder "Applications" of disk "Workspace" exists then delete folder "Applications" of disk "Workspace" if folder "Additional Applications" of disk "Workspace" exists then delete folder "Additional Applications" of disk "Workspace" if folder "Communications" of disk "Workspace" exists then delete folder "Communications" set locked of every file of the trash's entire contents to false if the trash is not (empty) then with timeout of 36000 seconds try empty trash without warning on error display dialog "I cant emtpy the trash. Please do it for me" buttons "Consider it done" return end try end timeout end if ---- Check again if (the (free space of disk "Workspace") / 1024 / 1024) is less than 500 then display dialog "This script requires 500mb of free HD space. Manually clear HD and run again" buttons "bummer" return end if end if ---- Drag all from HD to new folder called "To Trash" if folder "To Trash" of folder "desktop" exists then else make new folder at desktop with properties {name:"To Trash"} end if select every item of container window of startup disk move selection to folder "To Trash" replacing yes ---- If existing Data folder, move back if folder "Temporarilty" of folder "To Trash" of folder "desktop" exists then else make new folder at folder "To Trash" with properties {name:"Temporarilty"} end if select folder "Temporarilty" of folder "To Trash" if folder "data" of folder "To Trash" of folder "desktop" exists then select folder "data" of folder "To Trash" of folder "desktop" move selection to disk "Workspace" end if ---- Copy from Install Server if disk "Network Installers" exists then else MountVolume Volume "Network Installers" Server "Network Installers" Zone ¬ "Arch Students" Username "network" Password "install" end if with timeout of 36000 seconds select every item of container window of folder "Build" of disk "Network Installers" copy selection to disk "Workspace" end timeout ---- Install Configure Script in Startup Items select file "Configure Lab Mac" of folder "Scripts" of disk "Network Installers" duplicate selection to folder "Startup Items" of folder "System 8.1" of disk "Workspace" ---- Restart with New System activate select folder "System 8.1" of disk "Workspace" open selection using file "System Picker" of folder "System 8.1" of disk "Workspace" end tell
The above script looks for a hard disk called "Workspace". If it cannot find Workspace it attempts to name the startup disk "Workspace". If this is successful it then deletes everything from Workspace, except for the data folder, and copies Applications and System from a disk called "Network Installers". If this disk cannot be found it mounts the relevant network volume first. Upon completion of the copy the script installs a configuration script in the startup folder, and restarts the machine with the recently copied System. The Script installed and run on restart, Configure Lab Mac, is; -------------------------------------------------------------------------------------------------------------------- ---- ---- Script to configure a lab or staff machine ---- Simplified due to Office 98 ---- ---- Andrew Winter (andy@arch.usyd.edu.au) ---- Faculty of Architecture, University of Sydney -------------------------------------------------------------------------------------------------------------------- tell application "Finder" activate ---- Set name of HD to Workspace if not already with timeout of 36000 seconds ---- Set username and machine name to temp set owner name to "temp" & the (time of the (current date)) set computer name to "temp" & the (time of the (current date)) ---- Turn filesharing off repeat while sharing starting up -- a waiting loop until file sharing has been completed end repeat if (file sharing) is not false then set file sharing to false end if ---- Rename HD to "Workspace" if the name of startup disk is "Workspace" then else set name of startup disk to "Workspace" end if ---- Create Data and Additional Applications folders if folder "Data" of startup disk exists then else make folder at startup disk with properties {name:"Data"} end if if folder "Additional Applications" of startup disk exists then else make folder at startup disk with properties {name:"Additional Applications"} end if ---- Make aliases for Simpletext+, Acrobat, Printmonitor, Virex, Iomega Tools ---- Changed to overwrite existing aliases 10/2/98 if folder "Utilities" of folder "Applications" of startup disk exists then else make folder at folder "applications" of startup disk with properties {name:"Utilities"} end if if file "Workspace:Applications:Utilities:SimpleText+" exists then delete file "Workspace:Applications:Utilities:SimpleText+" end if if file "SimpleText+" of folder "Apple Menu Items" of system folder of startup disk exists then delete file "SimpleText+" of folder "Apple Menu Items" of system folder of startup disk end if select file "SimpleText+" of system folder of startup disk make new alias file to selection at folder "Utilities" of folder "Applications" of startup disk make new alias file to selection at folder "Apple Menu Items" of system folder of startup disk ---- Other aliases removed from this example for brevity (repeat the above code for other end timeout with timeout of 36000 seconds ---- Get information RE name of the machine display dialog "Lab or Staff Machine?" buttons {"Lab", "Staff"} default button ¬ "Staff" with icon caution set Aowner to the (button returned of the result) if Aowner = "Staff" then ---- Get Staff Info display dialog "Enter Owner name" default answer "LabMac" buttons "ok" default button ¬ "ok" with icon caution set Auser to the (text returned of the result) display dialog "Which Staff Group?" buttons {"Faculty", "DADS", "None"} default button "None" with icon caution set Agroup to the (button returned of the result) if Agroup is "None" then set Agroup to "" end if display dialog "Enter Machine ID" default answer "H001" buttons "ok" default button ¬ "ok" with icon caution set Aid to the (text returned of the result) display dialog "Enter Machine Type" default answer "G3" buttons "ok" default button ¬ "ok" with icon caution set Atype to the (text returned of the result) display dialog "Enter Macintosh name" default answer Auser & "'s " & Atype & " [" & Aid & ¬ "] - Rm292" buttons "ok" default button "ok" with icon caution set Amac to the (text returned of the result) ---- Staff get Aliases on the Desktop (Apple Menu Items, Startup Items) ---- Changed to delete existing aliases 10/2/98 if file "Apple Menu Items" of folder "desktop" exists then delete file "Apple Menu Items" of folder "desktop" end if select folder "Apple Menu Items" of system folder of startup disk make new alias file to selection at desktop if file "Startup Items" of folder "desktop" exists then delete file "Startup Items" of folder "desktop" end if select folder "Startup Items" of system folder of startup disk make new alias file to selection at desktop select file "Apple Menu Items" of desktop set position of selection to {38, 545} select file "Startup Items" of desktop set position of selection to {131, 545} else ---- Get Lab Info display dialog "Enter Machine ID" default answer "H001" buttons "ok" default button ¬ "ok" with icon caution set Aid to the (text returned of the result) display dialog "Enter Machine Type" default answer "G3" buttons "ok" default button ¬ "ok" with icon caution set Atype to the (text returned of the result) display dialog "Enter Macintosh name" default answer Atype & " [" & Aid & ¬ "] - Rm292" buttons "ok" default button "ok" with icon caution set Amac to the (text returned of the result) set Auser to Atype set Agroup to "" end if end timeout ---- Wait until filesharing is on so it doesnt bomb if filesharing is not ready repeat while sharing starting up -- a waiting loop until file sharing has been completed end repeat if (file sharing) is not true then set file sharing to true end if repeat while sharing starting up -- a waiting loop until file sharing has been completed end repeat ---- Set up the File Sharing Info if (owner name) = Aid then else set owner name to Aid end if if (computer name) = Amac then else set computer name to Amac end if ---- Set up a User in Users and Groups tell application "Users & Groups" ---- Check for existing user set the_user_list to users as list set the_name_list to {} repeat with this_user in the_user_list set the end of the_name_list to the name of this_user end repeat if Auser is in the_name_list then ---- if the user exists then do nothing else ---- create new user set the_new_user to make new user set name of the_new_user to Auser end if set can connect of user Auser to true set can change password of user Auser to true set can do program linking of user Auser to false quit end tell ---- Set up a "group" in Users and Groups if Agroup = "" then else tell application "Users & Groups" ---- Check for existing user set the_user_list to users as list set the_name_list to {} repeat with this_user in the_user_list set the end of the_name_list to the name of this_user end repeat if Agroup is in the_name_list then ---- If the user exists then do nothing else ---- create new user set the_new_user to make new user set name of the_new_user to Agroup set can connect of user Agroup to true set can change password of user Agroup to false set can do program linking of user Agroup to false end if quit end tell end if ---- Set Password for the User + "Group" Just Created - Using Quinn's Addition if Agroup = "" then set user info name Auser password Auser with dangerous hack if Aowner is "Lab" then tell application "Users & Groups" set can change password of user Auser to false quit end tell end if else if Agroup = "DADS" then set user info name Auser password Auser with dangerous hack set user info name Agroup password "staff" with dangerous hack else set user info name Auser password Auser with dangerous hack set user info name Agroup password "faculty" with dangerous hack end if end if ---- Lock down administrator account tell application "Users & Groups" set can change password of user Aid to false quit end tell set user info name Aid password "admin" with dangerous hack ---- Share the data folder for the above user ---- Due to a bug in AppleScript you cant set both owner and group without closing window open sharing window of folder "Workspace:Data" if the shared of folder "Data" of startup disk is false then set shared of folder "Data" set owner of folder "Workspace:Data" to Auser close sharing window of folder "Workspace:Data" open sharing window of folder "Workspace:Data" set group of folder "Workspace:Data" to Agroup close sharing window of folder "Workspace:Data" ---- set all privs in case Data folder already existed set the see folders of group privileges of folder "workspace:Data" to true set the see files of group privileges of folder "workspace:Data" to true set the make changes of group privileges of folder "workspace:Data" to true set the see folders of owner privileges of folder "workspace:Data" to true set the see files of owner privileges of folder "workspace:Data" to true set the make changes of owner privileges of folder "workspace:Data" to true set the see folders of guest privileges of folder "workspace:Data" to false set the see files of guest privileges of folder "workspace:Data" to false set the make changes of guest privileges of folder "workspace:Data" to false ---- Mount "Arch Services" Volume if disk "Network Installers" exists then else MountVolume Volume "Network Installers" Server "Network Installers" Zone ¬ "Arch Services" Username "network" Password "install" end if ---- Trash existing startup items (including this one) if folder "To Trash" of folder "desktop" exists then else make new folder at desktop with properties {name:"To Trash"} end if make new folder at folder "Startup Items" of system folder of startup disk select every item of container window of folder "Startup Items" of system folder of startup disk move selection to folder "To Trash" replacing yes -- Install AntiWorm Software select every item of container window of folder "Startup" of folder "Post Install" of disk "Network Installers" duplicate selection to folder "Startup Items" of system folder of startup disk replacing yes -- Clean Up root level of HD select folder "System 8.1" of startup disk set position of selection to {1, 0} select folder "Applications" of startup disk set position of selection to {1, 64} select folder "Data" of startup disk set position of selection to {129, 0} select folder "Communications" of startup disk set position of selection to {129, 64} select folder "Additional Applications" of startup disk set position of selection to {257, 64} select startup disk open selection set size of container window of startup disk to {371, 160} set position of container window of startup disk to {18, 51} ---- Open AppleTalk / TCP/IP and Chooser to correctly configure ---- (since we cannot script the correct configuration) select file "AppleTalk" of folder "Control Panels" of system folder of startup disk open selection select file "TCP/IP" of folder "Control Panels" of system folder of startup disk open selection select file "Chooser" of folder "Apple Menu Items" of system folder of startup disk open selection ---- empty trash try set locked of every file of the trash's entire contents to false on error return end try if the trash is not (empty) then with timeout of 36000 seconds try empty trash without warning on error return end try end timeout end if ---- Trash everything in Trash (and "To Trash") with timeout of 36000 seconds if folder "To Trash" of folder "desktop" exists then delete folder "To Trash" of folder "desktop" end if try set locked of every file of the trash's entire contents to false on error return end try if the trash is not (empty) then try --set locked of every file of the trash's entire contents to false empty trash without warning on error return end try end if end timeout ----- Display a dialog box saying configration complete with timeout of 36000 seconds display dialog "Configuration complete" buttons {"Quit", "Restart"} default button ¬ "Restart" with icon caution if the (button returned of the result) is "Restart" then restart end timeout end tell
This script creates necessary aliases, prompts the administrator for localised (staff or lab machine, owner, location etc) and sets up filesharing based on this information. It then cleans the root level of the hard disk, installs permanent startup items, deletes all unwanted items (including itself) and runs non scriptable applications for manual configuration (such as printers, AppleTalk zones, TCP/IP configuration). A similar script (for when Office 98 cannot be installed) runs the MS Office 4.2 installer for manual installation, and installs an Office Cleanup script to tidy the Office 4.2 install. (Why is the Microsoft folder not placed in the Microsoft Office folder automatically?) In addition to the standard AppleScript shipping with MacOS, I use the following freeware tools; SystemPicker (available from info-mac archives) which allows me to drag and drop a system folder to be active and restarts the machine. Quinn's filesharing AppleScript extension (OSAX) to allow me to After using an AppleScript solution to rebuild lab machines, the next stage The simple AppleScripts I created to install and configure machines have My heartfelt thanks go out to Microsoft for following the standards for Macintosh Applications with Office 98. Office 4.2 is the only application that I have discovered for the Mac that had to be installed from its installer instead of drag copying. Office is also the only application that had to be reinstalled from scratch if you replaced the Operating System, or even renamed the Hard Disk. (The Office 4.2 installer is not AppleScriptable). Scripting is addictive. The more you create the more opportunities you see within your day to day activities to script. The more you script the more you become frustrated by limitations and bugs in AppleScript, and create clever solutions to get around these limitations and bugs. The more you script the more you look for adding additional functions to AppleScript (ie I want to be able to select a printer. I want to change PRAM settings... I want I want I want......). Most of the additional functionality I have wished to add to AppleScript are available as OSAX's from scriptworld. Scripting is also frustrating. There are a number of features that don't exist So what's next? I was hoping to have a developers' release of 8.5 before the conference in order to test and play with the new AppleScript features scheduled for release, but was unable to obtain a copy from Apple Australia. Additional features scheduled for 8.5 include a completely scriptable Open Transport. This will allow further automation of my scripting tools. For example if OT can return the ethernet card address of a machine, a look up table can be created so the script can find out what kind of machine it is to install (laboratory, staff, or lecture theatre). The next logical step would be to automatically add entries to the lookup table if they do not exist so the next time the machine is rebuilt it will be done so automatically (with even fewer human errors). Further directions I wish to develope my scripting tools are to check for newer versions of applications on a network volume and update automatically if the user agrees, copying user configurations from an existing system to be updated to a newer version (ie Bookmarks, filesharing information, fonts, 'safe' control panels and extensions) and salvaging such user configurations from a corrupt system folder. Future ambitions include a web based solution to allow users to download AppleScripts to their local machine which will perform such functions as removing an existing installation of Office 4.2 (grrr) and replacing it with a custom installation of Office 98, to correctly configure Eudora for a user, and to check for updated virus definitions and update automatically. |
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||