Postupgrade steps

Hi!

Just update from c167 to c174 and as usual, I had to perform some post-upgrade steps that I want now to automate.

First add some lines to /etc/httpd/conf:

AddType application/x-ns-proxy-autoconfig .dat
AddType application/x-ns-proxy-autoconfig .pac
Redirect permanent /proxy.pac /wpad.dat

Will a simply
echo >> and a restart of apache do the job in a shell script, e.g.

echo AddType application/x-ns-proxy-autoconfig .dat >> /etc/httpd/conf
/etc/init.d/apache restart

I did not dare to add this line to my existing postupgrade.sh so far and just wanted to share above step and ask for experiences.

Second an similar to above, modify a line in /etc/sarg/sarg.conf.
This config already contains the line

# TAG:  resolve_ip yes/no
#       Convert ip address to dns name
#       sarg -n
resolve_ip no

The last line should be replace by resolve_ip dns
A simply echo won’t do the job here, so is there a command that is capable of modifying of text files?

1 Like

see the sed utility.

3 Likes

Oops. my bad. Maybe something like this:

sed -i 's/resolve_ip no/resolve_ip dns/g' /etc/sarg/sarg.conf

see:
https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/


edit:
If you want to make a backup of sarg.conf first you can try this:

sed -i.bak 's/resolve_ip no/resolve_ip dns/g' /etc/sarg/sarg.conf
3 Likes

Thanks @jon that’s exactly what I want and which works perfectly!

Thanks to @redneckmother for pointing into the right direction first :wink:

1 Like

Perl is another way to do the job of text substitution using regular expressions:

perl -i -pe 's/resolve_ip no/resolve_ip dns/g' /etc/sarg/sarg.conf
  • -i: Perl modifies the input file(s) specified by the command, rather than simply printing the output to the console. It changes directly to the file(s) being processed.

  • -p: loop over each line of the input file(s) and automatically print the line after applying the specified code, eliminating the need for writing explicit loops to iterate over the input.

  • -e: execute the code, in this case ‘s/resolve_ip no/resolve_ip dns/g’, which is a regular expression-based substitution pattern (like in the sed solution). It searches for the string “resolve_ip no” and replaces it with “resolve_ip dns” globally (g) in each line (as opposed to only the first occurrence, when g is ommited).

1 Like

This is right!
But in terms of efficiency the streaming editor should be preferred.

5 Likes

Hi, in my system there is only a directory named /etc/httpd/conf - so maybe we should better add one line into /etc/httpd/conf/mime.types
application/x-ns-proxy-autoconfig dat pac