#! /bin/sh #---------------------------------------------------------------------------- # master-diff-config - master file for config file camparison # # Copyright (c) 2001-2003 Ansgar Püster # # Creation: 24.12.2003 ap # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # include function library . /var/install/bin/config_shlib halt() { echo "+++ halt:" read a < /dev/tty } header() { header_$type } header_cd() { clrhome mecho -info "Show difference between current and default configuration" mecho "line 2: $l_source line 1: $r_source" } header_cb() { clrhome mecho -info "Show difference between current and backup configuration" mecho "line 2: $l_source line 1: $r_source" mecho } header_db() { clrhome mecho -info "Show difference between default and a backup configuration" mecho "line 2: $l_source line 1: $r_source" mecho } header_bb() { clrhome mecho -info "Show difference between two backup configurations" mecho "line 2: $l_source line 1: $r_source" mecho } footer() { mecho mecho anykey } strip_file() { in=$1 out=$2 cat ${in} | \ sed 's|^[[:blank:]]*||' | \ sed 's|[[:blank:]]*$||' | \ sed 's| |~|g' | \ grep '^[A-Z]' | \ sed 's|=| |' | \ sed "s|^\([^']*'\)\([^']*'\)\(.*\)|\1\2|"> ${out} chmod og-rw $out } echo_x() { val="$1 " mecho "${val:0:max_len}\c" } get_max_len() { max_len=0 while read var val do [ ${#var} -gt $max_len ] && max_len=${#var} done < $left while read var val do [ ${#var} -gt $max_len ] && max_len=${#var} done < $right max_len=$(expr $max_len + 2) } file_differ() { sort < $left > $left_sort sort < $right > $right_sort chmod og-rw $left_sort $right_sort diff $left_sort $right_sort >/dev/null 2>&1 rc=$? return $rc } clean() { rm -f $right rm -f $left rm -f $right_sort rm -f $left_sort rm -f $diff_file rm -f $both_ucont rm -f $both_cont } # save to o_ set_old () { o_varname=$varname o_varval=$varval } # save to n_ set_new () { n_varname=$varname n_varval=$varval } env_diff() { sed 's/.*/new &/' < $1 > $both_ucont sed 's/.*/old &/' < $2 >> $both_ucont chmod og-rw $both_ucont sort +1 < $both_ucont > $both_cont chmod og-rw $both_cont # indicator for new-line and old-line n_val=0 o_val=0 while read ind varname varval do # new indicator if [ $ind = 'new' ] then if [ $n_val = 1 ] then echo "> $n_varname $n_varval" set_new else set_new n_val=1 fi fi # old indicator if [ $ind = 'old' ] then if [ $o_val = 1 ] then echo "$o_varname $o_varval <" set_old else set_old o_val=1 fi fi # both value are set if [ $n_val = 1 -a $o_val = 1 ] then if [ $n_varname = $o_varname ] then # identical names if [ "$n_varval" = "$o_varval" ] then echo "$o_varname $o_varval $n_varname $n_varval" else echo "$o_varname $o_varval | $n_varname $n_varval" fi o_val=0 n_val=0 else if [[ $n_varname < $o_varname ]] then echo "> $n_varname $n_varval" n_val=0 else echo "$o_varname $o_varval <" o_val=0 fi fi fi done < $both_cont # check remaining names if [ $n_val = 1 ] then echo "> $n_varname $n_varval" n_val=0 fi if [ $o_val = 1 ] then echo "$o_varname $o_varval <" o_val=0 fi } show_detail() { get_max_len header row=4 gotoyx $row 1 #diff -y $left $right > $diff_file env_diff $left_sort $right_sort > $diff_file chmod og-rw $diff_file while read line do set -- $line v1="$1" v2="$2" v3="$3" v4="$4" v5="$5" case $# in 3) if [ "$v1" = ">" ]; then echo_x $v2 mecho "1: - undefined -" echo_x "" mecho '2: '$v3 | sed 's|~| |g' row=$(expr $row + 2) else if [ "$v3" = "<" ]; then echo_x $v1 mecho '1: '$v2 | sed 's|~| |g' echo_x "" mecho "2: - undefined -" row=$(expr $row + 2) else mecho "Error(3): $line" row=$(expr $row + 1) fi fi;; 4) if [ "$v2" != "$v4" ]; then echo_x $v1 mecho '1: '$v2 | sed 's|~| |g' echo_x "" mecho '2: '$v5 | sed 's|~| |g' row=$(expr $row + 2) fi;; 5) case $v3 in \|) echo_x $v1 mecho '1: '$v2 | sed 's|~| |g' echo_x "" mecho '2: '$v5 | sed 's|~| |g' row=$(expr $row + 2) ;; *) mecho "Error(5): $line" row=$(expr $row + 1) ;; esac;; *) mecho "Error($#): $line" row=$(expr $row + 1) ;; esac if [ $row -gt 21 ]; then mecho "Enter return to continue, q to quit:" read answer