Qualifiers

Brian K. White brian at aljex.com
Fri Dec 4 17:45:37 PST 2009


frank7767 at aol.com wrote:
>  I am in adding 5 qualifiers to an existing Filepro system....The 
> process of adding them is very tedious.
> is there a way to add these qualifiers to all the filepro files via a 
> script or any other way?
>  
> Regards
> Frank Gemeinhardt

I tried to post full details twice but perhaps the script attachement is 
bouncing the post to be moderator approved and Mark or Bill hasn't 
gotten to it yet..

Anyways, trying to post again, shorter:
This makes a lot of Aljex assumptions, it's not really general purpose, 
but, on your fg1.aljex.com box you can do this:

Take a look at /u/aljex/start/gempro. That's what we call a company 
environment start script. In that case it sets up the environment for 
filepro files in /u/gempro, unqualified. (the ". fpini" at the top 
unsets PFQUAL, and there is no PFQUAL=... in the script)

It's only 3 lines in the middle that you need to think about. Copy the 
script to a new name and change those
lines as appropriate , in stead of PFDIR=/u/gempro, make it whatever 
your fp tree is that you are working on. (I suggest do not use /appl or 
/u/appl, I suggest reserve those for your binaries and do all customer 
work in other directories, and don't put binaries in those dirs, just 
data & menus)

I will use gempro as the example for now as if that was the system you 
are working in.

Next look at /u/aljex/bin/cpq.
That's a script that copies a qualifier to another qualifier.
We create new qualifiers by using that to copy the unqualified dataset 
to a new name. In our case we always treat the unqualified dataset as a 
special case. the files are all either empty or if they have data it is 
data that is meant to be common to all qualifiers, or is meant to be a 
common default or fallback that is common to all qualifiers.
cpq gets two necessary pieces of info from the environment, which is set 
up by company start-scripts. PFQUAL and PFDATA/PFDIR.
It checks for the existence of $COMPANY to ensure that you have run some 
company start-script. That way, it can assume that if PFQUAL or PFDATA 
or PFDIR are empty or unset, it's because the start-script intentionally 
wants it that way, not merely because you forgot to set them to something.

Moving on, to create a new qualifier "aaa" in /u/gempro/appl/filepro
Just run:
gempro cpq aaa
To do all 5 you could run gempro once with no args. This places you in a 
new shell in that environment. Then you could just run cpq directly 5 times.
gempro
cpq aaa
cpq bbb
cpq ccc
cpq ddd
cpq eee
exit

Now to use them, go create 5 new start scripts by copying 
/u/aljex/start/gempro to /u/aljex/start/aaa , bbb, ... eee
In the new script, insert a line "PFQUAL=aaa" and change the company and 
pfname lines to match. Leave the pfdir lines alone in all cases.

/u/aljex/start/gempro:
---top---
#!/bin/bash
. fpini

COMPANY=gempro
PFNAME="Gemeinhart Produce System ($TTY)"
PFDIR=/u/gempro/appl

. fprun
---eof---


You create new ones like this:

/u/aljex/start/aaa:
---top---
#!/bin/bash
. fpini

COMPANY=aaa
PFNAME="AAA System ($TTY)"
PFQUAL=aaa
PFDIR=/u/gempro/appl

. fprun
---eof---



I don't want the cpq script to be some mystery to the rest of the list 
so rather than attach it I'll try justpasting it in this time, but 
understand that may make it harder to copy and use.
If my other posts ever show up they have the script as an attachement.

/u/aljex/bin/cpq:
---top---
#!/bin/ksh
# cpq - copy qualifier to new qualifier
# Filepro dir and source qualifier come from environment.
# Target qualifier comes from command line.
# Source may be unqualified.
# Must be in a company start script environment.
#
# By default:
#   Works on all files in the filepro directory that don't have a .common
#
#   If any filepro files are specified then only they are processed.
#
#   -f   "force" option, ignores .common
#        if used with filenames, affects all (only) files that come 
after it.
#
# usage: company cpq newqual [files...] [-f] [files...]
# examples:
#   in /u/global, copy unqualified to bbb, respect .common
#   (will ignore files like zipcodes and fpl_menu)
#       global cpq bbb
#   in /u/global, copy unqualified zipcodes to 1970, ignore .common
#       global cpq 1970 -f zipcodes
#
# 20060508 brian at aljex.com

DD=${PFDATA}${PFDIR}/filepro	# data dir
SQ=$PFQUAL			# source qualifier
[[ "$1" ]] && { TQ=$1 ; shift ; }		# target qualifier
BK=`stty -a |awk 'BEGIN{RS=";"}/intr =/{print $3}'`
FORCE=false

abrt () {
	cat <<-%%USAGE
		${1:+Error: $@}

		cpq - copy qualifier to new qualifier
	
		Filepro dir and source qualifier come from environment.
		Target qualifier comes from command line.
		Source may be unqualified.
		Must be in a company start script environment.
		
		By default:
		* Works on all files in the filepro directory that dont have a .common
		* If any filepro files are specified then only they are processed.
		* -f   "force" option, ignores .common
		  if used with filenames, affects all (only) files that come after it.
		
		usage:
			company cpq newqual [files...] [-f] [files...]
		
		examples:
		in /u/global, copy unqualified to bbb, respect .common
		(will ignore files with .common, like zipcodes and fpl_menu):
			global cpq bbb

		in /u/global, copy unqualified zipcodes to 1970, ignore .common:
			global cpq 1970 -f zipcodes
		
	%%USAGE
	exit 1
}

[[ "$COMPANY" ]] || abrt "Missing COMPANY."
[[ "$TQ" ]] || abrt "Missing target qualifier."
[[ "$SQ" = "$TQ" ]] && abrt "Source and Target qualifiers are the same."
cd $DD || abrt "Couldnt cd ${DD}"

echo "This will copy all qualifier \"${SQ}\" to new qualifier \"${TQ}\""
echo "in $DD ."
echo "Press ${BK:-BREAK} to Abort now."
echo "Press ENTER to continue."
read

for d in ${*:-*} ; do
	echo
	[[ "$d" = "-f" ]] && { FORCE=: ; continue ; }
	cd ${DD}/$d || continue
	print "$d : \c"
	[[ -e key$SQ ]] || continue
	$FORCE || [ ! -e .common ] || continue
	print "key \c"
         cp -p key$SQ key$TQ
	print "data \c"
	cp -p data$SQ data$TQ
	ls index${SQ}.* >/dev/null 2>&1 && {
		for i in index${SQ}.* ; do
			I=${i##*.}
			print "$I \c"
			cp -p $i index${TQ}.$I
		done
	}
	grep -q "^${TQ}\$" qualify || echo $TQ >> qualify
done
echo

---eof---

Also to make those start-scripts make more sense to the list:

/u/aljex/bin/fpini:
---top---

# fpini - Part of Aljex environment management system.
# Intentionally no shebang line above.
# This file (fpini), and fprun, are sourced by company start-scripts, 
like so:
# /u/aljex/start/foo:
#       #!/bin/bash
#       . fpini      # always first line after shebang
#       COMPANY=foo
#       PFNAME="Foo System ($TTY)"
#       PFQUAL=foo
#       PFDIR=/u/global/appl
#       . fprun      # always last line in the file
#
# removed ksh-isms, now works in bash, ksh, zsh.
# ksh was causing a bug involving the break key in rare cases.
# (bizz, on linux, 64bit)
#
# brian at aljex.com

export PATHFILE=/etc/default/fppath

export PFPROG=`sed -n 1p <$PATHFILE`
export PFDATA=`sed -n 2p <$PATHFILE`
export PFDIR=`sed -n 3p <$PATHFILE`
export PFDSK=${PFDATA:-/}

unset PFDLDIR PFGLOB PFMENU PFCONFIG PFTMP FPMERGE PFQUAL FPFAXDIR 
MILERDATA COMPANY PFNAME APS ALJEX_TYPE PREFIX FAXSYS ALJEX_DI ALJEX_CM

PS1='\h:\w \$ '

# Strip any company-specific path(s) from the beginning of $PATH
while [[ ${PATH:0:5} = "/pix/" ]] ; do PATH=${PATH#*:} ;done
---eof---

/u/aljex/bin/fprun:
---top---

# fprun - Main part of Aljex environment management system.
# Intentionally no shebang line above.
# This file (fprun), and fpini, are sourced by company start-scripts, 
like so:
# /u/aljex/start/foo:
#	#!/bin/bash
#	. fpini      # always first line after shebang
#	COMPANY=foo
#	PFNAME="Foo System ($TTY)"
#	PFQUAL=foo
#	PFDIR=/u/global/appl
#	. fprun      # always last line in the file
#
# removed ksh-isms, now works in bash, ksh, zsh.
# ksh was causing a bug involving the break key in rare cases.
# (bizz, on linux, 64bit)
#
# brian at aljex.com

umask 0
: ${CRON:=false}
#typeset -u HOST=`hostname`
export HOSTNAME=${HOSTNAME:-`hostname`}

# this is for cgi/cron/etc
[ -z "WANADDR" ] && . /etc/profile.local

# Set many variables dynamically based on the main company settings.
# Assumes that fpini has previously unset all.
# This doesn't override any variables that already exist, so you just put
# any differences from default in the company start script.

export COMPANY PFNAME PFQUAL PFDIR PFDATA ALJEX_TYPE PREFIX
export PFCONFIG=${PFCONFIG:-${PFDATA}${PFDIR}/fp/lib/config}
[ -f ${PFCONFIG}.${COMPANY} ] && export PFCONFIG=${PFCONFIG}.${COMPANY}
export PFMENU=${PFMENU:-${PFDATA}${PFDIR}/fp/menus}
export PFGLOB=${PFGLOB:-${PFDATA}${PFDIR}/fp/lib/edits}
export PS1="${HOSTNAME}: ${PFNAME}: "
export APS="$PS1"
export PFTMP=${PFTMP:-/pix/${COMPANY}/tmp}
export PFDLDIR=${PFDLDIR:-/pix/${COMPANY}/logos}
export FPMERGE=${FPMERGE:-${PFDATA}${PFDIR}/fpmerge}
export MILERDATA=${MILERDATA:-${PFTMP}/pcmiler}
export FPFAXDIR=${FPFAXDIR:-${PFTMP}/vsifax}
export PALMDIR=${PALMDIR:-${PFTMP}/palm}
export MAILTYPE=${MAILTYPE:-bare}
[ -n "$DEFFAXSYS" -a -z "$FAXSYS" ] && FAXSYS=$DEFFAXSYS
[ -n "$FAXSYS" ] && export FAXSYS FAXSOFTWARE=$FAXSYS # TODO: ditch 
FAXSOFTWARE
export SESSPID=$$ # session process id, because filepro has no @pid
[ -n "$ALJEX_CM" ] && export ALJEX_CM  # custom menus (use qualified 
fpl_menu)
PATH=/pix/${COMPANY}/bin:$PATH  # for company-specific scripts like cron 
jobs

# scanning version differences
[ -n "$ALJEX_DI" ] && export ALJEX_DI
case "$ALJEX_DI" in
	7.*)
		vs="/pix/${COMPANY}/.AljexDI_v7"
		[ -e "$vs" ] || { touch "$vs" ; chmod 444 "$vs" ; }
		unset vs
		: ${SCANIMG:=lib/scanimg_v$ALJEX_DI}
		export SCANIMG
		;;
esac

# xterms present a weird case, there is no tty when /etc/profile runs,
# yet each xterm gets a new tty without running /etc/profile any more.
[ -z "$TTY" -o "$TTY" = "not a tty" ] && {
	tty=`tty`
	TTY=${tty##*/}
	PFNAME=`echo "$PFNAME" |sed "s/()/($TTY)/;s/not a tty/$TTY/"`
	PS1="${HOSTNAME}: ${PFNAME}: "
	APS="$PS1"
}

# human readable company without (tty)
export COMPANYNAME=${PFNAME%\(*}

# nologin file
FPRUN_NOLOGIN=${PFTMP}/nologin

case "$ALJEX_TYPE" in
	air) PREFIX=air ;;
	rail) PREFIX=r ;;
	logistics) PREFIX=ll ;;
	broker|"") PREFIX= ;;
esac

preexec () {
	# pre exec setup
	# do this when running something, even if it's just a child shell
	# don't do this when just setting up env in current shell

	# look for per-company nologin file
	# like /etc/nologin but only for one company
	[ -f $FPRUN_NOLOGIN ] && {
		# always at least print the basic message to stderr
		echo "$COMPANY is disabled." >&2

		# If in cron then don't hang for user input,
		# and don't test for root, just exit now.
		# We want root to be able to use the system manually,
		# but we don't want roots cron jobs to include this company.
		$CRON && exit 1

		# if not in cron then wait for acknowledgment keypress
		echo -n "Press [Enter] "
		read

		# allow root to proceed
		[ `id -u` = 0 ] || exit 1
		echo "root allowed"
	}

	# create any referenced directories if they don't exist
	for tdir in $PFTMP $PFDLDIR $MILERDATA ${FPFAXDIR}/sent $PALMDIR ; do
		[ -d $tdir ] || mkdir -p $tdir
	done
	unset tdir

	# miscelaneous fixups.
	# pix invoice_public & invoice symlink
	[ -d /pix/${COMPANY}/invoice_public -a -L /pix/${COMPANY}/invoice ] || {
		[ -d /pix/${COMPANY}/invoice -a ! -d /pix/${COMPANY}/invoice_public ] 
&& mv /pix/${COMPANY}/invoice /pix/${COMPANY}/invoice_public
		mkdir -p /pix/${COMPANY}/invoice_public/thumb
		(cd /pix/${COMPANY} ;ln -s invoice_public invoice)
	}

	# logo.pcl needs to exist for print code tables, empty is ok.
	[ -e ${PFDLDIR}/logo.pcl ] || touch ${PFDLDIR}/logo.pcl

	# put environment name in the window title bar
	tty -s && [ -n "$TTY" -a -z "$NOTITLE" ] && wtitle "${HOSTNAME}: $PFNAME"
}

# launch app or shell or merely set env
case "$@" in
	"") # spawn a subshell in env so you can exit back out
		echo "Entering $PFNAME Environment"
		preexec
		exec ${SHELL:-sh}
		;;
	":") # do nothing, use with ". company :" to source-in the environment
		:
		;;
	query|status) # test enable/disable status
		[ -f $FPRUN_NOLOGIN ] && {
			$CRON || echo "$COMPANY is DISABLED on ${HOSTNAME}."
			exit 1
		} || {
			$CRON || echo "$COMPANY is ENABLED on ${HOSTNAME}."
			exit 0
		}
		;;
	disable) # turn off this system so only root can use it
		[ `id -u` = 0 ] || { echo "Only root may do this!" ; exit 1 ; }
		[ -f $FPRUN_NOLOGIN ] && {
			echo "$FPRUN_NOLOGIN exists. $COMPANY was already disabled."
		} || {
			touch $FPRUN_NOLOGIN && echo "$FPRUN_NOLOGIN created. $COMPANY is now 
disabled." || echo "Could not create $FPRUN_NOLOGIN !"
		}
		;;
	enable) # remove previous block and allow users to use this system
		[ `id -u` = 0 ] || { echo "Only root may do this!" ; exit 1 ; }
		[ -f $FPRUN_NOLOGIN ] && {
			rm -f $FPRUN_NOLOGIN && echo "$FPRUN_NOLOGIN removed. $COMPANY is now 
enabled." || echo "Could not remove $FPRUN_NOLOGIN !"
		} || {
			echo "$FPRUN_NOLOGIN not present. $COMPANY was already enabled."
		}
		;;
	cleantmp) # delete old temp files
		echo "Deleteing stale files in $PFTMP"
		find $PFTMP -mtime +1 ! -wholename "$FPRUN_NOLOGIN" -delete
		;;
	*) # run a command in the env as a child
		preexec
		exec "$@"
		;;
esac
---eof---

-- 
bkw


More information about the Filepro-list mailing list