#!/bin/bash # # Create a brandz zone to use for the JDS Common Build Environment # After you run this script do not boot this zone. Use it to clone # other zones. # PATH=/usr/xpg4/bin:/usr/bin:/usr/sbin:/sbin:/usr/ccs/bin # Name of the zone which we will clone. Not this clone does not # get booted zname=jdsclone # Local users to include in zone # The homedirs are mounted from the global zone xusers="jdsbuild" # Brand configuration brand=cbe brandcfg=/usr/lib/brand # ZFS filesystem to put the zone in zonebase=/export/zones ################################################################### zfsbase="$(zfs get mountpoint | nawk -v p="$zonebase" '$3==p { printf "%s\n",$1}')" [ "$zfsbase" = "" ] && { echo "Error: $zonebase is not a ZFS filesystem" exit 1 } zroot="$zonebase/$zname/root" [ -d "$zroot" ] && { echo "Error: $zroot already exists" exit 1 } [ ! -d /opt/jdsbld ] && { echo "Error: You have not installed the cbe at /opt/jdsbld?" exit 1 } [ ! -d /opt/SUNWspro ] && { echo "Error: Have you installed Sun Studio?" exit 1 } grep -q "^${zname}:" /etc/zones/index && { echo "Error: The zone ${zname} already exists" exit 1 } [ ! -d $brandcfg/$brand ] && { mkdir -p $brandcfg/$brand cp -p $brandcfg/native/postclone $brandcfg/$brand sed -e "s/native/$brand/" $brandcfg/native/config.xml \ > $brandcfg/$brand/config.xml sed -e "s/native/$brand/" $brandcfg/native/platform.xml \ > $brandcfg/$brand/platform.xml } [ -f /etc/zones/OSOL${brand}.xml ] && { echo "Error: /etc/zones/OSOL${brand}.xml already exists." exit 1 } # # This mess is code to produce a zone template # cat > /etc/zones/OSOL${brand}.xml << EOM EOM for i in $xusers do HOME="$(grep "^$i:" /etc/passwd | awk -F: '{print $6}')" [ "$HOME" != "" ] && { printf " \n" $HOME $HOME printf " \n" printf " \n\n" } >> /etc/zones/OSOL${brand}.xml done printf "\n" >> /etc/zones/OSOL${brand}.xml ( printf "create -t OSOL%s\n" $brand printf "set zonepath=%s/%s\n" $zonebase $zname printf "set autoboot=false\n" printf "commit\n" printf "exit\n" ) | zonecfg -z $zname > /dev/null 2>&1 grep -q "^${zname}:configured:" /etc/zones/index || { echo "Error: Could not configure zone" exit 1 } zoneadm -z $zname install [ "$zroot" = "" -o "$zroot" = "/" -o ! -d "$zroot" ] && { echo "The rootpath for the zone is nor correct" exit 1 } [ -x "/root/.bash_profile" ] && { mkdir -m 0700 $zroot/root && cp ~/.bash_profile $zroot/root } zusers=$(nawk -F: -v users="$xusers" ' { print $1 } END { printf "%s\n",users }' < $zroot/etc/passwd) for f in /etc/passwd /etc/shadow do for i in $zusers do /usr/xpg4/bin/grep -q "^${i}:" $zroot/$f || { /usr/xpg4/bin/grep "^${i}:" $f } done > $zroot/$f done for i in $xusers do /usr/xpg4/bin/grep -q "^${i}:" $zroot/etc/user_attr || { /usr/xpg4/bin/grep "^${i}:" /etc/user_attr >> $zroot/etc/user_attr } done tz="$(/usr/bin/nawk -F= '/^TZ/ {print $2}' /etc/TIMEZONE)" rpass="$(/usr/bin/nawk -F: '/^root:/ {print $2}' /etc/shadow)" cat > $zroot/etc/sysidcfg << EOM system_locale=${LANG} terminal=xterm timezone=${tz} network_interface=NONE { hostname=$zname } name_service=NONE root_password=${rpass} EOM