Print this page
XXX Remove nawk(1)


 232 
 233         chmod $mode $filename
 234         chown $own $filename
 235 }
 236 
 237 #
 238 # Read zonecfg fs entries and save the relevant data, one entry per
 239 # line.
 240 # This assumes the properties from the zonecfg output, e.g.:
 241 #       fs:
 242 #               dir: /opt
 243 #               special: /opt
 244 #               raw not specified
 245 #               type: lofs
 246 #               options: [noexec,ro,noatime]
 247 #
 248 # and it assumes the order of the fs properties as above.
 249 #
 250 get_fs_info()
 251 {
 252         zonecfg -z $zonename info fs | nawk '{
 253                 if ($1 == "options:") {
 254                         # Remove brackets.
 255                         options=substr($2, 2, length($2) - 2);
 256                         printf("%s %s %s %s\n", dir, type, special, options);
 257                 } else if ($1 == "dir:") {
 258                         dir=$2;
 259                 } else if ($1 == "special:") {
 260                         special=$2;
 261                 } else if ($1 == "type:") {
 262                         type=$2
 263                 }
 264         }' >> $fstmpfile
 265 }
 266 
 267 #
 268 # Mount zonecfg fs entries into the zonepath.
 269 #
 270 mnt_fs()
 271 {
 272         if [ ! -s $fstmpfile ]; then
 273                 return;
 274         fi
 275 
 276         # Sort the fs entries so we can handle nested mounts.
 277         sort $fstmpfile | nawk -v zonepath=$zonepath '{
 278                 if (NF == 4)
 279                         options="-o " $4;
 280                 else
 281                         options=""
 282 
 283                 # Create the mount point.  Ignore errors since we might have
 284                 # a nested mount with a pre-existing mount point.
 285                 cmd="/usr/bin/mkdir -p " zonepath "/root" $1 " >/dev/null 2>&1"
 286                 system(cmd);
 287 
 288                 cmd="/usr/sbin/mount -F " $2 " " options " " $3 " " \
 289                     zonepath "/root" $1;
 290                 if (system(cmd) != 0) {
 291                         printf("command failed: %s\n", cmd);
 292                         exit 1;
 293                 }
 294         }' >>$LOGFILE
 295 }
 296 
 297 #
 298 # Unmount zonecfg fs entries from the zonepath.
 299 #
 300 umnt_fs()
 301 {
 302         if [ ! -s $fstmpfile ]; then
 303                 return;
 304         fi
 305 
 306         # Reverse sort the fs entries so we can handle nested unmounts.
 307         sort -r $fstmpfile | nawk -v zonepath=$zonepath '{
 308                 cmd="/usr/sbin/umount " zonepath "/root" $1
 309                 if (system(cmd) != 0) {
 310                         printf("command failed: %s\n", cmd);
 311                 }
 312         }' >>$LOGFILE
 313 }
 314 
 315 # Find the dataset mounted on the zonepath.
 316 get_zonepath_ds() {
 317         ZONEPATH_DS=`/usr/sbin/zfs list -H -t filesystem -o name,mountpoint | \
 318             /usr/bin/nawk -v zonepath=$1 '{
 319                 if ($2 == zonepath)
 320                         print $1
 321         }'`
 322 
 323         if [ -z "$ZONEPATH_DS" ]; then
 324                 fail_fatal "$f_no_ds"
 325         fi
 326 }
 327 
 328 #
 329 # Perform validation and cleanup in the zoneroot after unpacking the archive.
 330 #
 331 post_unpack()
 332 {
 333         #
 334         # Check if the image was created with a valid libc.so.1.
 335         #
 336         hwcap=`moe -v -32 $ZONEROOT/lib/libc.so.1 2>&1`
 337         if (( $? != 0 )); then
 338                 vlog "$f_hwcap_info" "$hwcap"


 552 #   c) inside the zonepath root: We'll see all the top level dirs, ./etc,
 553 #      ./var, ./usr....  This is also the case we see when we get an archive
 554 #      of a physical sytem.  We must be in ZONEROOT when we unpack the archive.
 555 #
 556 # Note that there can be a directory named "root" under the ZONEPATH/root
 557 # directory.
 558 #
 559 # This function handles the above possibilities so that we reject absolute
 560 # path archives and figure out where in the file system we need to be to
 561 # properly unpack the archive into the zone.  It sets the ARCHIVE_BASE
 562 # variable to the location where the achive should be unpacked.
 563 #
 564 get_archive_base()
 565 {
 566         stage1=$1
 567         archive=$2
 568         stage2=$3
 569 
 570         vlog "$m_analyse_archive"
 571 
 572         base=`$stage1 $archive | $stage2 2>/dev/null | nawk -F/ '{
 573                 # Check for an absolute path archive
 574                 if (substr($0, 1, 1) == "/")
 575                         exit 1
 576 
 577                 if ($1 != ".")
 578                         dirs[$1] = 1
 579                 else
 580                         dirs[$2] = 1
 581         }
 582         END {
 583                 for (d in dirs) {
 584                         cnt++
 585                         if (d == "bin")  sawbin = 1
 586                         if (d == "etc")  sawetc = 1
 587                         if (d == "root") sawroot = 1
 588                         if (d == "var")  sawvar = 1
 589                 }
 590 
 591                 if (cnt == 1) {
 592                         # If only one top-level dir named root, we are in the




 232 
 233         chmod $mode $filename
 234         chown $own $filename
 235 }
 236 
 237 #
 238 # Read zonecfg fs entries and save the relevant data, one entry per
 239 # line.
 240 # This assumes the properties from the zonecfg output, e.g.:
 241 #       fs:
 242 #               dir: /opt
 243 #               special: /opt
 244 #               raw not specified
 245 #               type: lofs
 246 #               options: [noexec,ro,noatime]
 247 #
 248 # and it assumes the order of the fs properties as above.
 249 #
 250 get_fs_info()
 251 {
 252         zonecfg -z $zonename info fs | /usr/xpg4/bin/awk '{
 253                 if ($1 == "options:") {
 254                         # Remove brackets.
 255                         options=substr($2, 2, length($2) - 2);
 256                         printf("%s %s %s %s\n", dir, type, special, options);
 257                 } else if ($1 == "dir:") {
 258                         dir=$2;
 259                 } else if ($1 == "special:") {
 260                         special=$2;
 261                 } else if ($1 == "type:") {
 262                         type=$2
 263                 }
 264         }' >> $fstmpfile
 265 }
 266 
 267 #
 268 # Mount zonecfg fs entries into the zonepath.
 269 #
 270 mnt_fs()
 271 {
 272         if [ ! -s $fstmpfile ]; then
 273                 return;
 274         fi
 275 
 276         # Sort the fs entries so we can handle nested mounts.
 277         sort $fstmpfile | /usr/xpg4/bin/awk -v zonepath=$zonepath '{
 278                 if (NF == 4)
 279                         options="-o " $4;
 280                 else
 281                         options=""
 282 
 283                 # Create the mount point.  Ignore errors since we might have
 284                 # a nested mount with a pre-existing mount point.
 285                 cmd="/usr/bin/mkdir -p " zonepath "/root" $1 " >/dev/null 2>&1"
 286                 system(cmd);
 287 
 288                 cmd="/usr/sbin/mount -F " $2 " " options " " $3 " " \
 289                     zonepath "/root" $1;
 290                 if (system(cmd) != 0) {
 291                         printf("command failed: %s\n", cmd);
 292                         exit 1;
 293                 }
 294         }' >>$LOGFILE
 295 }
 296 
 297 #
 298 # Unmount zonecfg fs entries from the zonepath.
 299 #
 300 umnt_fs()
 301 {
 302         if [ ! -s $fstmpfile ]; then
 303                 return;
 304         fi
 305 
 306         # Reverse sort the fs entries so we can handle nested unmounts.
 307         sort -r $fstmpfile | /usr/xpg4/bin/awk -v zonepath=$zonepath '{
 308                 cmd="/usr/sbin/umount " zonepath "/root" $1
 309                 if (system(cmd) != 0) {
 310                         printf("command failed: %s\n", cmd);
 311                 }
 312         }' >>$LOGFILE
 313 }
 314 
 315 # Find the dataset mounted on the zonepath.
 316 get_zonepath_ds() {
 317         ZONEPATH_DS=`/usr/sbin/zfs list -H -t filesystem -o name,mountpoint | \
 318             /usr/xpg4/bin/awk -v zonepath=$1 '{
 319                 if ($2 == zonepath)
 320                         print $1
 321         }'`
 322 
 323         if [ -z "$ZONEPATH_DS" ]; then
 324                 fail_fatal "$f_no_ds"
 325         fi
 326 }
 327 
 328 #
 329 # Perform validation and cleanup in the zoneroot after unpacking the archive.
 330 #
 331 post_unpack()
 332 {
 333         #
 334         # Check if the image was created with a valid libc.so.1.
 335         #
 336         hwcap=`moe -v -32 $ZONEROOT/lib/libc.so.1 2>&1`
 337         if (( $? != 0 )); then
 338                 vlog "$f_hwcap_info" "$hwcap"


 552 #   c) inside the zonepath root: We'll see all the top level dirs, ./etc,
 553 #      ./var, ./usr....  This is also the case we see when we get an archive
 554 #      of a physical sytem.  We must be in ZONEROOT when we unpack the archive.
 555 #
 556 # Note that there can be a directory named "root" under the ZONEPATH/root
 557 # directory.
 558 #
 559 # This function handles the above possibilities so that we reject absolute
 560 # path archives and figure out where in the file system we need to be to
 561 # properly unpack the archive into the zone.  It sets the ARCHIVE_BASE
 562 # variable to the location where the achive should be unpacked.
 563 #
 564 get_archive_base()
 565 {
 566         stage1=$1
 567         archive=$2
 568         stage2=$3
 569 
 570         vlog "$m_analyse_archive"
 571 
 572         base=`$stage1 $archive | $stage2 2>/dev/null | /usr/xpg4/bin/awk -F/ '{
 573                 # Check for an absolute path archive
 574                 if (substr($0, 1, 1) == "/")
 575                         exit 1
 576 
 577                 if ($1 != ".")
 578                         dirs[$1] = 1
 579                 else
 580                         dirs[$2] = 1
 581         }
 582         END {
 583                 for (d in dirs) {
 584                         cnt++
 585                         if (d == "bin")  sawbin = 1
 586                         if (d == "etc")  sawetc = 1
 587                         if (d == "root") sawroot = 1
 588                         if (d == "var")  sawvar = 1
 589                 }
 590 
 591                 if (cnt == 1) {
 592                         # If only one top-level dir named root, we are in the