Advertisement
Guest User

etc-update

a guest
Nov 3rd, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 17.15 KB | None | 0 0
  1. #!/bin/bash
  2. # Copyright 1999-2011 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4.  
  5. # Author Brandon Low <lostlogic@gentoo.org>
  6. #
  7. # Previous version (from which I've borrowed a few bits) by:
  8. # Jochem Kossen <j.kossen@home.nl>
  9. # Leo Lipelis <aeoo@gentoo.org>
  10. # Karl Trygve Kalleberg <karltk@gentoo.org>
  11.  
  12. cd /
  13.  
  14. if type -P gsed >/dev/null ; then
  15.     sed() { gsed "$@"; }
  16. fi
  17.  
  18. get_config() {
  19.     # the sed here does:
  20.     #  - strip off comments
  21.     #  - match lines that set item in question
  22.     #    - delete the "item =" part
  23.     #    - store the actual value into the hold space
  24.     #  - on the last line, restore the hold space and print it
  25.     # If there's more than one of the same configuration item, then
  26.     # the store to the hold space clobbers previous value so the last
  27.     # setting takes precedence.
  28.     local item=$1
  29.     eval echo $(sed -n \
  30.         -e 's:[[:space:]]*#.*$::' \
  31.         -e "/^[[:space:]]*$item[[:space:]]*=/{s:[^=]*=[[:space:]]*\([\"']\{0,1\}\)\(.*\)\1:\2:;h}" \
  32.         -e '${g;p}' \
  33.         "${PORTAGE_CONFIGROOT}"etc/etc-update.conf)
  34. }
  35.  
  36. diff_command() {
  37.     local cmd=${diff_command//%file1/$1}
  38.     ${cmd//%file2/$2}
  39. }
  40.  
  41. scan() {
  42.     echo "Scanning Configuration files..."
  43.     rm -rf ${TMP}/files > /dev/null 2>&1
  44.     mkdir ${TMP}/files || die "Failed mkdir command!" 1
  45.     count=0
  46.     input=0
  47.     local find_opts
  48.     local my_basename
  49.  
  50.     for path in ${CONFIG_PROTECT} ; do
  51.         path="${ROOT}${path}"
  52.         # Do not traverse hidden directories such as .svn or .git.
  53.         find_opts="-name .* -type d -prune -o -name ._cfg????_*"
  54.         if [ ! -d "${path}" ]; then
  55.             [ ! -f "${path}" ] && continue
  56.             my_basename="${path##*/}"
  57.             path="${path%/*}"
  58.             find_opts="-maxdepth 1 -name ._cfg????_${my_basename}"
  59.         fi
  60.  
  61.         ofile=""
  62.         # The below set -f turns off file name globbing in the ${find_opts} expansion.
  63.         for file in $(set -f ; find ${path}/ ${find_opts} \
  64.                ! -name '.*~' ! -iname '.*.bak' -print |
  65.                sed -e "s:\(^.*/\)\(\._cfg[0-9]*_\)\(.*$\):\1\2\3\%\1%\2\%\3:" |
  66.                sort -t'%' -k2,2 -k4,4 -k3,3 | LANG=POSIX LC_ALL=POSIX cut -f1 -d'%'); do
  67.  
  68.             rpath=$(echo "${file/\/\///}" | sed -e "s:/[^/]*$::")
  69.             rfile=$(echo "${file/\/\///}" | sed -e "s:^.*/::")
  70.             for mpath in ${CONFIG_PROTECT_MASK}; do
  71.                 mpath="${ROOT}${mpath}"
  72.                 mpath=$(echo "${mpath/\/\///}")
  73.                 if [[ "${rpath}" == "${mpath}"* ]]; then
  74.                     mv ${rpath}/${rfile} ${rpath}/${rfile:10}
  75.                     break
  76.                 fi
  77.             done
  78.             if [[ ! -f ${file} ]] ; then
  79.                 echo "Skipping non-file ${file} ..."
  80.                 continue
  81.             fi
  82.  
  83.             if [[ "${ofile:10}" != "${rfile:10}" ]] ||
  84.                [[ ${opath} != ${rpath} ]]; then
  85.                 MATCHES=0
  86.                 if [[ "${EU_AUTOMERGE}" == "yes" ]]; then
  87.                     if [ ! -e "${rpath}/${rfile}" ] || [ ! -e "${rpath}/${rfile:10}" ]; then
  88.                         MATCHES=0
  89.                     else
  90.                         diff -Bbua ${rpath}/${rfile} ${rpath}/${rfile:10} | egrep '^[+-]' | egrep -v '^[+-][\t ]*#|^--- |^\+\+\+ ' | egrep -qv '^[-+][\t ]*$'
  91.                         MATCHES=$?
  92.                     fi
  93.                 elif [[ -z $(diff -Nua ${rpath}/${rfile} ${rpath}/${rfile:10}|
  94.                               grep "^[+-][^+-]"|grep -v '# .Header:.*') ]]; then
  95.                     MATCHES=1
  96.                 fi
  97.                 if [[ "${MATCHES}" == "1" ]]; then
  98.                     echo "Automerging trivial changes in: ${rpath}/${rfile:10}"
  99.                     mv ${rpath}/${rfile} ${rpath}/${rfile:10}
  100.                     continue
  101.                 else
  102.                     count=${count}+1
  103.                     echo "${rpath}/${rfile:10}" > ${TMP}/files/${count}
  104.                     echo "${rpath}/${rfile}" >> ${TMP}/files/${count}
  105.                     ofile="${rfile}"
  106.                     opath="${rpath}"
  107.                     continue
  108.                 fi
  109.             fi
  110.  
  111.             if [[ -z $(diff -Nua ${rpath}/${rfile} ${rpath}/${ofile}|
  112.                       grep "^[+-][^+-]"|grep -v '# .Header:.*') ]]; then
  113.                 mv ${rpath}/${rfile} ${rpath}/${ofile}
  114.                 continue
  115.             else
  116.                 echo "${rpath}/${rfile}" >> ${TMP}/files/${count}
  117.                 ofile="${rfile}"
  118.                 opath="${rpath}"
  119.             fi
  120.         done
  121.     done
  122.  
  123. }
  124.  
  125. sel_file() {
  126.     local -i isfirst=0
  127.     until [[ -f ${TMP}/files/${input} ]] || \
  128.           [[ ${input} == -1 ]] || \
  129.           [[ ${input} == -3 ]]
  130.     do
  131.         local numfiles=$(ls ${TMP}/files|wc -l)
  132.         local numwidth=${#numfiles}
  133.         for file in $(ls ${TMP}/files|sort -n); do
  134.             if [[ ${isfirst} == 0 ]] ; then
  135.                 isfirst=${file}
  136.             fi
  137.             numshow=$(printf "%${numwidth}i${PAR} " ${file})
  138.             numupdates=$(( $(wc -l <${TMP}/files/${file}) - 1 ))
  139.             echo -n "${numshow}"
  140.             if [[ ${mode} == 0 ]] ; then
  141.                 echo "$(head -n1 ${TMP}/files/${file}) (${numupdates})"
  142.             else
  143.                 head -n1 ${TMP}/files/${file}
  144.             fi
  145.         done > ${TMP}/menuitems
  146.  
  147.         if [ "${OVERWRITE_ALL}" == "yes" ]; then
  148.             input=0
  149.         elif [ "${DELETE_ALL}" == "yes" ]; then
  150.             input=0
  151.         else
  152.             [[ $CLEAR_TERM == yes ]] && clear
  153.             if [[ ${mode} == 0 ]] ; then
  154.                 echo "The following is the list of files which need updating, each
  155. configuration file is followed by a list of possible replacement files."
  156.             else
  157.                 local my_title="Please select a file to update"
  158.             fi
  159.  
  160.             if [[ ${mode} == 0 ]] ; then
  161.                 cat ${TMP}/menuitems
  162.                 echo    "Please select a file to edit by entering the corresponding number."
  163.                 echo    "              (don't use -3, -5, -7 or -9 if you're unsure what to do)"
  164.                 echo    "              (-1 to exit) (-3 to auto merge all remaining files)"
  165.                 echo    "                           (-5 to auto-merge AND not use 'mv -i')"
  166.                 echo    "                           (-7 to discard all updates)"
  167.                 echo -n "                           (-9 to discard all updates AND not use 'rm -i'): "
  168.                 input=$(read_int)
  169.             else
  170.                 dialog --title "${title}" --menu "${my_title}" \
  171.                     0 0 0 $(echo -e "-1 Exit\n$(<${TMP}/menuitems)") \
  172.                     2> ${TMP}/input || die "User termination!" 0
  173.                 input=$(<${TMP}/input)
  174.             fi
  175.             if [[ ${input} == -9 ]]; then
  176.                 read -p "Are you sure that you want to delete all updates (type YES):" reply
  177.                 if [[ ${reply} != "YES" ]]; then
  178.                     continue
  179.                 else
  180.                     input=-7
  181.                     export rm_opts=""
  182.                 fi
  183.             fi
  184.             if [[ ${input} == -7 ]]; then
  185.                 input=0
  186.                 export DELETE_ALL="yes"
  187.             fi
  188.             if [[ ${input} == -5 ]] ; then
  189.                 input=-3
  190.                 export mv_opts=" ${mv_opts} "
  191.                 mv_opts="${mv_opts// -i / }"
  192.             fi
  193.             if [[ ${input} == -3 ]] ; then
  194.                 input=0
  195.                 export OVERWRITE_ALL="yes"
  196.             fi
  197.         fi # -3 automerge
  198.         if [[ -z ${input} ]] || [[ ${input} == 0 ]] ; then
  199.             input=${isfirst}
  200.         fi
  201.     done
  202. }
  203.  
  204. user_special() {
  205.     if [ -r ${PORTAGE_CONFIGROOT}etc/etc-update.special ]; then
  206.         if [ -z "$1" ]; then
  207.             echo "ERROR: user_special() called without arguments"
  208.             return 1
  209.         fi
  210.         while read -r pat; do
  211.             echo ${1} | grep "${pat}" > /dev/null && return 0
  212.         done < ${PORTAGE_CONFIGROOT}etc/etc-update.special
  213.     fi
  214.     return 1
  215. }
  216.  
  217. read_int() {
  218.     # Read an integer from stdin.  Continously loops until a valid integer is
  219.     # read.  This is a workaround for odd behavior of bash when an attempt is
  220.     # made to store a value such as "1y" into an integer-only variable.
  221.     local my_input
  222.     while true; do
  223.         read my_input
  224.         # failed integer conversions will break a loop unless they're enclosed
  225.         # in a subshell.
  226.         echo "${my_input}" | ( declare -i x; read x) 2>/dev/null && break
  227.         echo -n "Value '$my_input' is not valid. Please enter an integer value:" >&2
  228.     done
  229.     echo ${my_input}
  230. }
  231.  
  232. do_file() {
  233.     interactive_echo() { [ "${OVERWRITE_ALL}" != "yes" ] && [ "${DELETE_ALL}" != "yes" ] && echo; }
  234.     interactive_echo
  235.     local -i my_input
  236.     local -i fcount=0
  237.     until (( $(wc -l < ${TMP}/files/${input}) < 2 )); do
  238.         my_input=0
  239.         if (( $(wc -l < ${TMP}/files/${input}) == 2 )); then
  240.             my_input=1
  241.         fi
  242.         until (( ${my_input} > 0 )) && (( ${my_input} < $(wc -l < ${TMP}/files/${input}) )); do
  243.             fcount=0
  244.  
  245.             if [ "${OVERWRITE_ALL}" == "yes" ]; then
  246.                 my_input=0
  247.             elif [ "${DELETE_ALL}" == "yes" ]; then
  248.                 my_input=0
  249.             else
  250.                 for line in $(<${TMP}/files/${input}); do
  251.                     if (( ${fcount} > 0 )); then
  252.                         echo -n "${fcount}${PAR} "
  253.                         echo "${line}"
  254.                     else
  255.                         if [[ ${mode} == 0 ]] ; then
  256.                             echo "Below are the new config files for ${line}:"
  257.                         else
  258.                             local my_title="Please select a file to process for ${line}"
  259.                         fi
  260.                     fi
  261.                     fcount=${fcount}+1
  262.                 done > ${TMP}/menuitems
  263.  
  264.                 if [[ ${mode} == 0 ]] ; then
  265.                     cat ${TMP}/menuitems
  266.                     echo -n "Please select a file to process (-1 to exit this file): "
  267.                     my_input=$(read_int)
  268.                 else
  269.                     dialog --title "${title}" --menu "${my_title}" \
  270.                         0 0 0 $(echo -e "$(<${TMP}/menuitems)\n${fcount} Exit") \
  271.                         2> ${TMP}/input || die "User termination!" 0
  272.                     my_input=$(<${TMP}/input)
  273.                 fi
  274.             fi # OVERWRITE_ALL
  275.  
  276.             if [[ ${my_input} == 0 ]] ; then
  277.                 my_input=1
  278.             elif [[ ${my_input} == -1 ]] ; then
  279.                 input=0
  280.                 return
  281.             elif [[ ${my_input} == ${fcount} ]] ; then
  282.                 break
  283.             fi
  284.         done
  285.         if [[ ${my_input} == ${fcount} ]] ; then
  286.             break
  287.         fi
  288.  
  289.         fcount=${my_input}+1
  290.  
  291.         file=$(sed -e "${fcount}p;d" ${TMP}/files/${input})
  292.         ofile=$(head -n1 ${TMP}/files/${input})
  293.  
  294.         do_cfg "${file}" "${ofile}"
  295.  
  296.         sed -e "${fcount}!p;d" ${TMP}/files/${input} > ${TMP}/files/sed
  297.         mv ${TMP}/files/sed ${TMP}/files/${input}
  298.  
  299.         if [[ ${my_input} == -1 ]] ; then
  300.             break
  301.         fi
  302.     done
  303.     interactive_echo
  304.     rm ${TMP}/files/${input}
  305.     count=${count}-1
  306. }
  307.  
  308. do_cfg() {
  309.  
  310.     local file="${1}"
  311.     local ofile="${2}"
  312.     local -i my_input=0
  313.  
  314.     until (( ${my_input} == -1 )) || [ ! -f ${file} ]; do
  315.         if [[ "${OVERWRITE_ALL}" == "yes" ]] && ! user_special "${ofile}"; then
  316.             my_input=1
  317.         elif [[ "${DELETE_ALL}" == "yes" ]] && ! user_special "${ofile}"; then
  318.             my_input=2
  319.         else
  320.             [[ $CLEAR_TERM == yes ]] && clear
  321.             if [ "${using_editor}" == 0 ]; then
  322.                 (
  323.                     echo "Showing differences between ${ofile} and ${file}"
  324.                     diff_command "${ofile}" "${file}"
  325.                 ) | ${pager}
  326.             else
  327.                 echo "Beginning of differences between ${ofile} and ${file}"
  328.                 diff_command "${ofile}" "${file}"
  329.                 echo "End of differences between ${ofile} and ${file}"
  330.             fi
  331.             if [ -L "${file}" ]; then
  332.                 echo
  333.                 echo "-------------------------------------------------------------"
  334.                 echo "NOTE: File is a symlink to another file. REPLACE recommended."
  335.                 echo "      The original file may simply have moved. Please review."
  336.                 echo "-------------------------------------------------------------"
  337.                 echo
  338.             fi
  339.             echo -n "File: ${file}
  340. 1) Replace original with update
  341. 2) Delete update, keeping original as is
  342. 3) Interactively merge original with update
  343. 4) Show differences again
  344. 5) Save update as example config
  345. Please select from the menu above (-1 to ignore this update): "
  346.             my_input=$(read_int)
  347.         fi
  348.  
  349.         case ${my_input} in
  350.             1) echo "Replacing ${ofile} with ${file}"
  351.                mv ${mv_opts} ${file} ${ofile}
  352.                [ -n "${OVERWRITE_ALL}" ] && my_input=-1
  353.                continue
  354.                ;;
  355.             2) echo "Deleting ${file}"
  356.                rm ${rm_opts} ${file}
  357.                [ -n "${DELETE_ALL}" ] && my_input=-1
  358.                continue
  359.                ;;
  360.             3) do_merge "${file}" "${ofile}"
  361.                my_input=${?}
  362. #              [ ${my_input} == 255 ] && my_input=-1
  363.                continue
  364.                ;;
  365.             4) continue
  366.                ;;
  367.             5) do_distconf "${file}" "${ofile}"
  368.                ;;
  369.             *) continue
  370.                ;;
  371.         esac
  372.     done
  373. }
  374.  
  375. do_merge() {
  376.     # make sure we keep the merged file in the secure tempdir
  377.     # so we dont leak any information contained in said file
  378.     # (think of case where the file has 0600 perms; during the
  379.     # merging process, the temp file gets umask perms!)
  380.  
  381.     local file="${1}"
  382.     local ofile="${2}"
  383.     local mfile="${TMP}/${2}.merged"
  384.     local -i my_input=0
  385.     echo "${file} ${ofile} ${mfile}"
  386.  
  387.     if [[ -e ${mfile} ]] ; then
  388.         echo "A previous version of the merged file exists, cleaning..."
  389.         rm ${rm_opts} "${mfile}"
  390.     fi
  391.  
  392.     # since mfile will be like $TMP/path/to/original-file.merged, we
  393.     # need to make sure the full /path/to/ exists ahead of time
  394.     mkdir -p "${mfile%/*}"
  395.  
  396.     until (( ${my_input} == -1 )); do
  397.         echo "Merging ${file} and ${ofile}"
  398.         $(echo "${merge_command}" |
  399.          sed -e "s:%merged:${mfile}:g" \
  400.              -e "s:%orig:${ofile}:g" \
  401.              -e "s:%new:${file}:g")
  402.         until (( ${my_input} == -1 )); do
  403.             echo -n "1) Replace ${ofile} with merged file
  404. 2) Show differences between merged file and original
  405. 3) Remerge original with update
  406. 4) Edit merged file
  407. 5) Return to the previous menu
  408. Please select from the menu above (-1 to exit, losing this merge): "
  409.             my_input=$(read_int)
  410.             case ${my_input} in
  411.                 1) echo "Replacing ${ofile} with ${mfile}"
  412.                    if  [[ ${USERLAND} == BSD ]] ; then
  413.                        chown "$(stat -f %Su:%Sg "${ofile}")" "${mfile}"
  414.                        chmod $(stat -f %Mp%Lp "${ofile}") "${mfile}"
  415.                    else
  416.                        chown --reference="${ofile}" "${mfile}"
  417.                        chmod --reference="${ofile}" "${mfile}"
  418.                    fi
  419.                    mv ${mv_opts} "${mfile}" "${ofile}"
  420.                    rm ${rm_opts} "${file}"
  421.                    return 255
  422.                    ;;
  423.                 2)
  424.                     [[ $CLEAR_TERM == yes ]] && clear
  425.                     if [ "${using_editor}" == 0 ]; then
  426.                         (
  427.                             echo "Showing differences between ${ofile} and ${mfile}"
  428.                             diff_command "${ofile}" "${mfile}"
  429.                         ) | ${pager}
  430.                     else
  431.                         echo "Beginning of differences between ${ofile} and ${mfile}"
  432.                         diff_command "${ofile}" "${mfile}"
  433.                         echo "End of differences between ${ofile} and ${mfile}"
  434.                     fi
  435.                    continue
  436.                    ;;
  437.                 3) break
  438.                    ;;
  439.                 4) ${EDITOR:-nano -w} "${mfile}"
  440.                    continue
  441.                      ;;
  442.                 5) rm ${rm_opts} "${mfile}"
  443.                    return 0
  444.                    ;;
  445.                 *) continue
  446.                    ;;
  447.             esac
  448.         done
  449.     done
  450.     rm ${rm_opts} "${mfile}"
  451.     return 255
  452. }
  453.  
  454. do_distconf() {
  455.     # search for any previously saved distribution config
  456.     # files and number the current one accordingly
  457.  
  458.     local file="${1}"
  459.     local ofile="${2}"
  460.     local -i count
  461.     local -i fill
  462.     local suffix
  463.     local efile
  464.  
  465.     for ((count = 0; count <= 9999; count++)); do
  466.         suffix=".dist_"
  467.         for ((fill = 4 - ${#count}; fill > 0; fill--)); do
  468.             suffix+="0"
  469.         done
  470.         suffix+="${count}"
  471.         efile="${ofile}${suffix}"
  472.         if [[ ! -f ${efile} ]]; then
  473.             mv ${mv_opts} "${file}" "${efile}"
  474.             break
  475.         elif diff_command "${file}" "${efile}" &> /dev/null; then
  476.             # replace identical copy
  477.             mv "${file}" "${efile}"
  478.             break
  479.         fi
  480.     done
  481. }
  482.  
  483. die() {
  484.     trap SIGTERM
  485.     trap SIGINT
  486.  
  487.     if [ "$2" -eq 0 ]; then
  488.         echo "Exiting: ${1}"
  489.         scan > /dev/null
  490.         [ ${count} -gt 0 ] && echo "NOTE: ${count} updates remaining"
  491.     else
  492.         echo "ERROR: ${1}"
  493.     fi
  494.  
  495.     rm -rf "${TMP}"
  496.     exit ${2}
  497. }
  498.  
  499. usage() {
  500.     cat <<-EOF
  501.     etc-update: Handle configuration file updates
  502.  
  503.     Usage: etc-update [options]
  504.  
  505.     Options:
  506.       -d, --debug    Enable shell debugging
  507.       -h, --help     Show help and run away
  508.       -V, --version  Show version and trundle away
  509.     EOF
  510.  
  511.     [[ -n ${*:2} ]] && printf "\nError: %s\n" "${*:2}" 1>&2
  512.  
  513.     exit ${1:-0}
  514. }
  515.  
  516. #
  517. # Run the script
  518. #
  519.  
  520. SET_X=false
  521. while [[ -n $1 ]] ; do
  522.     case $1 in
  523.         -d|--debug)   SET_X=true;;
  524.         -h|--help)    usage;;
  525.         -V|--version) emerge --version ; exit 0;;
  526.         *)            usage 1 "Invalid option '$1'";;
  527.     esac
  528.     shift
  529. done
  530. ${SET_X} && set -x
  531.  
  532. type portageq > /dev/null || exit $?
  533. eval $(portageq envvar -v CONFIG_PROTECT \
  534.     CONFIG_PROTECT_MASK PORTAGE_CONFIGROOT PORTAGE_TMPDIR ROOT USERLAND)
  535. export PORTAGE_TMPDIR
  536.  
  537. TMP="${PORTAGE_TMPDIR}/etc-update-$$"
  538. trap "die terminated 1" SIGTERM
  539. trap "die interrupted 1" SIGINT
  540.  
  541. [ -w ${PORTAGE_CONFIGROOT}etc ] || die "Need write access to ${PORTAGE_CONFIGROOT}etc" 1
  542. #echo $PORTAGE_TMPDIR
  543. #echo $CONFIG_PROTECT
  544. #echo $CONFIG_PROTECT_MASK
  545. #export PORTAGE_TMPDIR=$(/usr/lib/portage/bin/portageq envvar PORTAGE_TMPDIR)
  546.  
  547. rm -rf "${TMP}" 2> /dev/null
  548. mkdir "${TMP}" || die "failed to create temp dir" 1
  549. # make sure we have a secure directory to work in
  550. chmod 0700 "${TMP}" || die "failed to set perms on temp dir" 1
  551. chown ${UID:-0}:${GID:-0} "${TMP}" || die "failed to set ownership on temp dir" 1
  552.  
  553. # I need the CONFIG_PROTECT value
  554. #CONFIG_PROTECT=$(/usr/lib/portage/bin/portageq envvar CONFIG_PROTECT)
  555. #CONFIG_PROTECT_MASK=$(/usr/lib/portage/bin/portageq envvar CONFIG_PROTECT_MASK)
  556.  
  557. # load etc-config's configuration
  558. CLEAR_TERM=$(get_config clear_term)
  559. EU_AUTOMERGE=$(get_config eu_automerge)
  560. rm_opts=$(get_config rm_opts)
  561. mv_opts=$(get_config mv_opts)
  562. cp_opts=$(get_config cp_opts)
  563. pager=$(get_config pager)
  564. diff_command=$(get_config diff_command)
  565. using_editor=$(get_config using_editor)
  566. merge_command=$(get_config merge_command)
  567. declare -i mode=$(get_config mode)
  568. [[ -z ${mode} ]] && mode=0
  569. [[ -z ${pager} ]] && pager="cat"
  570.  
  571. if [ "${using_editor}" == 0 ]; then
  572.     # Sanity check to make sure diff exists and works
  573.     echo > "${TMP}"/.diff-test-1
  574.     echo > "${TMP}"/.diff-test-2
  575.    
  576.     if ! diff_command "${TMP}"/.diff-test-1 "${TMP}"/.diff-test-2 ; then
  577.         die "'${diff_command}' does not seem to work, aborting" 1
  578.     fi
  579. else
  580.     if ! type ${diff_command%% *} >/dev/null; then
  581.         die "'${diff_command}' does not seem to work, aborting" 1
  582.     fi
  583. fi
  584.  
  585. if [[ ${mode} == "1" ]] ; then
  586.     if ! type dialog >/dev/null || ! dialog --help >/dev/null ; then
  587.         die "mode=1 and 'dialog' not found or not executable, aborting" 1
  588.     fi
  589. fi
  590.  
  591. #echo "rm_opts: $rm_opts, mv_opts: $mv_opts, cp_opts: $cp_opts"
  592. #echo "pager: $pager, diff_command: $diff_command, merge_command: $merge_command"
  593.  
  594. if (( ${mode} == 0 )); then
  595.     PAR=")"
  596. else
  597.     PAR=""
  598. fi
  599.  
  600. declare -i count=0
  601. declare input=0
  602. declare title="Gentoo's etc-update tool!"
  603.  
  604. scan
  605.  
  606. until (( ${input} == -1 )); do
  607.     if (( ${count} == 0 )); then
  608.         die "Nothing left to do; exiting. :)" 0
  609.     fi
  610.     sel_file
  611.     if (( ${input} != -1 )); then
  612.         do_file
  613.     fi
  614. done
  615.  
  616. die "User termination!" 0
  617.  
  618.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement