1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # script to create test files/directories in the current
  28 # directory based on variables in v4test.cfg file, which
  29 # must be found in the same directory as the script.
  30 #
  31 #  Usage: $NAME [full-path-dir]
  32 #       if "full-path-dir" is not provided
  33 #       default to create test files/dirs in "./srvdir"
  34 #
  35 
  36 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  37 
  38 NAME=`basename $0`
  39 
  40 id | grep "0(root)" > /dev/null 2>&1
  41 if (( $? != 0 )); then
  42         echo "$NAME: This script must be run as root."
  43         exit 1
  44 fi
  45 
  46 TDIR="./srvdir"
  47 if (( $# > 0 )); then
  48         TDIR=${1}
  49 fi
  50 [[ ! -d $TDIR ]] && mkdir -m 0777 -p $TDIR
  51 DIR=`dirname $0`
  52 [[ "$DIR" = "." ]] && DIR=`pwd`
  53 
  54 # get all names
  55 CFGFILE="$DIR/config.suite"
  56 if [[ ! -f $CFGFILE ]]; then
  57         echo "$NAME: CFGFILE[$CFGFILE] not found;"
  58         echo "\tunable to create test files/dirs; exiting."
  59         exit 2
  60 fi
  61 . $CFGFILE
  62 # Any command below fails, will exit with non-zero immediately
  63 set -e
  64 cd $TDIR
  65 
  66 # Start creation of test files and directories in $TDIR
  67 echo "creating directories ..."
  68 mkdir -m 0777 $DIR0777 $DIR0777/dir2  $LARGEDIR
  69 mkdir -m 0755 $DIR0755 $DIR0755/dir2
  70 mkdir -m 0711 $DIR0711 $DIR0711/dir2
  71 mkdir -p $DNOPERM/dir2;
  72 mkdir -p $LONGDIR
  73 typeset -i i=1
  74 while (( $i < 256 ))
  75 do
  76         mkdir $LARGEDIR/dir-${i}
  77         cp $CFGFILE $LARGEDIR/file-${i}
  78         i=`expr $i + 1`
  79 done
  80 
  81 echo "creating test files ..."
  82 head -38 $CFGFILE > $TEXTFILE; chmod 0644 $TEXTFILE
  83 cp $CFGFILE $EXECFILE; chmod 0755 $EXECFILE
  84 cp $CFGFILE $RWFILE; chmod 0666 $RWFILE
  85 cp $CFGFILE $RWGFILE; chmod 0664 $RWGFILE
  86 cp $CFGFILE $ROFILE; chmod 0444 $ROFILE
  87 > $ROEMPTY; chmod 0444 $ROEMPTY
  88 head -68 $CFGFILE > $FNOPERM; chmod 0000 $FNOPERM
  89 zip -r $ZIPFILE $LARGEDIR > /dev/null 2>&1; chmod 0444 $ZIPFILE
  90 cp $TEXTFILE $LONGDIR/file.20
  91 find $RWFILE $ROFILE $ROEMPTY -print | cpio -dump $DIR0777
  92 find $RWFILE $ROFILE $ROEMPTY -print | cpio -dump $DIR0755
  93 find $RWFILE $ROFILE $ROEMPTY -print | cpio -dump $DIR0711
  94 find $RWFILE $ROFILE $ROEMPTY -print | cpio -dump $DNOPERM
  95 
  96 echo "creating symlink files ..."
  97 ln -s $DIR0777 $SYMLDIR
  98 ln -s $DNOPERM $SYMNOPD
  99 ln -s $EXECFILE $SYMLFILE
 100 ln -s $FNOPERM $SYMNOPF
 101 
 102 echo "creating special files ..."
 103 mknod $BLKFILE b 77 188; chmod 0644 $BLKFILE
 104 mknod $CHARFILE c 88 177; chmod 0666 $CHARFILE
 105 mknod $FIFOFILE p; chmod 0664 $FIFOFILE
 106 
 107 echo "creating extended attribute files ..."
 108 cp $RWFILE $ATTRFILE; chmod 666 $ATTRFILE
 109 mkdir -m 0777 $ATTRDIR
 110 
 111 echo "this is the ext-attr file for $ATTRFILE" | \
 112         runat $ATTRFILE "cat > $ATTRFILE_AT1; chmod 0777 ."
 113 runat $ATTRFILE "cp $ATTRFILE_AT1 $ATTRFILE_AT2; chmod 0 $ATTRFILE_AT2"
 114 cp -@ $ATTRFILE $ATFILE_NP; chmod 0 $ATFILE_NP;
 115 
 116 echo "this is the ext-attr file for $ATTRDIR" | \
 117         runat $ATTRDIR "cat > $ATTRDIR_AT1; chmod 0777 ."
 118 runat $ATTRDIR "cp $ATTRDIR_AT1 $ATTRDIR_AT2; chmod 0 $ATTRDIR_AT2"
 119 cp -@ -r $ATTRDIR $ATDIR_NP; chmod 0 $ATDIR_NP
 120 runat $ATDIR_NP "chmod 0777 ."
 121 
 122 # Make sure owner are set correctly
 123 chown -R 0:10 $TDIR
 124 chmod 0000 $TDIR/$DNOPERM
 125 set +e # End switch here as BASEDIR may be over UFS
 126 
 127 # ZFS requires ACL access to create xattr
 128 df -F zfs $TDIR > /dev/null 2>&1
 129 if (( $? == 0 )); then
 130         set -e
 131         chmod A+everyone@:write_xattr/write_attributes/write_acl:allow \
 132                 . $RWFILE $ATTRFILE $ATTRDIR
 133         chmod A+everyone@:read_xattr:deny \
 134                 $DNOPERM $FNOPERM $ATDIR_NP $ATFILE_NP
 135         set +e
 136 fi
 137 
 138 echo " "
 139 echo "DONE, all test files and directories have now been"
 140 echo "created under [$TDIR]"
 141 echo " "
 142 
 143 exit 0