I'm trying to write a bash script which will leverage Augeas to create a conf file in /etc/httpd/conf.d/ and also set up the necessary nodes for the vhost. For some reason I am unable to set the DocumentRoot node. When I try via the interactive shell, I can create it just fine:
[root@panel conf.d]# augtool
augtool> print /files/etc/httpd/conf.d/hey.com.conf/
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
augtool> set /files/etc/httpd/conf.d/hey.com.conf/VirtualHost/*[self::directive='DocumentRoot']/arg "/var/www/vhosts/hey.com"
augtool> print /files/etc/httpd/conf.d/hey.com.conf/
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive/arg = "/var/www/vhosts/hey.com"
augtool> save
Saved 1 file(s)
augtool> quit
[root@panel conf.d]# cat hey.com.conf
<VirtualHost *:80>
DocumentRoot /var/www/vhosts/hey.com
</VirtualHost>
However, my script is unable to create it:
(I put the script in my path for easy execution) Usage example: # aug hey.com
#!/bin/bash
# Set up conf file
name=$1
path="/files/etc/httpd/conf.d/"
conf="$name.conf"
echo ${path}${conf}
docroot="/var/www/vhosts/$name"
# Create Vhost
echo "DocRoot = $docroot"
mkdir $docroot
echo $path$conf
augtool -s set ${path}${conf}/VirtualHost/arg "*:80"
augtool -s set ${path}${conf}/VirtualHost/directive "DocumentRoot"
echo $docroot
echo "Nodes Present"
augtool print ${path}${conf}
#augtool -s set ${path}${conf}/VirtualHost/*[self::directive='DocumentRoot']/arg "$docroot"
augtool -s set /files/etc/httpd/conf.d/hey.com.conf/VirtualHost/*[self::directive=DocumentRoot]/arg /var/www/vhosts/hey.com
augtool print ${path}${conf}
augtool match /augeas//error
As far as I can tell it is trying to do the same command but it fails to write the argument to DocumentRoot. Any help to point me in the right direction or rework my thinking in general would be greatly appreciated.
This is on a CentOS 6.6 box.
Update:
The script creates the file on the fly, so it doesn't exist beforehand. I delete it in between runs of the script. Sample output is as follows:
[root@panel ~]# aug hey.com
/files/etc/httpd/conf.d/hey.com.conf
DocRoot = /var/www/vhosts/hey.com
/files/etc/httpd/conf.d/hey.com.conf
Saved 1 file(s)
Saved 1 file(s)
/var/www/vhosts/hey.com
Nodes Present
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
/augeas/files/etc/sysconfig/iptables.save/error = parse_failed