1 #!/bin/sh 2 3 # Make a test filesystem. 4 # 5 # Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 6 # 7 # This program is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License as 9 # published by the Free Software Foundation; either version 2 of 10 # the License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 # Boston, MA 02110-1301, USA 21 22 PROGNAME=$(basename "$0") 23 24 # Handle program options. 25 26 if [ "$1" = '-q' ] ; then 27 QUIET=$1 28 shift 1 29 else 30 QUIET= 31 fi 32 33 PKGDIR=$(realpath "$1") 34 E2ACCESS_DIR=$(realpath "$2") 35 TARGET=$(realpath "$3") 36 37 shift 3 38 39 if [ ! -e "$PKGDIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then 40 cat 1>&2 <<EOF 41 Usage: $PROGNAME [ -q ] <package directory> <e2access directory> <target> [ <program> ... ] 42 43 Package directory: $PKGDIR 44 e2access directory: $E2ACCESS_DIR 45 Target filesystem: $TARGET 46 Programs: $* 47 EOF 48 exit 1 49 fi 50 51 # Initialise the program details and environment. 52 53 E2ACCESS="$E2ACCESS_DIR"/e2access 54 export LD_LIBRARY_PATH="$E2ACCESS_DIR" 55 56 OPTIONS='-u 1000 -g 1000' 57 58 # Test parameters. 59 # See: tests/dstest_file_readdir.cfg 60 61 MANY_FILES_COUNT=400 62 63 # Define a convenience function for e2access invocation. 64 65 e2access() 66 { 67 "$E2ACCESS" $OPTIONS "$TARGET" $* 68 } 69 70 # Make a filesystem for the example. 71 72 mkdir tmp_e2test 73 cd tmp_e2test 74 75 # Set a sensible umask. 76 77 umask 0022 78 79 mkdir -p home/paulb/public 80 echo "Public!" > home/paulb/public/message 81 82 # Set a restrictive umask. 83 84 umask 0077 85 86 echo "Not public!" > home/paulb/public/message2 87 88 mkdir -p home/paulb/private 89 echo "Private!" > home/paulb/private/message 90 91 # Set a permissive umask. 92 93 umask 0000 94 95 mkdir -p home/paulb/shared 96 echo "Editable!" > home/paulb/shared/message 97 98 # Restore the umask for the remaining files. 99 100 umask 0022 101 102 mkdir -p home/paulb/many 103 cd home/paulb/many 104 105 # Populate the directory with plenty of files. 106 107 for N in `seq 1 $MANY_FILES_COUNT`; do 108 echo "Contents of #$N." > "file-$N".txt 109 done 110 111 cd .. 112 113 # Put file in the created home directory. 114 115 cp "$PKGDIR/../docs/LICENCE.txt" . 116 117 # Put some programs in the same place. 118 119 for PROGRAM in $* ; do 120 cp $(realpath "$PROGRAM") . 121 done 122 123 # Leave the filesystem root. 124 125 cd ../.. 126 127 # Create a filesystem image. 128 129 EXTRA=2000 130 SIZE=$(du -s -k home | cut -f 1) 131 TOTAL=$(($SIZE + $EXTRA)) 132 133 dd if=/dev/zero of="$TARGET" bs=1024 count=$TOTAL 134 135 if ! $(/sbin/mkfs.ext2 -q "$TARGET") ; then 136 exit 1 137 fi 138 139 # Add the directories and files to the image. 140 141 for DIR in home/paulb home/paulb/private home/paulb/public home/paulb/shared home/paulb/many ; do 142 e2access mkdir "$DIR" 143 e2access copy-in $(find "$DIR" -maxdepth 1 -type f | sort) "$DIR" 144 done 145 146 # Leave the root of the filesystem. 147 148 cd .. 149 150 if [ ! "$QUIET" ] ; then 151 e2access ls '' 152 e2access ls 'home' 153 e2access ls 'home/paulb' 154 e2access ls 'home/paulb/many' 155 e2access ls 'home/paulb/private' 156 e2access ls 'home/paulb/public' 157 e2access ls 'home/paulb/shared' 158 fi 159 160 rm -r tmp_e2test 161 162 # vim: tabstop=4 expandtab shiftwidth=4