3 # Test that augeas can create a file based on new paths added to the tree
4 # The tree should retain the paths on a subsequent load operation
7 root=${abs_top_builddir:-.}/build/test-createfile
8 lenses=${abs_top_srcdir:-.}/lenses
10 sysctl_file=/etc/sysctl.d/newfile1.conf
13 mkdir -p $(dirname $root/$sysctl_file)
15 expected_match="/files/etc/sysctl.d/newfile1.conf/net.ipv4.ip_nonlocal_bind = 1"
16 expected_content='net.ipv4.ip_nonlocal_bind = 1'
18 output=$(augtool --nostdinc -r $root -I $lenses <<EOF | grep "$expected_match"
19 set /files/etc/sysctl.d/newfile1.conf/net.ipv4.ip_nonlocal_bind 1
21 match /files/etc/sysctl.d/newfile1.conf/net.ipv4.ip_nonlocal_bind
25 if [[ ! -e $root/$sysctl_file ]]; then
26 echo "Failed to create file $sysctl_file under $root"
28 elif ! diff -bq $root/$sysctl_file <(echo "$expected_content") 1>/dev/null 2>&1; then
29 echo "Contents of $root/sysctl_file are incorrect"
30 cat $root/$sysctl_file
31 echo '-- end of file --'
33 echo "$expected_content"
34 echo '-- end of file --'
36 elif [[ -z "$output" ]]; then
37 echo "Missing /files/$sysctl_file in tree after save"
40 echo "Successfully created $sysctl_file with content:"
41 cat $root/$sysctl_file
42 echo '-- end of file --'
45 sysctl_file=/etc/sysctl.d/newfile2.conf
47 expected_match="/files/etc/sysctl.d/newfile2.conf/net.ipv4.ip_forward = 1"
48 expected_content='net.ipv4.ip_forward = 1'
50 output=$(augtool --nostdinc -r $root -I $lenses <<EOF | grep "$expected_match"
51 set /files/etc/sysctl.d/newfile2.conf/net.ipv4.ip_forward 1
54 match /files/etc/sysctl.d/newfile2.conf/*
59 if [[ ! -e $root/$sysctl_file ]]; then
60 echo "Failed to create file $sysctl_file under $root"
62 elif ! diff -bq $root/$sysctl_file <(echo "$expected_content") 1>/dev/null 2>&1; then
63 echo "Contents of $root/sysctl_file are incorrect"
64 cat $root/$sysctl_file
65 echo '-- end of file --'
67 echo "$expected_content"
68 echo '-- end of file --'
70 elif [[ -z "$output" ]]; then
71 echo "Missing /files/$sysctl_file in tree after save"
74 echo "Successfully created $sysctl_file with content:"
75 cat $root/$sysctl_file
76 echo '-- end of file --'