Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-createfile.sh
1 #!/bin/bash
2 #
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
5 #
6
7 root=${abs_top_builddir:-.}/build/test-createfile
8 lenses=${abs_top_srcdir:-.}/lenses
9
10 sysctl_file=/etc/sysctl.d/newfile1.conf
11
12 rm -rf $root
13 mkdir -p $(dirname $root/$sysctl_file)
14
15 expected_match="/files/etc/sysctl.d/newfile1.conf/net.ipv4.ip_nonlocal_bind = 1"
16 expected_content='net.ipv4.ip_nonlocal_bind = 1'
17
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
20 save
21 match /files/etc/sysctl.d/newfile1.conf/net.ipv4.ip_nonlocal_bind
22 EOF
23 )
24
25 if [[ ! -e $root/$sysctl_file ]]; then
26   echo "Failed to create file $sysctl_file under $root"
27   exit 1
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 --'
32   echo "Expected:"
33   echo "$expected_content"
34   echo '-- end of file --'
35   exit 1
36 elif [[ -z "$output" ]]; then
37   echo "Missing /files/$sysctl_file in tree after save"
38   exit 1
39 else
40   echo "Successfully created $sysctl_file with content:"
41   cat  $root/$sysctl_file
42   echo '-- end of file --'
43 fi
44
45 sysctl_file=/etc/sysctl.d/newfile2.conf
46
47 expected_match="/files/etc/sysctl.d/newfile2.conf/net.ipv4.ip_forward = 1"
48 expected_content='net.ipv4.ip_forward = 1'
49
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
52 save
53 load
54 match /files/etc/sysctl.d/newfile2.conf/*
55 save
56 EOF
57 )
58
59 if [[ ! -e $root/$sysctl_file ]]; then
60   echo "Failed to create file $sysctl_file under $root"
61   exit 1
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 --'
66   echo "Expected:"
67   echo "$expected_content"
68   echo '-- end of file --'
69   exit 1
70 elif [[ -z "$output" ]]; then
71   echo "Missing /files/$sysctl_file in tree after save"
72   exit 1
73 else
74   echo "Successfully created $sysctl_file with content:"
75   cat  $root/$sysctl_file
76   echo '-- end of file --'
77 fi