paul@154 | 1 | #!/bin/sh |
paul@154 | 2 | |
paul@154 | 3 | THIS_DIR=$(realpath $(dirname "$0")) |
paul@154 | 4 | |
paul@155 | 5 | if [ "$1" = '-q' ] ; then |
paul@155 | 6 | QUIET=$1 |
paul@155 | 7 | shift 1 |
paul@155 | 8 | else |
paul@155 | 9 | QUIET= |
paul@155 | 10 | fi |
paul@155 | 11 | |
paul@154 | 12 | PKGDIR=$1 |
paul@154 | 13 | E2ACCESS_DIR=$2 |
paul@154 | 14 | TARGET=$3 |
paul@154 | 15 | |
paul@154 | 16 | if [ ! -e "$PKGDIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then |
paul@155 | 17 | echo "Usage: $0 [ -q ] <package directory> <e2access directory> <target>" 1>&2 |
paul@154 | 18 | exit 1 |
paul@154 | 19 | fi |
paul@154 | 20 | |
paul@155 | 21 | PKGDIR=`realpath "$PKGDIR"` |
paul@155 | 22 | E2ACCESS_DIR=`realpath "$E2ACCESS_DIR"` |
paul@154 | 23 | TARGET=`realpath "$TARGET"` |
paul@154 | 24 | |
paul@154 | 25 | # Initialise the program details and environment. |
paul@154 | 26 | |
paul@154 | 27 | E2ACCESS="$E2ACCESS_DIR"/e2access |
paul@154 | 28 | export LD_LIBRARY_PATH="$E2ACCESS_DIR" |
paul@154 | 29 | |
paul@154 | 30 | # Make a filesystem for the example. |
paul@154 | 31 | |
paul@154 | 32 | mkdir tmp_e2test |
paul@154 | 33 | cd tmp_e2test |
paul@154 | 34 | mkdir -p home/paulb/many |
paul@154 | 35 | cd home/paulb/many |
paul@154 | 36 | |
paul@154 | 37 | # Populate the directory with plenty of files. |
paul@154 | 38 | |
paul@154 | 39 | for N in `seq 1 400`; do |
paul@154 | 40 | echo "Contents of #$N." > "file-$N".txt |
paul@154 | 41 | done |
paul@154 | 42 | |
paul@154 | 43 | cd .. |
paul@154 | 44 | |
paul@154 | 45 | # Put a file in the directory above. |
paul@154 | 46 | |
paul@154 | 47 | cp "$PKGDIR/../docs/LICENCE.txt" . |
paul@154 | 48 | |
paul@154 | 49 | # Leave the filesystem root. |
paul@154 | 50 | |
paul@154 | 51 | cd ../.. |
paul@154 | 52 | |
paul@154 | 53 | # Create a filesystem image. |
paul@154 | 54 | |
paul@154 | 55 | EXTRA=2000 |
paul@154 | 56 | SIZE=$(du -s -k home | cut -f 1) |
paul@154 | 57 | TOTAL=$(($SIZE + $EXTRA)) |
paul@154 | 58 | |
paul@154 | 59 | dd if=/dev/zero of="$TARGET" bs=1024 count=$TOTAL |
paul@154 | 60 | |
paul@154 | 61 | if ! $(/sbin/mkfs.ext2 -q "$TARGET") ; then |
paul@154 | 62 | exit 1 |
paul@154 | 63 | fi |
paul@154 | 64 | |
paul@154 | 65 | # Add the directory and files to the image. |
paul@154 | 66 | |
paul@154 | 67 | "$E2ACCESS" "$TARGET" --make-dirs home/paulb/many |
paul@154 | 68 | |
paul@154 | 69 | "$E2ACCESS" "$TARGET" --copy-in $(find home/paulb/many -maxdepth 1 -type f | sort) home/paulb/many |
paul@154 | 70 | "$E2ACCESS" "$TARGET" --copy-in $(find home/paulb -maxdepth 1 -type f | sort) home/paulb |
paul@154 | 71 | |
paul@154 | 72 | # Leave the root of the filesystem. |
paul@154 | 73 | |
paul@154 | 74 | cd .. |
paul@154 | 75 | |
paul@155 | 76 | if [ ! "$QUIET" ] ; then |
paul@155 | 77 | "$E2ACCESS" "$TARGET" --list-dirs '' |
paul@155 | 78 | "$E2ACCESS" "$TARGET" --list-dirs 'home' |
paul@155 | 79 | "$E2ACCESS" "$TARGET" --list-dirs 'home/paulb' |
paul@155 | 80 | "$E2ACCESS" "$TARGET" --list-dirs 'home/paulb/many' |
paul@155 | 81 | fi |
paul@154 | 82 | |
paul@154 | 83 | rm -r tmp_e2test |