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