-1

For my testing purposes I have to do installs of macOS on a lot of different machines. I've been hardcoding the desired install volume into my start up script. But I'd love to set the volume path to a variable. I get Error:

could not find target.

while attempting to run the script - some irrelevant parts have been omitted.

#!/bin/bash

Boot= diskutil info / | grep "Volume Name:" | awk '{print $3}'
echo $Boot
./startosinstall --volume /Volumes/$Boot --agreetolicense --rebootdelay 200
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137

2 Answers2

0

There are several problems with how you're getting and using the volume name, but before I get to them: why do you need it at all? I haven't used it, but my understanding is that startosinstall defaults to installing onto the current startup volume, so you can just leave the --volume option off:

./startosinstall --agreetolicense --rebootdelay 200

Now, if you actually do need the startup volume name, here's what needs fixing:

  • To capture the output of a command in a variable, you need to use var=$(command). You're missing the $( ), and there cannot be a space after the = (or before it either). (BTW, there's a version that uses backquotes instead of $( ), but it's messier in a couple of ways, so don't use it.)

  • The command diskutil info / | grep "Volume Name:" | awk '{print $3}' will print the first word of the startup volume's name. For example, if the volume is named "Macintosh HD", the output of the diskutil | grep part is "Volume Name: Macintosh HD", and awk will print the third word of that, which is "Macintosh". Fixing this is messier; the simplest way that occurs to me is to use sed instead of grep and awk:

    Boot=$(diskutil info / | sed -n 's/^   Volume Name:              //p')
    
  • Finally, when you use the Boot variable, you need to put double-quotes around it to keep it from being split into multiple "words":

    echo "$Boot"
    ./startosinstall --volume "/Volumes/$Boot" --agreetolicense --rebootdelay 200
    

BTW, shellcheck.net is good at catching common mistakes; I'd strongly recommend running your scripts through it.

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
0

I've managed many macs, there is an apple tool called "Server" [ https://www.apple.com/macos/server/ ] that contains the tools to both create images and a server that can customise those images while installing. While there is a bit of a learning curve, to automate the installation of a mac, it's pretty hard to beat for the cost apple asks for it ($29).

It also does a whole lot of other things as well, but just having the install server is well worth it if you're trying to automate these things. I used to have 2 install servers at different physical locations, just being able to (re-)install any mac anywhere.