(********************************************* * Personal Installation of BOINC on MacOS X * * Eric Myers - 8 January 2005 * @(#) $Id: Install_BOINC.applescript,v 1.3 2005/02/13 21:19:48 myers Exp $ *********************************************) -- *********** Global Variables *********************** global previous_boinc_existed, boinc_folder, boinc_backup_folder, user_library global run_boinc, stop_boinc global BOINC_version set BOINC_version to "4.19" -- *********** BEGIN: if not Show_Introduction() then quit Show_License() stop_running_BOINC() set previous_boinc_existed to Prepare_BOINC_folder() Copy_BOINC_to_Library() if previous_boinc_existed then Preserve_Project_Info() else Setup_Account_Info() end if Remove_Backup_Copy() set run_boinc to boinc_folder & ":Run_BOINC.term" Run_BOINC_at_Login() Run_BOINC_Now() -- *********** END: -- ********** Function (Handler) definitions *********** -- Show_Introduction just tells the user what this thing is going -- to do and gives them the opportunity to cancel out on Show_Introduction() set q to display dialog "BOINC " & BOINC_version & " Installation Berkeley Open Infrastructure for Network Computing (BOINC!) This will add a 'Personal' installation of BOINC version " & BOINC_version & " to your account on this computer, and optionally arrange to automatically start BOINC whenever you login. Shall we proceede? " buttons {"Cancel", "Continue..."} default button  "Continue..." giving up after 300 if (gave up of q is true) or (button returned of q is "Cancel") then return false else return true end if end Show_Introduction -- Show the License and proceede only if user has accepted it -- (this will display a file later on...) on Show_License() set license_accepted to false repeat until license_accepted = true set q to display dialog "Software License Use of this software is governed by the GNU Lesser Public License (LGPL). Press 'View' if you wish to view the license. Do you accept the terms of this license? " buttons {"View", "Decline", "Accept"} default button  "Accept" giving up after 300 with icon note if (button returned of q) is "View" then set src_BOINC_folder to "Install_BOINC:BOINC" set license_file to src_BOINC_folder & ":LGPL.txt" as alias tell application "Finder" activate open license_file end tell -- display dialog "(Show LGPL here)" end if if (button returned of q is "Decline") then quit if (button returned of q is "Accept") then set license_accepted to true return end if end repeat end Show_License ---------------------------------------------------------- -- Stop any BOINC that is running now on stop_running_BOINC() -- what follows doesn not yet work, but will be better --set src_BOINC_folder to container of (path to me) as alias --display dialog "path to me is " & src_BOINC_folder set src_BOINC_folder to "Install_BOINC:BOINC" set stop_boinc to POSIX path of src_BOINC_folder & "/stop-boinc.sh" display dialog "Stopping any running BOINC " buttons "Cancel" with icon stop giving up after 1 do shell script stop_boinc end stop_running_BOINC ----------------------------------------------------------- -- Prepare_BOINC_folder primarily looks for an old BOINC installation -- and saves it if the user wishes to preserves it to extract account info on Prepare_BOINC_folder() set user_library to ((path to home folder) as string) & "Library" set boinc_folder to ((path to home folder) as string) & "Library:BOINC" set boinc_backup_folder to ((path to home folder) as string) &  "Library:BOINC-backup" set previous_boinc_existed to Save_old_BOINC_folder(boinc_folder) return previous_boinc_existed end Prepare_BOINC_folder on Save_old_BOINC_folder(the_folder) tell application "Finder" set folder_exists to exists of folder the_folder end tell if folder_exists then set q to display dialog "A previous installation of BOINC was found in the folder " & boinc_folder & " We can either save previous account information or clear it and make a fresh start of things. What should we do? " buttons {"Cancel", "Reset", "Save"} default button "Save" giving up after 300 with icon caution if (gave up of q is true) or (button returned of q is "Cancel") then quit if (button returned of q is "Reset") then -- delete the old BOINC folder (moves it to the trash) tell application "Finder" delete folder the_folder end tell set folder_exists to false else -- rename the old BOINC folder, we will use it later tell application "Finder" if exists of folder boinc_backup_folder then delete folder boinc_backup_folder set q to get folder boinc_folder set name of q to "BOINC-backup" end tell end if end if return folder_exists end Save_old_BOINC_folder ----------------------------------------------------------- -- Copy the BOINC folder from the source folder to the -- user's Library folder on Copy_BOINC_to_Library() -- need a better way to find this set src_BOINC_folder to "Install_BOINC:BOINC" set user_library to ((path to home folder) as string) & "Library" display dialog "Copying BOINC folder to Library..." with icon note buttons "Cancel" giving up after 1 tell application "Finder" duplicate folder src_BOINC_folder to folder user_library replacing yes end tell end Copy_BOINC_to_Library -------------------------------------------------------- -- Copy any account_*xml files and the projects folder -- to the new BOINC folder from the previous folder on Preserve_Project_Info() tell application "Finder" set a_list to files of folder boinc_backup_folder whose name starts with "account_" repeat with f in a_list copy f to folder boinc_folder end repeat set p_list to folder "projects" of folder boinc_backup_folder copy p_list to folder boinc_folder end tell end Preserve_Project_Info ------------------------------------------------------------- -- Setup_Account_Info() gets Project URL and Account Key and writes -- these to an account_URL.xml file on Setup_Account_Info() -- Get Project URL set got_account to false repeat while got_account is false -- ask user for Project URL and account key display dialog "BOINC 4.13: account setup When you created your project account you should have received an e-mail containing both the project URL and Account Key. Please enter here the project URL (without the \"http://\"). Enter Project URL: http://" default answer "pirates.vassar.edu" set project_url to text returned of result -- need here to clean up the url: -- remove trailing spaces and trailing / -- remove leading http:// part set got_account to true end repeat -- Get Project Account Key set got_key to false set key_msg to "You should have received an Account Key for the project via e-mail when your account was created. " repeat while got_key is false display dialog "Project Account Key: " & key_msg & " Please enter your Account Key here: " default answer "" with icon note set account_key to text returned of result -- need here to verify that the account key has the right form -- hex digits only, and the right number of them set got_key to true end repeat -- Write an account.xml file for this account set xml_doc to " http://" & project_url & "/ " & account_key & " " set filename to boinc_folder & ":account_" & project_url & ".xml" set file_ref to open for access file filename with write permission write xml_doc to file_ref close access file_ref end Setup_Account_Info -------------------------------------------------------------- -- Remove_Backup_Copy() removes a previously installed BOINC folder -- if one exists on Remove_Backup_Copy() tell application "Finder" if exists of folder boinc_backup_folder then delete folder boinc_backup_folder end if end tell end Remove_Backup_Copy --------------------------------------------------- -- Ask user if BOINC should start at login, and if they agree -- then arrange for that to happen on Run_BOINC_at_Login() -- Do not run at login unless the user specifically agrees, so first -- be sure to remove any startup items that might already be there tell application "System Events" get every login item repeat with q in every login item set q_name to name of q if q_name is equal to "Run_BOINC" then -- display dialog "Previous startup item found. delete it?" delete login item q_name end if end repeat end tell -- add to user's Startup Items if user agrees set q to display dialog "Login Startup: Do you want BOINC to start automatically whenever you log in? " buttons {"Cancel", "No", "Yes"} default button "Yes" giving up after 300 if button returned of q is "Yes" then tell application "Finder" set app_link to get run_boinc end tell set app_name to "Run_BOINC" set app_POSIX_path to POSIX path of app_link tell application "System Events" make new login item at end with properties  {name:app_name, kind:"APPLICATION", path:app_POSIX_path, hidden:false} end tell end if end Run_BOINC_at_Login ----------------------------------------------------------------- -- Fire up BOINC now if user agrees on Run_BOINC_Now() set q to display dialog "Run BOINC now? Do you want to start BOINC now? " buttons {"Cancel", "No", "Yes"} default button "Yes" giving up after 300 if button returned of q is "Yes" then tell application "Finder" set f to file run_boinc open f end tell end if end Run_BOINC_Now --EOF