View Full Version : Help needed - shell script to boot up from source drive after copy completes

05-25-2006, 09:30 PM
I have an iMac G5 (iSight), running 10.4.5, with the latest 2.1.1 SuperDuper and I have two external drives named "A" and "B".

When I use Super Duper, I boot from the "A" disk, and copy the iMac disk to B.

After the copy completes, I'd like to automatically select the iMac disk as the Startup volume, and then reboot.

It looks like there's a way to execute a shell script after Super Duper completes, but I have no ideea how to write shell commands to set the startup disk to Imac, and restart.

Any ideas?

05-25-2006, 09:48 PM
This isn't a really easy thing to do, but given fixed paths, you could do something like:

#! /bin/sh
if [ -a /Volumes/A/System/Library/CoreServices/BootX ]; then
UCHGSET=$(ls -lo /Volumes/A/System/Library/CoreServices/BootX | grep -vqF uchg; echo $?);
chflags nouchg /Volumes/A/System/Library/CoreServices/BootX;
bless -folder /Volumes/A/System/Library/CoreServices -save9 -label A -setBoot;

if [ $UCHGSET -eq 1 ]; then
chflags uchg /Volumes/A/System/Library/CoreServices/BootX;

echo "Successfully set A as startup disk";
echo "Could not set A as the startup disk because it does not contain a valid Mac OS X System Folder.";
exit 1;

nohup /bin/bash -c "sleep 10; /Applications/SuperDuper!.app/Contents/Resources/Scripts/restart.scpt"&

05-27-2006, 12:15 AM
Thanks for the shell script. The line...

chflags nouchg /Volumes/A/System/Library/CoreServices/BootX;

gave permissions problems for me when I tried executing that script.

What ended up working, though was the following Applescript, which is called by a shell script, which is called by Super Duper

The Applescript:

tell application "Finder" to exists disk "iMac"

--change the boot volume and restart if the result is true

if the result then do shell script "/usr/sbin/bless -folder '/Volumes/iMac/System/Library/CoreServices' -setOF;/sbin/shutdown -r now" password "admin_password" with administrator privileges --put your admin password in for "admin_password", otherwise it will use a pop up dialog to ask the password.

And the shell script that calls it:

#! /bin/sh

osascript /Volumes/A010/Users/jaimev/Documents/boot-from-Imac-app.app

05-27-2006, 08:22 AM
Um, I wouldn't do that, actually -- shutdown is a pretty severe way of restarting the system!

Instead, you'll find the script I provided *will* work if you run it authenticated (sudo), as SuperDuper does.