#!/bin/sh # # Short: Create Mac OS X NetInfo mounts from a text file # Version: 2.03, 13-08-02 # Author: Mark J Swift, msw AT blackpool.ac.uk # Long: This script will create Mac OS X netinfo entries for every # mount point specified in a given text file. The text file # must have a line for every mount that gives the following # information': machine_name,machine_ip,mountpoint # # 1. Log in as root # # 2. Copy this script into roots home directory # (/private/var/root/Documents). # # 3. Start a new shell process and change directory to roots home. # # cd ~/Documents # # 4. Set the execute flag is set on the script, type: # # chmod u+x mkmounts.sh # # 5. Create a text file containing a line for every mount # that gives the following information': # # machine_name,machine_ip,mountpoint ...i.e: # # oak,192.168.1.2,/share1 # oak,192.168.1.2,/Volumes/STORE1/share2 # cedar,192.168.1.3,/Volumes/STORE2/share3 # # 6. Save the file as "mounts.txt" in roots' home directory # # 7. Execute the "mkmounts.sh" script and pass it the mounts file # "mounts.txt" with the following command: # # ~/Documents/mkmounts.sh mounts.txt # # quit if wrong number of parameters NPARAMS=$# if [ $NPARAMS -ne 1 ] then echo usage: $0 \ exit 0 fi # check if mount import file exists INFILE=$1 if ! ( test -r $INFILE ) then echo file not found: $INFILE exit 0 fi # get the name of this workstation node_name=`uname -n` # -------------------------------- # debug - print host details to screen # -------------------------------- # echo " node_name:$node_name" # -------------------------------- # NetInfo: are we sharing, are we master? # -------------------------------- ni_notshared=`niutil -rparent . | grep -c -y "[.]*no parent"` if [ $ni_notshared -eq 1 ] then ni_isshared=0 ni_ismaster=0 ni_host_name=$node_name else ni_isshared=1 ni_ismaster=`niutil -rparent . | grep -c -y "^$node_name[]*/[]*"` ni_host_name=`niutil -rparent . | cut -d/ -f1 | cut -d. -f1 ` fi if [ $ni_isshared -eq 0 -o $ni_ismaster -eq 1 ] then ni_canmodify=1 else ni_canmodify=0 fi # -------------------------------- # debug - print host NetInfo details to screen # -------------------------------- # echo " ni_is_shared:$ni_isshared" # echo " ni_is_master:$ni_ismaster" # echo " ni_canmodify:$ni_canmodify" # echo " ni_host_name:$ni_host_name" if [ $ni_canmodify -eq 0 ] then echo "ERROR: This script must be run on the NetInfo Master server, $ni_host." else # -------------------------------- # read from file, line-by-line # -------------------------------- line_count=0 tr -s "\015" "\012" < "$1" | while read whole_line do line_count=`expr $line_count + 1` # -------------------------------- # get mount details from file # -------------------------------- # strip extra spaces whole_line=`echo "$whole_line" | tr -s "\040"` # extract (lower case) machine name machine_name=`echo $whole_line | tr [A-Z] [a-z] | cut -d, -f1` whole_line=`echo $whole_line | cut -d, -s -f2-` # extract ip address machine_ip=`echo $whole_line | tr [A-Z] [a-z] | cut -d, -f1` whole_line=`echo $whole_line | cut -d, -s -f2-` # debug - print machine details to screen # echo "machine name: $machine_name" # echo " machine ip: $machine_ip" while [ "$whole_line" ]; do mount_point=`echo $whole_line | cut -d, -f1` whole_line=`echo $whole_line | cut -d, -s -f2-` # deduce a share point from the mount temp=$mount_point while [ "$temp" ]; do share_point=`echo $temp | cut -d/ -f1` temp=`echo $temp | cut -d/ -s -f2-` done # debug - print user details to screen # echo "mount point : $mount_point" # echo "share point : $share_point" # -------------------------------- # create mounts NETINFO details # -------------------------------- # does the mount already exist count=`nireport / /mounts name | grep -c -y "^$machine_name:$mount_point\b"` if [ $count -eq 0 ] then # mount point doesn't yet exist echo " : Creating mount $machine_name:$mount_point" # its difficult to create directory containing "/" char while [ `niutil 2>&1 -create / /mounts/new_directory | grep -y -c " *Permission denied"` -ne 0 ]; do sleep 2 ; done # ...so do it in two stages while [ `niutil 2>&1 -createprop / /mounts/new_directory name "$machine_name:$mount_point" | grep -y -c " *Permission denied"` -ne 0 ]; do sleep 2 ; done else # Everything is fine, mount already exists echo " : Updating mount $machine_name:$mount_point" fi # get netinfo directory id for mount ni_dirid=`nigrep "$machine_name:$mount_point$" / /mounts | cut -d ' ' -f1` # create/overwrite vfstype property while [ `niutil 2>&1 -createprop / $ni_dirid vfstype url | grep -y -c " *Permission denied"` -ne 0 ]; do sleep 2 ; done # create/overwrite dir property while [ `niutil 2>&1 -createprop / $ni_dirid dir "/Network/Servers" | grep -y -c " *Permission denied"` -ne 0 ]; do sleep 2 ; done # create/overwrite opts property while [ `niutil 2>&1 -createprop / $ni_dirid opts net | grep -y -c " *Permission denied"` -ne 0 ]; do sleep 2 ; done # append to opts property while [ `niutil 2>&1 -appendprop / $ni_dirid opts "url==afp://;AUTH=NO%20USER%20AUTHENT@$machine_ip/$share_point" | grep -y -c " *Permission denied"` -ne 0 ]; do sleep 2 ; done done done fi