#!/bin/bash # # Ross J. Michaels (1995) # rjm2@lehigh.edu # # and # # Judith Elaine # blondie@cybertia.org.tenn.com # # (Only the major functional lines were entered by Bill # Stearns (wstearns@pobox.com). The full text can be found # in the November 1995 Linux Gazette at: # http://www.ssc.com/lg/linux/gazette.nov.html CONFIG_DIR="${HOME}/config" DIR_DIST="${HOME}/config/dist" DIR_LINKS="${HOME}/config/links" DIR_BACKUPS="${HOME}/config/backup" EDITED_FILES="${HOME}/config/edited_files" #EDITOR='pico -w' #EDITOR='mcedit' EDITOR='mcedit -c' CURR_DIR=`pwd` #if [ "$LOGNAME" != "root" ] #then # echo "hack: user not logged in as root" ; exit 1 #fi if [ "$1" = "" ]; then echo "hack: filename is missing" ; exit 2 ; fi if [ ! -f "$1" ]; then echo "hack: filename is bad or is a directory" ; exit 3 ; fi BASENAME=`basename $1` if [ ! -d $CONFIG_DIR ]; then mkdir $CONFIG_DIR ; chmod 711 $CONFIG_DIR ; fi if [ ! -d $DIR_DIST ]; then mkdir $DIR_DIST ; chmod 711 $DIR_DIST ; fi if [ ! -d $DIR_BACKUPS ]; then mkdir $DIR_BACKUPS ; chmod 711 $DIR_BACKUPS ; fi if [ ! -d $DIR_LINKS ]; then mkdir $DIR_LINKS ; chmod 711 $DIR_LINKS ; fi if [ ! -f $EDITED_FILES ]; then touch $EDITED_FILES ; chmod 600 $EDITED_FILES ; fi if [ ! -f "$DIR_DIST/$BASENAME.dist" ]; then cp $1 $DIR_DIST/$BASENAME.dist echo "hack: creating file" $DIR_DIST/$BASENAME".dist" elif [ -f $DIR_DIST/$BASENAME.dist ]; then echo "hack:" $DIR_DIST/$BASENAME".dist already exists" else echo "hack: fatal error in destination file" exit 4 fi if [ -f $CURR_DIR/$1 ] then if [ $CURR_DIR = "/" ]; then ln -s "$1" "$DIR_LINKS/$BASENAME" echo "hack: linking" $1 echo "/"$1 >> $EDITED_FILES elif [ ! -L $DIR_LINKS/$1 ]; then ln -s "$CURR_DIR/$1" "$DIR_LINKS/$1" echo "hack: (c) linking" $CURR_DIR"/"$1 echo $CURR_DIR/$1 >> $EDITED_FILES else echo $CURR_DIR/$1 >> $EDITED_FILES fi elif [ -f $1 ]; then if [ ! -L $DIR_LINKS/$BASENAME ]; then ln -s "$1" "$DIR_LINKS/$BASENAME" echo "hack: linking" $1 fi echo $1 >> $EDITED_FILES else echo "hack: something is fundamentally wrong here" fi cp -b $1 $DIR_BACKUPS/$BASENAME.`date +%y%m%d` echo "hack: creating dated backup" $BASENAME.`date +%y%m%d` rm -f $EDITED_FILES.tmp cp $EDITED_FILES $EDITED_FILES.tmp cat $EDITED_FILES.tmp | sort | uniq > $EDITED_FILES rm -f $EDITED_FILES.tmp if [ "${TERM}" = "xterm" -o "${TERM}" = "xterm-color" ]; then echo -ne "\033]0;hack ${1}\007" fi export XTITLE="hack ${1}" $EDITOR $1 if [ "${TERM}" = "xterm" -o "${TERM}" = "xterm-color" ]; then if [ -n "${XTITLE}" ]; then echo -ne "\033]0;${XTITLE}\007" ; else echo -ne "\033]0;${USER}@${SHOSTNAME} ${PWD}\007" | sed -e "s@${HOME}@\~@" fi fi exit