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