The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   Networking (http://hintsforums.macworld.com/forumdisplay.php?f=14)
-   -   network setup script (http://hintsforums.macworld.com/showthread.php?t=81235)

tlarkin 06-04-2008 10:35 AM

The app is not modifying it, you are. Then you have two options, build the package as a pkd or as a dmg. Then deploy it. When you run it as admin it replaces the files with admin rights to whatever files you modified or created.

Just don't make the mistake I did, and keep the user level prefs in there. I once pushed out my dock settings to about 1200 laptops....the users emailed me like crazy, and all I could say was, my bad, but its just a pref just rebuild your dock!

Lesson learned the hard way LOL

astro666 06-04-2008 10:39 AM

Results...
 
Hmm... I didn't make it clear. After I took the snapshot, i removed all references to the wireless network - both in keychain access (from the sys keychain) and from the preferred network order.
Anyway, I will soon know about the system keychain and if it replaces or modifies it.

To get around the permissions issue the post-flight script i am running is a repair permissions, which takes time yes but solves the issues ;)

arbushell 06-08-2008 09:24 AM

Has anyone a clarifying answer to the thread starting issue as posted by tlarkin?
I'm having exactly the same problem on Leopard 10.5.3 and for me is mandatory to solve it using Applescript or terminal commands

tlarkin 06-08-2008 12:17 PM

Quote:

Originally Posted by arbushell (Post 475015)
Has anyone a clarifying answer to the thread starting issue as posted by tlarkin?
I'm having exactly the same problem on Leopard 10.5.3 and for me is mandatory to solve it using Applescript or terminal commands

In 10.5 there is a network setup command in bash. You can use it to build a script to change network settings. View the man pages of it and see what you can build.

look in

/usr/sbin/networksetup

astro666 06-08-2008 06:26 PM

Nup.
 
Quote:

Originally Posted by tlarkin (Post 475031)
In 10.5 there is a network setup command in bash. You can use it to build a script to change network settings. View the man pages of it and see what you can build.

look in

/usr/sbin/networksetup

The problem with this is it doesn't put it in your remebered network lists, nor does it store the Passkey in your system/login keychain, thus unless you get this script to run on every wake, reboot, and whenever the connection comes into range, its useless.

This is a big problem for us, so i'm going to ask the Apple Dev's at WWDC tomorrow :D

tlarkin 06-08-2008 09:37 PM

Quote:

Originally Posted by astro666 (Post 475098)
The problem with this is it doesn't put it in your remebered network lists, nor does it store the Passkey in your system/login keychain, thus unless you get this script to run on every wake, reboot, and whenever the connection comes into range, its useless.

This is a big problem for us, so i'm going to ask the Apple Dev's at WWDC tomorrow :D

Keep us posted what you find out. There are some command line apps that do set system preferences, but I just can't think of them at the moment.

arbushell 06-09-2008 02:28 AM

I'm not sure to have explained correctly my question: I have inconsistent results from the terminal command 'networksetup', exactly as stated in the following extract from the Apple discussion forum:
**************************
Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -getairportpower
AirPort Power: Off

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower on
You cannot set AirPort power because all AirPort network services are disabled.

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -getnetworkserviceenabled AirPort
Enabled

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setnetworkserviceenabled AirPort on

Loaner-2:~ tech$

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup-tiger -setairportpower on
You cannot set AirPort power because all AirPort network services are disabled.
*********************************

tlarkin 06-09-2008 08:43 AM

Quote:

Originally Posted by arbushell (Post 475156)
I'm not sure to have explained correctly my question: I have inconsistent results from the terminal command 'networksetup', exactly as stated in the following extract from the Apple discussion forum:
**************************
Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -getairportpower
AirPort Power: Off

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower on
You cannot set AirPort power because all AirPort network services are disabled.

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -getnetworkserviceenabled AirPort
Enabled

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setnetworkserviceenabled AirPort on

Loaner-2:~ tech$

Loaner-2:~ tech$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup-tiger -setairportpower on
You cannot set AirPort power because all AirPort network services are disabled.
*********************************

In 10.5 that binary moved to its own little place in /usr/sbin/networksetup

I have also had issues with powering on and off the airport via command line. It could just be a bug, because I never really got it to work all that well.

astro666 06-11-2008 02:26 PM

A way forward
 
tlarkin is right - binary's have moved as stated above. I've seen an issue with a MBA where the airport card becomes disabled because its loose, not soldered on properly or something - kinda sucks when thats the only NI you have!
Maybe ensure that you can still turn it on via the airport menu in the GUI, as if that doesn't work then time for a trip to your local store.

So i've asked the ENG team at Apple about how to roll out a 'new' wireless network to clients fully back-end. The major issue for us is that out system.keychain is corrupted, and the keychains are not something you can just replace - they are encrypted and have hardware hash's and if you try to simply replace them there will be tears before bedtime.
So, for us, there is a process.
1) image a mac with the same image your other users are using.
2) make the nessicary changes to the wireless
3) get the systempreferences.plist and airport.plist files from /Library/Preferences and ~/Library/Preferences (cant remmeber which one is which - maybe use some snapshot software to detect the changes - package maker is decent)
4) open keychain access and ensure that the entry for your wireless network is there.
5) open terminal, and type man security. This is where it gets tricky. You have to export the keychain item (wireless network password) in P12 format using the 'export' command
6) (for us only) - delete the system.keychain, logout then back in to generate a new one
7) copy over the preference files from before, and copy over the exported P12 file to somewhere on the users system
8) using the import switch from the security command, do an 'import' back into they system.keychain - ensuring you get the settings right.

I would be more specific but I haven't tested this myself, although the guy who helped build the Apple Keychain (hehe) swears black and blue that will work.

Mark

tlarkin 06-11-2008 02:34 PM

This is the 10.4 script I used to create different setting on different wifi networks. It has been over a year since I have used it, so I can't recall exactly how effective it was.

Code:

#!/bin/bash

#this script will set the WEP/WPA and preferred network for the laptop users by Tom Larkin

#Please note that if you are using 10.5 or higher, the network setup program has moved to the following:
#/usr/sbin/networksetup

#Insert your WEP and/or WPA passkey in the quotes

WEP="passkey"
WPA="passkey"

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setnetworkserviceenabled "AirPort" on
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower "on"
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportnetwork "SSID" $WEP

#PLEASE MAKE SURE you replace the SSID and the $WEP or $WPA with your own settings


astro666 06-11-2008 03:02 PM

Wont work
 
Quote:

Originally Posted by tlarkin (Post 475780)
This is the 10.4 script I used to create different setting on different wifi networks. It has been over a year since I have used it, so I can't recall exactly how effective it was.

Code:

#!/bin/bash

#this script will set the WEP/WPA and preferred network for the laptop users by Tom Larkin

#Please note that if you are using 10.5 or higher, the network setup program has moved to the following:
#/usr/sbin/networksetup

#Insert your WEP and/or WPA passkey in the quotes

WEP="passkey"
WPA="passkey"

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setnetworkserviceenabled "AirPort" on
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower "on"
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportnetwork "SSID" $WEP

#PLEASE MAKE SURE you replace the SSID and the $WEP or $WPA with your own settings



The problem with this script is that its a once off join - the networksetup command passes another command to the airportd, which means when you run the script and 'work as advertised', but it wont save the password of the wireless network, so unless you have this script running all the time and suppressing any error messages, its probably not very effective.

brlittle 06-17-2008 12:51 PM

Making it usable
 
Quote:

Originally Posted by astro666 (Post 475783)
The problem with this script is that its a once off join - the networksetup command passes another command to the airportd, which means when you run the script and 'work as advertised', but it wont save the password of the wireless network, so unless you have this script running all the time and suppressing any error messages, its probably not very effective.

I worked around this by wrapping all this stuff in an AppleScript and using the security command to write a keypair into the Keychain that stores the username and WEP shared secret. So long as the keypair is named correctly, it functions well, providing the required credentials after the user chooses the network from the Airport menu.

tlarkin 06-17-2008 01:15 PM

Quote:

Originally Posted by brlittle (Post 476942)
I worked around this by wrapping all this stuff in an AppleScript and using the security command to write a keypair into the Keychain that stores the username and WEP shared secret. So long as the keypair is named correctly, it functions well, providing the required credentials after the user chooses the network from the Airport menu.

Could you post an example? It would be appreciated greatly!

raymondlewisjone 06-17-2008 01:54 PM

osascript -e "'tell application 'finder'" -e "activate" -e "end tell"

I believe this is how you execute applescripts from within a shell

tlarkin 06-17-2008 02:12 PM

Quote:

Originally Posted by raymondlewisjone (Post 476953)
osascript -e "'tell application 'finder'" -e "activate" -e "end tell"

I believe this is how you execute applescripts from within a shell

I would like to see your whole script and the apple script so I could tinker with it, if that is not too much to ask.

brlittle 06-17-2008 05:13 PM

Hah!
 
Nothing good comes of posting too early in the testing phase.

Essentially, everything I had blew up in my face today. *However*, I have not given up, and will post here when I have something useful to post. Meaning "other than 'Ooo, lookie what I made work except that it doesn't really work after all!'"

:::grumble:::

Sorry about that, guys.

tlarkin 06-28-2008 05:01 PM

I found this

http://macosx.com/forums/howto-faqs/...mand-line.html

and

http://blog.simongregory.com/01/keyc...hellsh-script/

tlarkin 08-26-2008 01:21 PM

I got some information today that we may be migrating to WPA or something else so I was looking back into this, and I found this on google. It is an apple script, which I am not too keen on running in my environment since it runs in the gui with the user present, but I think it may be a good solution over all.

Code:

set CertName to "your.cert"
set WPANameString to "your.wpa.network"
set WEPNameString to "your.wep.network"
set WEPPassString to "your.wep.password"
set ClearClipboardString to "something to overwrite the password info later on"
set theUser to (do shell script "echo $USER")

try
  tell current application
      activate
      set acctBox to display dialog "Wireless Connection Setup:
Please enter your network USERNAME
(Ex. USERNAME@mydomain.com)" default answer "" buttons {"Cancel", "OK"} default button 2
      set myAcct to the text returned of acctBox
      set myButton to the button returned of acctBox
      if myButton is "OK" then
          if myAcct is not "" then
              set myPass to display dialog "Please enter your network password: Be careful to enter it correctly!" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
              if myPass is not "" then
                  set myMacPassDialog to display dialog "Please carefully enter your Mac/Apple password. (This is the password you used to start the installer)" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
                  set myMacPass to the text returned of myMacPassDialog
              else
                  RestartRoutine()
              end if
          else
              RestartRoutine()
          end if
      else
          RestartRoutine()
      end if
     
      if myAcct contains "@" then
          set myAcct to text 1 through ((offset of "@" in myAcct) - 1) of myAcct
      end if
     
     
      set acctBox to display dialog "Click OK to install then please DO NOT TOUCH the keyboard or mouse/trackpad until wireless setup is complete!" buttons {"Cancel", "OK"} default button 2
      set myButton to the button returned of acctBox
      if myButton is "Cancel" then
          quit
      end if
  end tell
 
  -- MUST Turn off wireless
  do shell script "networksetup -setairportpower off" user name theUser password myMacPass with administrator privileges
 
  -- MUST Turn on Assistive Devices for script to run properly
  do shell script "sudo touch /private/var/db/.AccessibilityAPIEnabled" user name theUser password myMacPass with administrator privileges
 
  tell application "System Preferences"
      activate
      set the current pane to pane id "com.apple.preference.network"
      get the name of every anchor of pane id "com.apple.preference.network"
      reveal anchor "Advanced Airport" of pane id "com.apple.preference.network"
      try
          tell application "System Events"
              tell application process "System Preferences"
                  -- Setup WPA2 network
                  do shell script "/tmp/somefolder/BigHonkingText -M -p 2 -b orange \" Please DO NOT TOUCH, be patient. \""
                  click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
                  set the clipboard to WPANameString
                  click text field 1 of group 1 of window 1
                  keystroke "v" using {command down}
                  click pop up button 1 of window 1
                  click menu item "WPA2 Enterprise" of menu 1 of pop up button 1 of window 1
                  delay 1
                  click pop up button 2 of window 1
                  click menu item "Automatic" of menu 1 of pop up button 2 of window 1
                  delay 1
                  set the clipboard to myAcct
                  click text field 1 of window 1
                  keystroke "v" using {command down}
                  delay 1
                  set the clipboard to myPass
                  keystroke tab
                  keystroke "v" using {command down}
                  delay 1
                  click button "Add" of window 1
                 
                  -- Setup WEP network
                 
                  do shell script "/tmp/somefolder/BigHonkingText -M -p 2 -b orange \" Please DO NOT TOUCH, be patient. \""
                  click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
                  set the clipboard to WEPNameString
                  click text field 1 of group 1 of window 1
                  keystroke "v" using {command down}
                  click pop up button 1 of window 1
                  click menu item "WEP Password" of menu 1 of pop up button 1 of window 1
                  set the clipboard to WEPPassString
                  keystroke "v" using {command down}
                  delay 1
                  click button "Add" of window 1
                  click button "OK" of sheet 1 of window "Network"
                  keystroke myMacPass
                  keystroke return
                  set the clipboard to ClearClipboardString
                  delay 2
                  click button "Apply" of window "Network"
                  delay 1
              end tell
             
          end tell
      on error
          display dialog "Network settings error"
      end try
  end tell
 
  -- Add the certificate to the keychain
  try
      do shell script "sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain /private/tmp/some_folder/your.certificate.pem" user name theUser password myMacPass with administrator privileges
      delay 1
  on error
      display dialog "Could not load certificate"
  end try
  -- Connect to wireless
  do shell script "networksetup -setairportpower on"
  delay 1
  tell application "System Preferences" to quit
  do shell script "/tmp/somefolder/BigHonkingText -M -p 4 -b orange \" Wireless Setup Is Complete! \""
 
 
on error
  display dialog "Wireless setup failed! Please call Jenny at 867-5309 for more help."
 
end try

found from: http://bbs.macscripter.net/viewtopic.php?pid=101188

Anyone here ever try this stuff?


All times are GMT -5. The time now is 08:01 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.