Mounting SMB from command line and installing packages from a folder

I am working on making a script that will mount a smb share off a server, copy all the packages out of a folder to the laptop, then install these packages.

There are two parts I need help with.

The first, This is going to be used at many different locations. The ip address formula is the same at all locations so rather then make a bunch of different scripts i wanted to get the ip address of the computer and using that to mount the share.

The address of the computer and the share have a formula. 124.30.location number.computer number

the first two ip octet are always the same for both the server and the laptop. so lets say that is 124.30.

the third octet varies by location, but is the same on both the server and the laptop at that location. so if you get the ip address of the laptop you cat get the first three octets of the server address.

The server always has the same computer number at every location 124.30.location.40

So using this info and what I have created below, it should be abled to be modified to work.

The second thing i need help with is, rather then list out each package to install, is there a way to read the packages in the folder once it is copied over and install them based on that?

#!/bin/sh

ifconfig en0 | grep 124.30.?.135

mkdir /Volumes/MacUpdates
mount_smbfs //User:password@124.30.?.40/MacUpdates /Volumes/MacUpdates

mkdir /Users/Shared/MacUpdates

cp /Volumes/MacUpdates/* /Users/Shared/MacUpdates/

sudo installer -pkg /Users/Shared/MacUpdates/Java1.4.1.pkg -target /

For the server address it’s quite simple


set myip to do shell script "ifconfig en0 | grep 'inet ' | awk '{print $2}'"

set AppleScript's text item delimiters to "."
set serverAddress to text items 1 thru 3 of myip & "40" as string
set AppleScript's text item delimiters to ""
return serverAddress

I assumed this was your biggest struggle. The rest of your script can be used the way you typed it.

so to pass the resulting serverAddress to mount the share, can the smb share be mounted via apple script?

I know how to do it from the command line but not via apple script.

Rich

Just as you typed

set myip to do shell script "ifconfig en0 | grep 'inet ' | awk '{print $2}'"

set AppleScript's text item delimiters to "."
set serverAddress to text items 1 thru 3 of myip & "40" as string
set AppleScript's text item delimiters to ""
do shell script "mkdir /Volumes/MacUpdates"
do shell script "mount_smbfs //User:password@" & serverAddress & "/MacUpdates /Volumes/MacUpdates"