#!/bin/bash



. /usr/share/preupgrade/common.sh
check_applies_to "squid"
check_rpm_to "" ""
#END GENERATED SECTION

if [ ! -f /etc/squid/squid.conf ] ; then
    exit $RESULT_NOT_APPLICABLE;
fi




# Copy your config file from RHEL6 (in case of scenario RHEL6_7) 
# to Temporary Directory
CONFIG_FILE="/etc/squid/squid.conf"

mkdir -p $VALUE_TMP_PREUPGRADE/cleanconf/$(dirname $CONFIG_FILE)
cp $CONFIG_FILE $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE

#workaround to openscap buggy missing PATH
export PATH=$PATH:/usr/bin
ret=$RESULT_INFORMATIONAL

grep -q "^[[:space:]]*dns_v4_fallback" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* Squid now uses DNS parallel lookups as a replacement for the 'dns_v4_fallback' option. 
  This option will be therefore removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'dns_v4_fallback' option will be erased."
    sed -i -e '/^\([[:space:]]*\)dns_v4_fallback/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
    
fi


grep -i "^[[:space:]]*emulate_httpd_log" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'emulate_httpd_log' option is replaced by a common format option on the 'access_log' directive.
  Modify your 'access_log' directive manually if you want to preserve the behavior of the 'emulate_httpd_log' option.
  This option will be removed from your squid.conf file.
" >> $SOLUTION_FILE
    
    log_slight_risk "The 'emulate_httpd_log' option will be erased."
    sed -i '/^[[:space:]]*emulate_httpd_log/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE 
    ret=$RESULT_FAIL
fi


grep -q "^[[:space:]]*forward_log" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'forward_log' option is now obsolete and will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'forward_log' option will be erased."
    sed -i -e '/^\([[:space:]]*\)forward_log/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi

grep -q "^[[:space:]]*ftp_list_width" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'ftp_list_width' option is now obsolete and will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'ftp_list_width' option will be erased."
    sed -i -e '/^\([[:space:]]*\)ftp_list_width/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi


grep -i "^[[:space:]]*log_fqdn" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'log_fqdn' option is replaced by an automatic detection of the %>A logformat tag.
Modify your logformat directive manually if you want to preserve the behavior of the 'log_fqdn' option.
This option will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'log_fqdn' option will be erased."
    sed -i '/^[[:space:]]log_fqdn/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi 


grep -i "^[[:space:]]*log_ip_on_direct" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'log_ip_on_direct' option is replaced by an automatic detection of the %<A logformat tag.
Modify your logformat directive manually if you want to preserve the behavior of the 'log_ip_on_direct' option.
This option will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'log_ip_on_direct' option will be erased."
    sed -i '/^[[:space:]]log_ip_on_direct/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi 


grep -i "^[[:space:]]*maximum_single_addr_tries" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'maximum_single_addr_tries' option is replaced by the 'connect_retries' option, which operates a little differently.
Modify your squid.conf file manually if you want to preserve the original behavior.
This option will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'maximum_single_addr_tries' option will be erased."
    sed -i '/^[[:space:]]maximum_single_addr_tries/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi 


grep -i "^[[:space:]]*pconn_timeout" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'pconn_timeout' option is replaced by the 'server_idle_pconn_timeout' option.
This option will be therefore modified into the newly introduced 'server_idle_pconn_timeout' option.
" >> $SOLUTION_FILE
    
    log_slight_risk "The 'pconn_timeout' option will be modified."
    sed -i 's/^\([[:space:]]*\)pconn_timeout/\1server_idle_pconn_timeout/' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi 

grep -i "^[[:space:]]*persistent_request_timeout" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'persistent_request_timeout' option is replaced by the 'client_idle_pconn_timeout' option. 
This option will be therefore modified into the newly introduced 'client_idle_pconn_timeout' option.
" >> $SOLUTION_FILE
    
    log_slight_risk "The 'persistent_request_timeout' option will be modified."
    sed -i 's/^\([[:space:]]*\)persistent_request_timeout/\1client_idle_pconn_timeout/' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE 
    ret=$RESULT_FAIL
fi 

grep -i "^[[:space:]]*referr\?er_log" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'referer_log' option is replaced by referrer format option on an access_log directive.
  Modify your access_log directive manually if you want to preserve the behavior of referer option.
  This option will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'referer_log' option will be erased."
    sed -i '/^[[:space:]]*referr\?er_log/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi 

grep -i "^[[:space:]]*url_rewrite_concurrency" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'url_rewrite_concurrency' option is now replaced by 'url_rewrite_children' concurrency.
  This option will be modified into the newly introduced 'url_rewrite_children' concurrency.
" >> $SOLUTION_FILE
    
    log_slight_risk "The 'url_rewrite_concurrency' option will be modified."
    sed -i 's/^\([[:space:]]*\)url_rewrite_concurrency/\1url_rewrite_children concurrency/' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL

fi 

grep -i "^[[:space:]]*useragent_log" $CONFIG_FILE
if [ $? -eq 0 ]; then
    echo "\
* The 'useragent_log' option is replaced by useragent format option on an access_log directive.
  Modify your access_log directive manually if you want to preserve the behavior of the 'useragent_log' option.
  This option will be removed from your squid.conf file.
" >> $SOLUTION_FILE

    log_slight_risk "The 'useragent_log' option will be erased."
    sed -i '/^[[:space:]]*useragent_log/d' $VALUE_TMP_PREUPGRADE/cleanconf/$CONFIG_FILE
    ret=$RESULT_FAIL
fi 


exit $ret
