#!/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 # # Since this was typed in, improvements have been made by Bill # Stearns. #Version 0.4 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 [ -d "$1" ]; then echo "hack: filename is a directory" ; exit 3 ; fi if [ ! -f "$1" ]; then echo "hack: filename is bad" ; 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 if [ `ls -al "$1" | awk '{print $2}'` -gt 1 ]; then echo "$1" is hardlinked, copying to break link. if type -path mktemp >/dev/null 2>/dev/null ; then notempfile () { #Handle the case where the temp file can't be created for some reason. echo Couldn\'t create $1 temp file, exiting. exit 1 } TEMPFILE=`mktemp -q /tmp/hack.XXXXXX` || notempfile hack else echo No mktemp on this system, using insecure method for temp file. TEMPFILE=/tmp/hack.$$ rm -f $TEMPFILE fi cp -p "$1" $TEMPFILE rm -f "$1" mv $TEMPFILE "$1" else echo "$1" has only a single link, good. 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 #Many thanks to Johannes Ullrich for the rcs tutorial. if [ -f "$1,v" ] || [ -f "RCS/$1,v" ]; then echo Checking out and locking "$1" file in rcs. co -l "$1" fi $EDITOR "$1" if [ -f "$1,v" ] || [ -f "RCS/$1,v" ]; then echo Checking in and unlocking "$1" file in rcs. ci -u "$1" fi 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