Creating a script (like a windows batch file)

Joined
Jan 15, 2012
Messages
2
Reaction score
0
Points
1
Hi all,

I reinstall alot of Macs in my job - then fully update those systems and then 'reseal' the units so the user gets the machine at the start of the 'out of box' experience.

I use two ways to remove the user account and 'reseal' the OS :
Both times the username is set to user*

Boot to terminal:
fsck -fy
mount -uw /
rm /var/db/.applesetupdone
cd /users
rm -rf user
reboot

OR

Boot to terminal:
mount -uw /
rm -R /Users/user
rm /var/db/dslocal/nodes/Default/users/user.plist
rm /var/db/.applesetupdone


My question is -

Can either of these 'scripts' be put onto a pen drive - THEN when i boot to terminal - mount the pendrive and "execute" either 'script' to save me typing it out all the time -

Thanks in advance for any response - and if the above makes no sense at all please let me know and i'll try and write it out better as solving this would really help me out.

thanks again.\\

Ed/
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Making shell scripts (*nix equivalent of batch files) is very much like batch files (at its most basic). Simply put the commands one after the other into a plain text file, save it and make it executable (chmod +x <script name>).

Note - it has to be plain text. I mention this because apps like TextEdit default to rich text which will add a bunch of text to your script which will screw it up.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Sure.. it's good practice to shebang the scripts though.

That is...

Code:
#!/bin/bash
fsck -fy
mount -uw /
rm /var/db/.applesetupdone
cd /users
rm -rf user
reboot   #does this need to be done with elevated permissions?  If so, toss in sudo

It would be easy, at this point to establish what user by simply doing something like...

Code:
#!/bin/bash
if [ $# -ne 1 ] ; then 
	echo "Usage: $0 username"
	exit
fi

fsck -fy
mount -uw /
rm /var/db/.applesetupdone
rm -rf /users/$1
reboot   #does this need to be done with elevated permissions?  If so, toss in sudo
 
OP
L
Joined
Jan 15, 2012
Messages
2
Reaction score
0
Points
1
Hi -

thanks for both responses - i'm a nOOB with all this but i'll give it a go and get back to you...

thanks.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top