0
votes

I have bash command that contains a variable to a file which updates the firmware for a specific hardware and give it a serial number.

#!/bin/bash
fpath=$(dirname "$0")

ee_image=mlr-2000119.bin

sudo nvram tbt-options=4

sudo /usr/sbin/bless -mount / -firmware "$fpath/ThorUtilDevice.efi" -payload "$fpath/$ee_image" -options "-o -ej 1 -blast efi-apple-payload0-data" 

sudo reboot now

I would like to create a file through automator or applescript that will create this same file but will automatically increase the ee_image bin file name by one. So that the end user doesn't always have to open the command file in text edit, make the change manually then save then execute the file..

Any help with this would be a God send.

2

2 Answers

0
votes

The last line in your script sudo reboot now would make any sort of loop meaningless.

However, if you insist, use may a loop:

#!/bin/bash
fpath=$(dirname "$0")

for i in {2000119..3000119}; do
  ee_image=mlr-${i}.bin
  sudo nvram tbt-options=4
  sudo /usr/sbin/bless -mount / -firmware "$fpath/ThorUtilDevice.efi" -payload "$fpath/$ee_image" -options "-o -ej 1 -blast efi-apple-payload0-data" 
  sudo reboot now
done

This would loop through mlr-2000119.bin to mlr-3000119. You can also consider passing an argument to the script in which case you can use your original script with the ee_image line as

  ee_image=mlr-$1.bin

and invoke bash /path/to/your/script.sh 2000119

0
votes

@devnull wrote:

The last line in your script sudo reboot now would make any sort of loop meaningless.

I believe that the reboot command is just like any other command. It should be echoed to a file rather than being run to generate the script for the end-user.

I think that a good idea would be to have a script that creates scripts.

This is similar to how many websites work. The script on the server can echo HTML, CSS, and JavaScript code for consumption by the web browser.

Here is an example:

#!/bin/bash

# set the path to the dir
dir=$(dirname $0)"/"

# set the path to the file that keeps track of the serial numbers
snFile="$dir""sn.txt"

# set the file name of the file to be generated
fileName="serialize"

# read the last serial number used
if [ -e "$snFile" ];
then
    read lastSN < "$snFile"
else
    lastSN="0"
fi

# increment the serial number
let "nextSN = $lastSN + 1"
echo "$nextSN" > "$snFile"

# create a path variable for the file being created.
generatedPath="$dir$fileName$nextSN.sh"

# generate the script
echo "#!/bin/bash" > "$generatedPath"
echo 'fpath=$(dirname "$0")' >> "$generatedPath"
echo '' >> "$generatedPath"
echo "ee_image=mlr-$nextSN.bin" >> "$generatedPath"
echo '' >> "$generatedPath"
echo 'sudo nvram tbt-options=4' >> "$generatedPath"
echo '' >> "$generatedPath"
echo 'sudo /usr/sbin/bless -mount / -firmware \"$fpath/ThorUtilDevice.efi\" -payload \"$fpath/$ee_image\" -options \"-o -ej 1 -blast efi-apple-payload0-data\" \' >> "$generatedPath"
echo '' >> "$generatedPath"
echo 'sudo reboot now' >> "$generatedPath"

# give the user some feedback
echo "generatedPath: $generatedPath"

If having your end-user run a bash script is good enough, then I think that you're almost done.

If you want to have an even better user interface and have a Mac application for the end-user to run, send me an email and I can help you with that.

[email protected]