#!/bin/ksh # FPCOPYALL - work-around for broken fpcopy # Uses fpcopy to copy a filepro file, but copies all prc, tok, out, screen, # brw, & sel files including those with names over 14 bytes, which fpcopy # incorrectly ignores as of 4.08.09 on SCO Unix. # 1 Finds screen, prc, tok, out, brw, & sel filenames that are over 14 bytes # 2 Renames them to a shorter name # 3 Executes fpcopy # 4 Restores the old names in both the source and target filepro files # 5 Clears bad checksums in target out.* files that ahd to be renamed # (note: this removes passwords from these output formats, only in the # newly created target file) # # run from a user menu, or otherwise be sure that PFDIR is set # may need to run as root (I need to, you may not.) # if PFNAME is set already, it will be used # Written and tested on SCO Open Server 5.0.5 # should work on at least any version of SCO Open Server, possibly Xenix # should work on Linux (untested, 'iffy' commands tested individually though) # Brian K. White - linut@squonk.net # -- # Brian K. White http://www.squonk.net/users/linut # +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. # filePro BBx Linux SCO Prosper/FACTS AutoCAD #callahans Satriani ############################################################################## #SAVEKEY=`tput kf12` ;export SAVEKEY # F12 - save key (Albany Burner Control) SAVEKEY="\033\033" ;export SAVEKEY # Esc Esc - save key (default) # set to true or execute fpcopyall with -d for debugging messages DEBUG=false [ "$1" = "-d" ] && DEBUG=true $DEBUG && echo "** DEBUG messages are enabled **" ABE=ASCII; export ABE PFME=ON; readonly PFME FD=$PFDIR/filepro LOG=$PFDIR/fpcopyall.$$.log unset PSW TARGET OP1 OP2 DO OPTSOK=false $DEBUG || DO=">/dev/null 2>&1" pause () { echo "- press enter to continue -\c" ; read junk ; } # ** maybe my system is just misconfigured, maybe you do not need this check ** # UGLYNESS! ahhhh crap... (if everyone used bash this wouldn't be needed) case `uname -s` in [Ll]inux) PSCMD="ps auxn |awk '{print $1, $2}'" ;; SCO_SV) PSCMD="ps -e -ouid,pid" ;; *) echo "WARNING: can't verify UID=0" ; PSCMD="echo 0 $$" ;; esac USER=`$PSCMD |grep $$ |grep -v grep |awk '{print $1}' ` $DEBUG && echo " ** Current UID: $USER ** " [ "$USER" = "0" ] || { echo " ** Need to be root to execute $0 ** " pause ; exit 1 } # # gather info # until [ $OPTSOK = true ] ;do until [ -d $FD/$PFNAME -a -n "$PFNAME" ] ;do echo "Existing filepro file to copy: \c" ;read PFNAME ;export PFNAME done echo "Creation password for $PFNAME: \c";read PSW while [ -e $FD/$TARGET -o -z "$TARGET" ] ;do echo "Name for new copy of $PFNAME: \c" ;read TARGET done echo "" echo " 1 - Copy File Layout And Formats Only" echo " 2 - Copy File Layout, Formats, And Data" echo "" until [ "$OP1" = "1" -o "$OP1" = "2" ] ;do echo "Enter 1 or 2: \c" ;read OP1 done echo "" echo " 1 - Assign The Creation Password As The Runtime Password" echo " 3 - Remove All Runtime Passwords" echo "" until [ "$OP2" = "1" -o "$OP2" = "3" ] ;do echo "Enter 1 or 3: \c" ;read OP2 done echo "" echo "" echo "SOURCE: $PFNAME" echo "PASSWD: $PSW" echo "TARGET: $TARGET" echo "1) layout & formats \n2) layout, formats, & data : $OP1" echo "1) runtime passwd = creation passwd \n3) remove runtime passwd : $OP2" echo "" echo "These options correct? (Y/n)\c" ; read OPTSOK case $OPSTOK in [Nn]|[Nn][Oo]) OPTSOK=false ; unset PFNAME ;; *) OPTSOK=true ;; esac done # # shorten long filenames in source file # TF=/tmp/fp-$PFNAME-$TARGET-** ; >$TF PREFIXES="screen out prc tok brw sel" cd $FD/$PFNAME for PFX in $PREFIXES ; do for OF in $PFX.* ; do [ `echo "$OF\c"|wc -c` -gt 14 ] && { NF=$PFX.$RANDOM while [ -f $NF ] ;do NF=$PFX.$RANDOM done echo "$NF=$OF" >>$TF $DEBUG && echo "moving $OF --> $NF" mv -f $OF $NF 2>>$LOG $DEBUG && pause } done ; done # # run fpcopy # cd $PFDIR $DEBUG && echo "running fpcopy..." echo "$PSW\r$TARGET\r$OP1\r$OP2\r\c" | $PFDIR/fp/fpcopy $DO $DEBUG && pause # # restore altered filenames in source and target files # cd $FD for i in `cat $TF ` ;do NF=`echo $i |cut -d= -f1` OF=`echo $i |cut -d= -f2` $DEBUG && echo "moving $PFNAME/$NF --> $PFNAME/$OF" mv -f $PFNAME/$NF $PFNAME/$OF 2>>$LOG $DEBUG && echo "moving $TARGET/$NF --> $TARGET/$OF" mv -f $TARGET/$NF $TARGET/$OF 2>>$LOG $DEBUG && pause done # # fix bad checksums # PFNAME=$TARGET ; export PFNAME for OF in `cat $TF |grep ^out |cut -d= -f2 |sed s/^out\.//g ` ;do $DEBUG && echo "fixing checksum in $PFNAME: out.$OF" [ -n "$PSW" -a "$OP2" = "1" ] && { $DEBUG && { echo "using dmoedef WITH password" ; pause ; } echo "$PSW\r$OF\r\rU\r${SAVEKEY}X\c" | $PFDIR/fp/dmoedef $DO } || { $DEBUG && { echo "using dmoedef WITHOUT password" ; pause ; } echo "$OF\r\rU\r${SAVEKEY}X\c" | $PFDIR/fp/dmoedef $DO } $DEBUG && pause done $DEBUG || rm -f $TF [ -n "`cat $LOG`" ] && { echo "*!* WARNING: Errors were logged to $LOG *!*" ; pause ; exit 1 ; } || rm -f $LOG