1#!/bin/sh 2 3# Regression test for "etcupdate: Do not ignore empty files" 4 5FAILED=no 6WORKDIR=$(pwd)/work 7 8usage() 9{ 10 echo "Usage: empty_file_test.sh [-s script] [-w workdir]" 11 exit 1 12} 13 14COMMAND=etcupdate 15while getopts "s:w:" option; do 16 case $option in 17 s) 18 COMMAND="sh $OPTARG" 19 ;; 20 w) 21 WORKDIR=$OPTARG 22 ;; 23 *) 24 echo 25 usage 26 ;; 27 esac 28done 29shift $((OPTIND - 1)) 30if [ $# -ne 0 ]; then 31 usage 32fi 33 34SRC=$WORKDIR/src 35DEST=$WORKDIR/dest 36TEST=$WORKDIR/test 37 38# Clean up 39rm -rf $WORKDIR 40 41# Create a mock source tree 42mkdir -p $SRC 43touch $SRC/empty_file 44 45# Create a mock make script 46cat > $WORKDIR/mock_make.sh <<EOF 47#!/bin/sh 48 49# Scan all arguments for targets 50for arg in "\$@"; do 51 case \$arg in 52 *=*) 53 # Export variable assignments 54 export "\$arg" 55 ;; 56 distrib-dirs) 57 if [ -n "\$DESTDIR" ]; then 58 mkdir -p "\$DESTDIR/etc" 59 fi 60 ;; 61 distribution) 62 if [ -n "\$DESTDIR" ]; then 63 cp $SRC/empty_file "\$DESTDIR/etc/empty_file" 64 echo "./etc/empty_file type=file mode=0644 uname=root gname=wheel" > "\$DESTDIR/METALOG" 65 fi 66 ;; 67 esac 68done 69exit 0 70EOF 71chmod +x $WORKDIR/mock_make.sh 72 73# Run etcupdate 74# Use -B to skip build targets 75# Use -N to run without root privileges 76# Use 'extract' command to bypass root check in 'update' command 77$COMMAND extract -N -B -s $SRC -d $WORKDIR -m $WORKDIR/mock_make.sh > $WORKDIR/test.out 2>&1 78 79if [ -f $WORKDIR/current/etc/empty_file ]; then 80 echo "Empty file preserved." 81else 82 echo "Empty file missing from current tree." 83 FAILED=yes 84fi 85 86[ "${FAILED}" = no ] 87