[dl-x86solaris-devel 99] CVS update: dlkit2/cl

Zurück zum Archiv-Index

SAWADA Keiji card_capto****@users*****
2006年 3月 29日 (水) 01:48:30 JST


Index: dlkit2/cl/disklessify
diff -u dlkit2/cl/disklessify:1.1.2.1 dlkit2/cl/disklessify:1.1.2.2
--- dlkit2/cl/disklessify:1.1.2.1	Sun Mar 12 14:18:56 2006
+++ dlkit2/cl/disklessify	Wed Mar 29 01:48:30 2006
@@ -1,13 +1,42 @@
 #!/bin/sh
+# -*- shell-script -*-
+# disklessify - disklessify client; in NFS miniroot environemnt,
+# search existing slice and copy them to new NFS volume.  The NFS
+# volume will be new root slice for future boot environment.
+#
+# Copyright (c) 2005-2006 SAWADA Keiji <card_capto****@users*****>
+# Copyright (c) 2005-2006 teelime <teeli****@users*****>
+#
+# This program is free software and has two license options; GNU
+# General Public License, or Common Development and Distribution
+# License.  You can and must select one when you redistribute and/or
+# modify this program.  Whatever you choose, this software comes with
+# absolutely no warranty.
 
-# Usage: cl.disklessify {[-probe] | -copy | -bootenv}
+# NOTE: names of each slices in current and existing environment.
+# system cannot hold more than one (potential) root slice.
 
-CL_ROOT=/a
+set -e
+
+#----------------------------------------------------------------------
+# subroutines
 
 echon() {
     printf "%s" "$@"
 }
 
+perror() {
+    echo "ERROR: " "$@"
+    exit 1
+}
+
+usage() {
+    echo
+    echo "Usage: $0 {-probe | -copy | -bootenv}"
+    echo "       (-probe option is default)"
+    exit 0
+}
+
 backup_file() {
     file=${1:?}
     if [ ! -f "$file.localdisk" ]; then
@@ -16,27 +45,28 @@
     fi
 }
 
+#----------------------------------------------------------------------
+# enumeration and checking routines
+
 check_nfsroot() {
     mnttab=${1:-/etc/mnttab}
-    return 1
-    while read spec mntpt fstype opts mnttime
-    do
-      if [ "x$mntpt" = x/ ]; then
-	  if [ "x$fstype" = xnfs ]; then
-	      echo "rootdir is nfs-mounted"
-	      return 0
-	  else
-	      echo "Error: rootdir is *NOT* nfs-mounted"
-	      exit 1
-	  fi
-      fi
+
+    echon "Checking root directory is NFS volume... "
+    while read spec mntpt fstype opts mnttime; do
+	if [ "x$mntpt" = x/ ]; then
+	    if [ "x$fstype" = xnfs ]; then
+		echo "yes"
+		return 0
+	    else
+		echo "no"; perror "rootdir should be NFS volume"
+	    fi
+	fi
     done < $mnttab
-    echo "Error: rootdir not found in $mnttab"
-    exit 1
+    perror "rootdir not found in $mnttab"
 }
 
-enum_slices() {
-    # Usage: enum_slices [/dev/dsk]
+enum_slice_devices() {
+    # Usage: enum_slice_devices [/dev/dsk]
     devdsk=${1:-/dev/dsk}
     (cd $devdsk
 	for s in c*d*s* c*t*d*s*
@@ -44,7 +74,7 @@
 	  test -L $s && echo $devdsk/$s
 	  done)
 }
-#enum_slices
+#enum_slice_devices
 
 find_spec_from_vfstab_by_mntpt() {
     # Usage: find_spec_from_vfstab_by_mntpt mntpt [/etc/vfstab]
@@ -55,8 +85,8 @@
     done < $vfstab
 }
 
-devnode_for_dev() {
-    # Usage: devnode_for_dev device [lsout]
+get_devnode_from_spec() {
+    # Usage: get_devnode_from_spec device [lsout]
     dev=${1:?}
     regex=`echo "$dev" | sed 's,/,\\\\/,g'`
 
@@ -64,8 +94,8 @@
 	| sed -n "s/^.*${regex} -> .*\/devices\(\/.*\)\$/\1/p"
 }
 
-dev_for_devnode() {
-    #Usage: dev_for_devnode node lsout
+get_spec_from_devnode() {
+    #Usage: get_spec_from_devnode node lsout
     node=${1:?}; lsout=${2:?}
     regex=`echo "$node" | sed 's,/,\\\\/,g'`
 
@@ -116,8 +146,8 @@
 	return 1
     fi
 
-    rnode=`devnode_for_dev "/localdisk/$rdev"`
-    lnode=`devnode_for_dev "$ldev"`
+    rnode=`get_devnode_from_spec "/localdisk/$rdev"`
+    lnode=`get_devnode_from_spec "$ldev"`
     umount /localdisk
 
     if [ "x$rnode" = "x$lnode" ]; then
@@ -131,64 +161,65 @@
     fi
 }
 
-#----------------------------------------------------------------------
+find_root_slice() {
+    echo "Searching for ufs slice(s) on local disk(s)... "
+    for ldev in `enum_slice_devices`
+    do
+      if slice_is_ufs "$ldev"; then
+	  ufs_slices="$ufs_slices $ldev"
+      fi
+    done
 
-mode=${1:--probe}
+    for ldev in $ufs_slices
+    do
+      echon "Checking if $ldev is root slice... "
+      if slice_is_root_slice "$ldev"; then
+	  echo "yes"; root_slice="$ldev"
+      else
+	  echo "no"
+      fi
+    done
+    if [ -z "$root_slice" ]; then
+	echo "Error: root slice not found"; exit 1
+    fi
 
-trandir=/dlkit
-. $trandir/config.in
+    echo "Gathering /dev and vfstab info from root slice..."
+    mount -F ufs -o ro $root_slice /localdisk
+    (cd /localdisk
+	cp etc/vfstab $tmpfile.ldisk_vfstab
+	find ./dev -type l -ls > $tmpfile.ldisk_devlist)
+    (cd /
+	find ./dev -type l -ls > $tmpfile.curr_devlist)
+    umount /localdisk
+}
 
-check_nfsroot
+enum_existing_slices() {
+    echo "Enuemerating existing slice(s) on local disk(s)... "
+    while read spec fsckdev mntpt fstype fsckpass mntflag opts; do
+	if [ ! "x$fstype" = xufs ]; then continue; fi
 
-umount /localdisk > /dev/null 2>&1
-mkdir -p /localdisk
+	node=`get_devnode_from_spec "$spec" $tmpfile.ldisk_devlist`
+	if [ -z "$node" ]; then continue; fi
 
-echo "Mounting $CL_ROOT on $SV_IPADDR:$SV_FIN_ROOT..."
-umount $CL_ROOT > /dev/null 2>&1
-mount $SV_IPADDR:$SV_FIN_ROOT $CL_ROOT
+	c_dev=`get_spec_from_devnode "$node" $tmpfile.curr_devlist`
+	if [ -z "$c_dev" ]; then continue; fi
 
-echo "Searching for ufs slice(s) on local disk(s)... "
-for ldev in `enum_slices`
-do
-  if slice_is_ufs "$ldev"; then
-      ufs_slices="$ufs_slices $ldev"
-  fi
-done
-
-for ldev in $ufs_slices
-do
-  echon "Checking if $ldev is root slice... "
-  if slice_is_root_slice "$ldev"; then
-      echo "yes"; root_slice="$ldev"
-  else
-      echo "no"
-  fi
-done
-if [ -z "$root_slice" ]; then
-    echo "Error: root slice not found"; exit 1
-fi
-
-echo "Gathering /dev and vfstab info from root slice..."
-mount -F ufs -o ro $root_slice /localdisk
-(cd /localdisk
-    cp etc/vfstab /tmp/.v.vfstab
-    find ./dev -type l -ls > /tmp/.v.ldisk_devlist)
-(cd /
-    find ./dev -type l -ls > /tmp/.v.curr_devlist)
-umount /localdisk
+	echo "Current $c_dev was $spec at $mntpt"
+    done < $tmpfile.ldisk_vfstab
+}
 
 #----------------------------------------------------------------------
-#
+# transferring local disk content
 
-copy_local_disks() {
-    echo "Copying ufs directories on local disk(s)... "
+transfer_existing_slices() {
+    echo "Copying existing slice(s) to NFS root... "
     while read spec fsckdev mntpt fstype fsckpass mntflag opts; do
 	if [ ! "x$fstype" = xufs ]; then continue; fi
 
-	node=`devnode_for_dev "$spec" /tmp/.v.ldisk_devlist`
+	node=`get_devnode_from_spec "$spec" $tmpfile.ldisk_devlist`
 	if [ -z "$node" ]; then continue; fi
 
-	c_dev=`dev_for_devnode "$node" /tmp/.v.curr_devlist`
+	c_dev=`get_spec_from_devnode "$node" $tmpfile.curr_devlist`
 	if [ -z "$c_dev" ]; then continue; fi
 
 	echo ""
@@ -209,25 +240,9 @@
 
 	echo "Copied $c_dev ($mntpt)"
 	umount /localdisk
-    done < /tmp/.v.vfstab
-}
-
-enum_local_disks() {
-    echo "Enuemerating ufs directories on local disk(s)... "
-    while read spec fsckdev mntpt fstype fsckpass mntflag opts; do
-	if [ ! "x$fstype" = xufs ]; then continue; fi
-
-	node=`devnode_for_dev "$spec" /tmp/.v.ldisk_devlist`
-	if [ -z "$node" ]; then continue; fi
-
-	c_dev=`dev_for_devnode "$node" /tmp/.v.curr_devlist`
-	if [ -z "$c_dev" ]; then continue; fi
-
-	echo "Current $c_dev was $spec at $mntpt"
-    done < /tmp/.v.vfstab
+    done < $tmpfile.ldisk_vfstab
 }
 
-
 config_vfstab() {
     echo "Configuring /etc/vfstab..."
 
@@ -241,6 +256,7 @@
 	s_option="$CL_MOUNT_OPTION"
     fi
 
+    # remove ufs entry (keeps other file system entry)
     while read line; do
 	case "$line" in
 	    '#*')
@@ -253,10 +269,11 @@
 	esac
     done < $CL_ROOT/etc/vfstab.localdisk > $CL_ROOT/etc/vfstab
 
-    echo "$SV_NAME:$SV_FIN_ROOT - / nfs - no $r_option" >> $CL_ROOT/etc/vfstab
-
-    echo "$SV_NAME:$SV_SWAPFILE - $CL_SWAPFILE nfs - no $s_option" >> $CL_ROOT/etc/vfstab
-    echo "$CL_SWAPFILE - - swap - no -" >> $CL_ROOT/etc/vfstab
+    (
+	echo "$SV_NAME:$SV_FIN_ROOT - / nfs - no $r_option"
+	echo "$SV_NAME:$SV_SWAPFILE - $CL_SWAPFILE nfs - no $s_option"
+	echo "$CL_SWAPFILE - - swap - no -"
+    ) >> $CL_ROOT/etc/vfstab
 }
 
 config_default_nfs() {
@@ -271,23 +288,15 @@
 
 config_autofs() {
     if [ ! -z "$CL_EXPORT_HOME_MODE" ]; then
-	#echo "Setting mode and ownership for $CL_NAME:/export/home..."
 	echo "Setting mode and ownership for /export/home..."
 	if [ ! -d "$CL_ROOT/export/home" ]; then
-		mkdir -p $CL_ROOT/export/home
-		chown root $CL_ROOT/export/home
-		chgrp root $CL_ROOT/export/home
+	    mkdir -p $CL_ROOT/export/home
+	    chown root $CL_ROOT/export/home
+	    chgrp root $CL_ROOT/export/home
 	fi
 	chmod "$CL_EXPORT_HOME_MODE" $CL_ROOT/export/home
     fi
 }
-network_iface() {
-    netstat -i | tail +2 | while read name mtu dest other; do
-	if [ ! "x$name" = xlo0 -a ! "x$dest" = xloopback ]; then
-	    echo "$name"; break
-	fi
-    done
-}
 
 setup_bootenv() {
     backup_file $CL_ROOT/etc/vfstab
@@ -297,18 +306,40 @@
     config_default_nfs
     config_autofs
 
-    # An allopathy
+    # TODO: An allopathy
     mkdir -p $CL_ROOT/etc/skel/.gnome2/panel2.d/default/launchers
 }
 
+#----------------------------------------------------------------------
+
+mode=${1:-"-probe"}
+
+CL_ROOT=/a
+tmpfile=/tmp/disklessiy
+trandir=/dlkit
+. $trandir/config.in
+
+check_nfsroot
+
+umount /localdisk > /dev/null 2>&1
+mkdir -p /localdisk
+
+echo "Mounting $CL_ROOT on $SV_IPADDR:$SV_FIN_ROOT..."
+umount $CL_ROOT > /dev/null 2>&1
+mount $SV_IPADDR:$SV_FIN_ROOT $CL_ROOT
 
 case "x$mode" in
+    x-probe)
+	find_root_slice
+	enum_existing_slices ;;
     x-copy)
-	copy_local_disks ;;
+	find_root_slice
+	transfer_existing_slices ;;
     x-bootenv)
+	find_root_slice
 	setup_bootenv ;;
     *)
-	enum_local_disks ;;
+	usage ;;
 esac
 
 echo "Unmounting $CL_ROOT..."


dl-x86solaris-devel メーリングリストの案内
Zurück zum Archiv-Index