I want to insert a block of text after a specific line that starts with the word DocumentRoot.
This is the original text (file named li1023-68.members.linode.com):
<VirtualHost *:80>
ServerName li1023-68.members.linode.com
DocumentRoot /srv/www/li1023-68.members.linode.com/public_html/
ErrorLog /srv/www/li1023-68.members.linode.com/logs/error.log
CustomLog /srv/www/li1023-68.members.linode.com/logs/access.log combined
</VirtualHost>
This is what I want to achieve:
<VirtualHost *:80>
ServerName li1023-68.members.linode.com
DocumentRoot /srv/www/li1023-68.members.linode.com/public_html/
<Directory /srv/www/$path/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /srv/www/li1023-68.members.linode.com/logs/error.log
CustomLog /srv/www/li1023-68.members.linode.com/logs/access.log combined
</VirtualHost>
I tried doing so with the following code and it doesn't work. $path holds the name of the text that should be modified (ie li1023-68.members.linode.com):
value="<Directory /srv/www/$path/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>"
sed '/DocumentRoot.*$/a $value' /etc/apache2/sites-available/$path
while read line
do
echo $line
echo $line | grep -q "DocumentRoot"
[ $? -eq 0 ] && echo "$value"
done < $path
What am I missing?