[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: CTRL+ALT+Backspace will kill the X-server



On Fri, Nov 21, 2003 at 12:00:32PM -0500, David Z Maze wrote:
> "Sridhar M.A." <mas@uomphysics.net> writes:
> 
> > If you want to temporarily disable booting to xdm on your VT100 and
> > revert to xdm once you get back the monitor, just disable the xdm
> > startup from all levels.
> >
> >    # update-rc.d -f xdm remove
> >
> > After you get back the monitor,
> >
> >    # update-rc.d xdm defaults
> 
> Neither of these are the right answer.  (a) will cause the /etc/rc?.d
> links to be put back into place if the package gets upgraded; (b) will
> put the links back, but at the wrong priority, so xdm would get
> started before things like cron.  Not a huge deal, but it's probably
> easier to leave one runlevel (say, 5) in the "pristine" state; delete
> /etc/rc2.d/S99xdm if you don't want xdm to start, and then use 'ln -s'
> to make a link identical to what's in /etc/rc5.d if you want to bring
> it back.
> 

I have written a bash script to remove/restore any file entry
  in '/etc/init.d',
including ALL links and save them
  to '/etc/init.d/SAVE/'           as <file>.tar.gz.



e.g. "init.d -s xdm"
      saves /etc/init.d/xdm and ALL links referring to xdm 
      to "/etc/init.d/SAVE/xdm.tar.gz

     "init.d -r xdm" will restore xdm and ALL links to place

The advantage: any change made to "xdm" or to any link adjustment will
be saved and, if needed, later restored to its original state.

One can easily test the system's reaction to removing a file, and, if
problems show up, restore the file.




Here is this script:       (on my system stored in '/usr/local/sh')
---------------------


#!/bin/sh

# \wwf 9.3.02

USE ()	{
  echo
  echo "========================================================"
  echo "Save+Remove // Restore  Start_Stop Files in /etc/init.d/"
  echo "========================================================"
  setterm -bold on
  echo 'including related Links in   /etc/rc?.d/'
  setterm -bold off
  echo
  echo
  echo "usage:"
  echo
  echo "$0  [{-s|-r}] <fname ...>    (-s = default)"
  echo "--------------------------------------------------------"
  echo '( put Filename Wildcards in Double-Quotes:   "*",  "?" )'
  echo
  echo
  echo 'Options:'
  echo '--------'
  echo '-s = (S)ave    files to   /etc/init.d/SAVE/<file>.tar.gz'
  echo '-r = (R)estore files from /etc/init.d/SAVE/<file>.tar.gz'
  echo
  echo '(-s:  Files are MOVED from Directories to Archive)'
  echo '(-r:  Files are MOVED from Archive to Directories)'
  echo
  echo
}


Save ()	{
  test -d /etc/init.d/SAVE || mkdir /etc/init.d/SAVE

  echo "Save+Deinstall init.d Files to /etc/init.d/SAVE/<file>.tar.gz"
  echo "============================================================="
  cd /etc/init.d
  for FILE in ${@}; do
    echo

#   Skip bad Params
    if [ ! -f ${FILE} ]; then
      echo "/etc/init.d/${FILE}:  NO FILE -- skipping Param"
      echo "------------------------------------------------------"
	  echo
      continue		## comment this line: save links only
#					## when /etc/init.d/<file> is missing
    fi

    if [ -f SAVE/${FILE}.tar.gz ]; then
      echo "Dest_Archive already exists:"
      echo "NO REwriting to /etc/SAVE/${FILE}.tar.gz -- skipping Param"
      echo "----------------------------------------------------------"
	  echo
      continue
    fi

#   Begin of Job
    echo -n "Save+Deinstall /etc/init.d/${FILE} ? "; read answ
    case "$answ" in
      y*|Y*|j*|J*)	echo "Answer = ${answ}";;	# Save Files
      *          )	echo "Answer = ${answ}:    NO Action -- skipping Param"
					echo
					continue
    esac

    echo
    echo Saving spec''d Files to /etc/init.d/SAVE/${FILE}.tar.gz
    echo "---------------------------------------------------------"
    find /etc/rc* /etc/init.d -name "*${FILE}" | \
	tar -cvzf /etc/init.d/SAVE/${FILE}.tar.gz -PT -
    echo
    echo "Comparing Tar Archive to orig. Source Files"
    echo "-------------------------------------------"
    tar -dvzf /etc/init.d/SAVE/${FILE}.tar.gz

    if [ `echo $?` = 0 ]; then
      echo
      echo "=================="
      echo "All Files saved OK"
      echo "=================="
      echo
      echo -n "Remove saved Source Files now ? "; read answ
      case "$answ" in
        y*|Y*|j*|J*) echo "Answer = ${answ}";;	# Remove Files
        *          ) echo "Answer = ${answ}: Files NOT removed"
i					 echo
                     continue
      esac
      echo
      echo "Removing saved Files from /etc/rc*/   /etc/init.a/"
      find /etc/rc* /etc/init.d -name "*${FILE}" -exec rm {} \;
    else
      echo
      echo "ERROR, BAD Match!!"
      echo "=================="
      echo "/etc/init.d/SAVE/${FILE}.tar.gz differs to"
      echo "Source Files in /etc/rc*/, /etc/init.d/"
      echo "NO File removed"
      echo
    fi
  done
}


Restore ()	{
  echo "Reinstall Files from /etc/init.d/SAVE/<file>.tar.gz"
  echo "---------------------------------------------------"
  cd /etc/init.d/SAVE/
  for FILE in ${@}; do
    echo
    ARCHIV=""
    [ -f ${FILE} ] && ARCHIV=${FILE}
    [ -f ${FILE}.tar.gz ] && ARCHIV=${FILE}.tar.gz
##  echo "File = " ${FILE} "Archive = " ${ARCHIV}; read answ

    if [ -z ${ARCHIV} ]; then
      echo "NO matching Archive: " ${FILE} "-- skipping Param"
	  echo
      continue
    fi

    echo -n "Reinstall ${ARCHIV} ? "; read answ

    case "$answ" in
      y*|Y*|j*|J*) ;;		# Answer = 'yes', start Job
      *          ) echo "Answer = ${answ}: NO Action taken!!";
				   echo
                   continue;;
    esac

    echo "Reinstalling Archive to /etc/rc*, /etc/init.d/"
    tar -xvkzf ${ARCHIV} -P

    echo -n "Remove" ${ARCHIV} "now ? "; read answ
    case "$answ" in
      y*|Y*|j*|J*) echo "Answer = ${answ}";;  # Remove Archive
      *          ) echo "Answer = ${answ}: Archive NOT removed"
				   echo
                   continue;;
    esac
    echo
    echo "Removing" /etc/init.d/SAVE/${ARCHIV}
    rm ${ARCHIV}
  done
}

Delete ()	{
	rm -i /etc/init.d/SAVE/${ARCHIV}
}


# -----------------------------------------------------------------
# main prog
# -----------------------------------------------------------------

clear
[ $# = 0 ] && USE && exit 1	# -> No Param:  Help

JOB=Save;			# default -> Save to tar archive, Deinstall
case $1 in
  -s ) JOB=Save;    shift;;	# -> Save to tar archive, Deinstall
  -r ) JOB=Restore; shift;;	# -> Reinstall from tar archive
  -d ) JOB=Delete;  shift;;	# -> Delete tar archive
  -* ) USE; exit 1			# -> Help
esac

# Select JOB: Deinstall, Reinstall or Remove
${JOB} ${@} && exit 0 || exit -1

# ------------------------------------------
# End of Program
# ------------------------------------------



Reply to: