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