3 # Check that saving preserves mode and ownership; for this test to make
4 # much sense (if any) the user running it should have at least one
7 root=$abs_top_builddir/build/preserve
12 mkdir -p $(dirname $hosts)
16 ls -il $1 | awk '{ print $1 }'
19 AUGTOOL="augtool --nostdinc -r $root -I $abs_top_srcdir/lenses"
22 printf '127.0.0.1\tlocalhost\n' > $hosts
25 group=$(groups | tr ' ' '\n' | tail -1)
28 [ -x /usr/bin/chcon ] && selinux=yes || selinux=no
29 [ x$SKIP_TEST_PRESERVE_SELINUX = x1 ] && selinux=no
30 if [ $selinux = yes ] ; then
31 /usr/bin/chcon -t etc_t $hosts > /dev/null 2>/dev/null || selinux=no
34 $AUGTOOL >/dev/null <<EOF
35 set /files/etc/hosts/1/alias alias.example.com
39 echo "augtool failed on existing file"
43 act_group=$(ls -l $hosts | sed -e 's/ */ /g' | cut -d ' ' -f 4)
44 act_mode=$(ls -l $hosts | cut -b 1-10)
45 if [ $selinux = yes ] ; then
46 act_con=$(stat --format=%C $hosts | cut -d ':' -f 3)
48 if [ "x$group" != "x$act_group" ] ; then
49 echo "Expected group $group but got $act_group"
53 if [ x-rw------- != "x$act_mode" ] ; then
54 echo "Expected mode 0600 but got $act_mode"
58 if [ $selinux = yes -a xetc_t != "x$act_con" ] ; then
59 echo "Expected SELinux type etc_t but got $act_con"
63 # Check that we create new files without error and with permissions implied
69 $AUGTOOL > /dev/null <<EOF
70 set /files/etc/hosts/1/ipaddr 127.0.0.1
71 set /files/etc/hosts/1/canonical host.example.com
75 echo "augtool failed on new file"
78 if [ ! -e $hosts ]; then
79 echo "augtool didn't create new /etc/hosts file"
82 act_mode=$(ls -l $hosts | cut -b 1-10)
83 if [ x-rw-rw-r-- != "x$act_mode" ] ; then
84 echo "Expected mode 0664 due to $(umask) umask but got $act_mode"
89 # Check that we create new files without error when backups are requested
92 $AUGTOOL -b > /dev/null <<EOF
93 set /files/etc/hosts/1/ipaddr 127.0.0.1
94 set /files/etc/hosts/1/canonical host.example.com
98 echo "augtool -b failed on new file"
102 # Check that we preserve a backup file on request
103 printf '127.0.0.1\tlocalhost\n' > $hosts
104 exp_inode=$(stat_inode $hosts)
106 $AUGTOOL -b > /dev/null <<EOF
107 set /files/etc/hosts/1/alias alias.example.com
112 if [ ! -f $hosts.augsave ] ; then
113 echo "Backup file was not created"
117 act_inode=$(stat_inode $hosts.augsave)
118 if [ "x$act_inode" != "x$exp_inode" ] ; then
119 echo "Backup file's inode changed"
123 act_inode=$(stat_inode $hosts)
124 if [ "x$act_inode" = "x$exp_inode" ] ; then
125 echo "Same inode for backup file and main file"