- This topic has 6 replies, 3 voices, and was last updated 16 years, 5 months ago by
TAW.
-
AuthorPosts
-
December 17, 2009 at 2:40 am #377688
TAW
ParticipantI am trying to make two very simple packages that run postinstall scripts. One of them is a simple lpadmin command to add a printer and the other is a networksetup command to add a wireless network and WPA2 password.
My network script looks like this, when I run it at the command line it works fine. The package fails. What am I doing wrong?
#! /bin/bash
sudo networksetup -setairportnetwork en1 Wireless mywpapassswordDecember 17, 2009 at 4:22 am #377689larkost
ParticipantThere are a few things wrong here:
1) There should be no space after the shebang, so:
[code]#!/bin/bash[/code]2) ‘sudo’ is not going to help you here. If you check the box to have this be an admin package it will run with admin (root/wheel) rights, and then ‘sudo’ is superfluous. If you don’t check the box then there is no way for it to get the password it needs.
3) When you are writing scripts always use full paths to things. The environment that the script runs in might not have the same path or aliases as your login. This is probably what you are running into since networksetup is in /usr/sbin, and I am not sure that is included in the installer environment path. To find this I used ‘whereis networksetup’.
4) You are putting a password in cleartext. You might not have a choice, but this is a dangerous thing in general, and you should at least cringe at the necessity.
5) I would be careful just calling netoworksetup this way, since it was only in /usr/sbin starting in 10.5. Prior to that it was tucked in the ARD package, and even then you had to know if you were calling the 10.3 or 10.4 version.
6) This is an InstaDMG form, and I am not sure that even the chroot available in 10.5 (for 10.5 images) is going to allow this script to function properly in an InstaDMG workflow. This will definitely fail on 10.6 at the moment.
December 17, 2009 at 12:58 pm #377690TAW
ParticipantThanks for the detailed response larkost.
So are you saying that moving forward (10.6+) packaged scripts are not going to work? Or just my exampe with the network setup command?
I am really trying to get my head around the InstaDMG workflow becasue I feel its a better way to image but so far I am struggling with all the customization that needs to happen. If I am getting stuck on adding the wireless network who knows what I am in for when I get to the adding it to my OD domain.
December 17, 2009 at 2:55 pm #377691walt
ParticipantNo, packaged scripts will always work in InstaDMG. What he means is that the specific command you are using is really meant to be run on a live/booted system. When you run that networksetup command in a script that is in an installer package, the command will, by it’s design, run on and in turn make changes to the booted system volume. CHROOT allows commands to run inside of “jails” so to speak, so that you can direct a command to not go outside of a specific directory, which may get this command to run targeting a volume that isn’t actually booted (your target InstaDMG Image).
Setting up the wireless network the way you are can be done using a first boot script. What this means is you create an install package to use with InstaDMG that installs a startup item, that startup item can be a shell script that runs the commands you want when the computer first boots, this solves the problem of not being able to target certain commands at systems that aren’t booted, like the one you are trying to use here.
Here is an example of an installer package I use to set standard settings on my images, part of which includes a script that runs on first boot:
[b]Postflight Script from the package:[/b]
[code]
#!/bin/sh# Standard settings for images.
# Script is meant to be run as a postflight script in a .pkg file. Also installs startup settings script as a Launchd item which is inside the package /Contents/Resources directory.
##### Begin Declare Variables Used by Script #####
# Declare ‘defaults’and ‘PlistBuddy’.
defaults=”/usr/bin/defaults”
PlistBuddy=”/usr/libexec/PlistBuddy”# Declare directory variables.
PKG_DIR=”$1/Contents/Resources”
SCRIPTS_DIR=”$3/Library/Scripts/Purchase”
LAUNCHD_DIR=”$3/Library/LaunchDaemons”
PRIVETC_DIR=”$3/private/etc”
PREFS_DIR=”$3/Library/Preferences”
USERPREFS_DIR=”$3/System/Library/User Template/English.lproj/Library/Preferences”
ROOT=”$3/”
UPDATE_DYLD=”$3/usr/bin/update_dyld_shared_cache” # Set variable to location of update_dyld_shared_cache command on target volume.##### End Declare Variables Used by Script #####
##### Begin Startup Settings Script Installation #####
# This script that is installed on the target volume sets settings that need to be set on the first boot of the image.
# Create scripts directory.
mkdir “${SCRIPTS_DIR}”
# Copy startupssettings.sh script to the scripts directory.
cp “${PKG_DIR}/startupsettings.sh” “${SCRIPTS_DIR}”
# Install Launchd item to /Library/LaunchDaemons.
$defaults write “${LAUNCHD_DIR}/edu.purchase.startupsettings” Label edu.purchase.startupsettings
$defaults write “${LAUNCHD_DIR}/edu.purchase.startupsettings” ProgramArguments -array
$PlistBuddy -c “Add :ProgramArguments:Item\ 1 string /Library/Scripts/Purchase/startupsettings.sh” “${LAUNCHD_DIR}/edu.purchase.startupsettings.plist”
$defaults write “${LAUNCHD_DIR}/edu.purchase.startupsettings” RunAtLoad -bool YES# Give Launchd item correct permissions.
chown root:wheel “${LAUNCHD_DIR}/edu.purchase.startupsettings.plist”
chmod 644 “${LAUNCHD_DIR}/edu.purchase.startupsettings.plist”##### End Startup Settings Script Installation #####
##### Begin Preference Setting #####
# These settings can be set on the target volume before startup.
# Run update_dyld_shared_cache
$UPDATE_DYLD -universal_boot -root $ROOT
# Display login window as Name and Password.
$defaults write “${PREFS_DIR}/com.apple.loginwindow” SHOWFULLNAME -bool YES
# Use encrypted virtual memory.
$defaults write “${PREFS_DIR}/com.apple.virtualMemory” UseEncryptedSwap -bool Yes
# Set Safari Preferences.
$defaults write “${USERPREFS_DIR}/com.apple.Safari” HomePage http://www.purchase.edu/
$defaults write “${USERPREFS_DIR}/com.apple.Safari” ShowStatusBar -bool YES# Set Finder Prefereces.
$defaults write “${USERPREFS_DIR}/com.apple.finder” ShowMountedServersOnDesktop -bool YES
# No .ds-store files on Network Shares
$defaults write “${PREFS_DIR}/com.apple.desktopservices” DSDontWriteNetworkStores true
# Globally Set Expanded Print Dialouge Box.
$defaults write “${PREFS_DIR}/.GlobalPreferences” PMPrintingExpandedStateForPrint -bool TRUE
# Use short-name for logging into Network Shares
$defaults write “${PREFS_DIR}/com.apple.NetworkAuthorization” UseDefaultName -bool NO
$defaults write “${PREFS_DIR}/com.apple.NetworkAuthorization” UseShortName -bool YES# Set Apple Mouse button 1 to Primary click and button 2 to Secondary click.
$defaults write “${USERPREFS_DIR}/com.apple.driver.AppleHIDMouse” Button1 -integer 1
$defaults write “${USERPREFS_DIR}/com.apple.driver.AppleHIDMouse” Button2 -integer 2# Disable Time Machine Offers.
$defaults write “${PREFS_DIR}/com.apple.TimeMachine” DoNotOfferNewDisksForBackup -bool YES##### End Preferences Setting #####
exit 0
[/code][b]Startup Settings Script that is installed by the above postflight script and runs on first boot:[/b]
[code]
#!/bin/sh# System startup script that should be a Launchd startup script, the script deletes itself and the launchd item after completion.
# Define ‘kickstart’ and ‘systemsetup’ variables, built in OS X script that activates and sets options for ARD.
kickstart=”/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart”
systemsetup=”/usr/sbin/systemsetup”# Delete iMove (Previous Version) Directory if it exists, because we don’t need it.
rm -R /Applications/iMovie\ \(previous\ version\).localized/
# ARD Configuration
# Set options and activate ARD for only ctstech user with all privelages.
# First we have to define specified users with ARD privelages in a separate command.
$kickstart -configure -users adminuser -access -on -privs -all
# The next command configures the other ARD options.
$kickstart -activate -configure -allowAccessFor -specifiedUsers -clientopts -setmenuextra -menuextra yes
# Set time zone and time server.
$systemsetup -setusingnetworktime on
$systemsetup -settimezone America/New_York -setnetworktimeserver time.apple.com
# Activate WakeOnLAN.
$systemsetup -setwakeonnetworkaccess on
# Activate SSH.
$systemsetup -setremotelogin on
# Delete the script and the launchd item.
srm /Library/LaunchDaemons/edu.purchase.startupsettings.plist
srm “$0”
[/code]
Also don’t get discouraged, figuring out modular imaging to the point where I could actually build images to my liking took me a couple of months of reading and a lot of trial and error. My scripting skills also needed a lot of polishing :P. In the end the extra effort is worth it though. It will all make sense, just stick with it and ask questions if you run into trouble :).
December 17, 2009 at 3:04 pm #377692TAW
ParticipantWalt,
This is a huge help thanks for sharing this info.
I have a pretty good handle on most things and am not shy of the command line but I have never written shell scripts so this new concept is taking me some time to absorb.
Thanks again
Troy
December 18, 2009 at 1:42 pm #377697TAW
ParticipantWalt,
I have been experimenting with your script and trying to understand things. Some of your commands have a $ in front of them, what does this do? When I inserted my networksetup command with the $ it failed with command not found, without the $ it works fine.December 18, 2009 at 11:22 pm #377702TAW
ParticipantNevermind. After further investigation I see that you have defined a couple of things as variables and the $ prefaces those variables……Im getting there
-
AuthorPosts
- You must be logged in to reply to this topic.
Comments are closed