1 #!/bin/sh 2 3 PROGNAME=$(basename "$0") 4 5 if [ "$1" = '-q' ] ; then 6 QUIET=$1 7 shift 1 8 else 9 QUIET= 10 fi 11 12 PKGDIR=$(realpath "$1") 13 E2ACCESS_DIR=$(realpath "$2") 14 TARGET=$(realpath "$3") 15 16 if [ ! -e "$PKGDIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then 17 cat 1>&2 <<EOF 18 Usage: $PROGNAME [ -q ] <package directory> <e2access directory> <target> 19 20 Package directory: $PKGDIR 21 e2access directory: $E2ACCESS_DIR 22 Target filesystem: $TARGET 23 EOF 24 exit 1 25 fi 26 27 # Initialise the program details and environment. 28 29 E2ACCESS="$E2ACCESS_DIR"/e2access 30 export LD_LIBRARY_PATH="$E2ACCESS_DIR" 31 32 OPTIONS='-u 1000 -g 1000' 33 34 e2access() 35 { 36 "$E2ACCESS" $OPTIONS $* 37 } 38 39 # Make a filesystem for the example. 40 41 mkdir tmp_e2test 42 cd tmp_e2test 43 44 # Set a sensible umask. 45 46 umask 0022 47 48 mkdir -p home/paulb/public 49 echo "Public!" > home/paulb/public/message 50 51 # Set a restrictive umask. 52 53 umask 0077 54 55 echo "Not public!" > home/paulb/public/message2 56 57 mkdir -p home/paulb/private 58 echo "Private!" > home/paulb/private/message 59 60 # Set a permissive umask. 61 62 umask 0000 63 64 mkdir -p home/paulb/shared 65 echo "Editable!" > home/paulb/shared/message 66 67 # Restore the umask for the remaining files. 68 69 umask 0022 70 71 mkdir -p home/paulb/many 72 cd home/paulb/many 73 74 # Populate the directory with plenty of files. 75 76 for N in `seq 1 400`; do 77 echo "Contents of #$N." > "file-$N".txt 78 done 79 80 cd .. 81 82 # Put a file in the directory above. 83 84 cp "$PKGDIR/../docs/LICENCE.txt" . 85 86 # Leave the filesystem root. 87 88 cd ../.. 89 90 # Create a filesystem image. 91 92 EXTRA=2000 93 SIZE=$(du -s -k home | cut -f 1) 94 TOTAL=$(($SIZE + $EXTRA)) 95 96 dd if=/dev/zero of="$TARGET" bs=1024 count=$TOTAL 97 98 if ! $(/sbin/mkfs.ext2 -q "$TARGET") ; then 99 exit 1 100 fi 101 102 # Add the directories and files to the image. 103 104 for DIR in home/paulb/private home/paulb/public home/paulb/shared home/paulb/many home/paulb ; do 105 e2access "$TARGET" make-dirs "$DIR" 106 e2access "$TARGET" copy-in $(find "$DIR" -maxdepth 1 -type f | sort) "$DIR" 107 done 108 109 # Leave the root of the filesystem. 110 111 cd .. 112 113 if [ ! "$QUIET" ] ; then 114 e2access "$TARGET" list-dirs '' 115 e2access "$TARGET" list-dirs 'home' 116 e2access "$TARGET" list-dirs 'home/paulb' 117 e2access "$TARGET" list-dirs 'home/paulb/many' 118 e2access "$TARGET" list-dirs 'home/paulb/private' 119 e2access "$TARGET" list-dirs 'home/paulb/public' 120 e2access "$TARGET" list-dirs 'home/paulb/shared' 121 fi 122 123 rm -r tmp_e2test 124 125 # vim: tabstop=4 expandtab shiftwidth=4