PDA

View Full Version : Help with basic (I think) Shell script.


trevo
2011-06-10, 10:36
Hi Applenova, it's been a while.

I've been customising 13 iMac's Guest accounts through Terminal. It's time consuming. I realised that I should probably look into Shell scripts. It's not really going well.

If anyone would like to give me a hand, I'd even be happy to donate a few dollars for the help.

Here's what I have to run:

Guest$ su administrator
Password: 1234

bash-3.2$ sudo -s
Password: 1234

$ cd /System/Library
$ tar cfz UserTemplateBackup.tar.gz "User Template"

$ cd /Users/Guest
$ cp .DS_Store "/System/Library/User Template/English.lproj/.DS_Store"

$ rm -R "/System/Library/User Template/English.lproj/Pictures"/
$ cp -R Pictures/ "/System/Library/User Template/English.lproj/Pictures"/


$ rm -R "/System/Library/User Template/English.lproj/Desktop"/
$ cp -R Pictures/ "/System/Library/User Template/English.lproj/Desktop"/

$ rm -R "/System/Library/User Template/English.lproj/Library"/
$ cp -R Library/ "/System/Library/User Template/English.lproj/Library"/

Restart.

Brad
2011-06-10, 11:47
A shell script is really just a pile of commands that you would normally execute one by one on the shell. So, you could literally just take your list of commands, stick them in a file, and be done (mostly).

I'm on an iPhone now, but I'll take another look at this thread this evening from a Real Computer and post a sample script based on what you have there.

chucker
2011-06-10, 12:00
What Brad said. Essentially, this should work:

#!/bin/bash

su administrator
sudo -s

cd /System/Library
tar cfz UserTemplateBackup.tar.gz "User Template"

cd /Users/Guest
cp .DS_Store "/System/Library/User Template/English.lproj/.DS_Store"

rm -R "/System/Library/User Template/English.lproj/Pictures"/
cp -R Pictures/ "/System/Library/User Template/English.lproj/Pictures"/

rm -R "/System/Library/User Template/English.lproj/Desktop"/
cp -R Pictures/ "/System/Library/User Template/English.lproj/Desktop"/

rm -R "/System/Library/User Template/English.lproj/Library"/
cp -R Library/ "/System/Library/User Template/English.lproj/Library"/

You can save it as myScript.command to have it double-clickable in Finder. Note that, due to the first two commands, you'll be prompted for a password, twice.

trevo
2011-06-10, 23:20
Ha! I can't believe it's that easy. Thank you so much.

Security is not a big deal in this case so I've googled about including passwords in the script. It looks like I have 2 choices?

1. chmod 4711 on the file, then chown to root. This sounds good would it work?
2. allow sudo access without a password.

And to restart, is this all I need for it to work?

tell app Finder
restart
end tell

edit: just found this:
/sbin/shutdown -r now