#! /bin/sh ################################################################# # # # (P)roblem (D)ata (B)ase PROGRAM # # By Kirk Waingrow # # # ################################################################# echo -n "( Initializing... )" umask 000 ############################################################################# # VARIABLES THAT MUST BE SET HERE !!! ############################################################################# PRBPATH="/home/kewaingr/bin" FILEPATH="/home/kewaingr/records" # the categories. TMP="/tmp" # Location of temp files edline="$PRBPATH/kile" # line editor edvi="vi" #"/usr/bin/vi" # visual editor me=`whoami` TERMINAL=`tty` hit_return() { echo if [ $IBM ]; then : else echo -n "HIT (RETURN) TO CONTINUE..." read dummy fi } send_to_printer() { echo echo -n "Send hardcopy to local printer (yes/[no]): " read sendit if [ -n "$sendit" ];then if [ "$sendit" = "yes" -o "$sendit" = "YES" ];then lpr -h $FILEPATH/ask.$i echo echo "[ HARDCOPY SENT ] " hit_return fi fi } display_found_pattern() { if [ -z "$look" ]; then clear echo if [ $IBM ]; then cat $TMP/pdp.$ID.$TIME | awk -F: '{printf "%4d) %s\n", $1, $2 }' else cat $TMP/pdp.$ID.$TIME | awk -F: '{printf "%4d) %s\n", $1, $2 }' | more fi echo echo -n "Hit (RETURN) to continue or make selections: " read look look=`echo $look | sed 's/,/ /g'` fi if [ $select_menu -eq 1 -o $select_menu -eq 2 ]; then if [ -n "$look" ]; then for i in $look do clear if [ -f "$FILEPATH/ask.$i" ]; then cat $FILEPATH/ask.$i | more send_to_printer else echo; echo "RECORD NUMBER $i DOES NOT EXIST"; echo hit_return fi done fi fi } get_search_pattern() { look='' cat /dev/null > $TMP/pdp.$ID.$TIME if [ -z "$argv1" ]; then echo echo -n " Record # or Search Pattern: " read pattern else pattern=$argv1 fi if [ -n "$pattern" ]; then if [ $select_menu = 6 ]; then case $pattern in [0123456789]*) look=$pattern break;; esac else case $pattern in [0123456789]*) look=$pattern display_found_pattern break;; esac fi pattern=`echo $pattern | sed 's/,/ /g'` clear echo echo -n "SEARCHING ( $pattern )" if [ -s $FILEPATH/INDEX ]; then if [ $select_menu = 1 -o $select_menu = 6 ]; then # SEARCH INDEX # grep -i "$pattern" $FILEPATH/INDEX > $TMP/pdp.$ID.$TIME cp $FILEPATH/INDEX $TMP/ask.index.$ID.$TIME for i in $pattern do grep -i "$i" $TMP/ask.index.$ID.$TIME > $TMP/ask.index2.$ID.$TIME mv $TMP/ask.index2.$ID.$TIME $TMP/ask.index.$ID.$TIME done mv $TMP/ask.index.$ID.$TIME $TMP/pdp.$ID.$TIME else echo; echo -n "( READING )" # grep -i "$pattern" $FILEPATH/ask.* > $TMP/pdp.db.$ID.$TIME cat /dev/null > $TMP/ask.list.$ID.$TIME for i in `ls $FILEPATH/ask*`; do found=1 for j in $pattern; do cat /dev/null > $TMP/fill.$ID.$TIME grep -i $j $i > $TMP/fill.$ID.$TIME if [ ! -s "$TMP/fill.$ID.$TIME" ];then found=0 fi done if [ $found -eq 1 ];then echo $i | cut -d"." -f2 >> $TMP/ask.list.$ID.$TIME echo -n "." fi done rm -f $TMP/fill.$ID.$TIME echo; echo -n "( COLLATING )" cat /dev/null > $TMP/pdp.$ID.$TIME for i in `cat $TMP/ask.list.$ID.$TIME`; do echo -n "." while read line do # SEARCH DATABASE recnum=`echo $line | cut -d":" -f1` if [ $i -eq $recnum ]; then echo $line >> $TMP/pdp.$ID.$TIME break fi done < $FILEPATH/INDEX done sort -t: -n $TMP/pdp.$ID.$TIME > $TMP/pdp.db.$ID.$TIME mv $TMP/pdp.db.$ID.$TIME $TMP/pdp.$ID.$TIME echo fi fi fi echo if [ -s $TMP/pdp.$ID.$TIME ]; then display_found_pattern else if [ -n "$pattern" ]; then echo echo "( $pattern WAS NOT FOUND IN THE DATABASE )" hit_return fi fi } save_record() { if [ -s $FILEPATH/INDEX ]; then : else touch FILEPATH/INDEX fi num=`tail -1 $FILEPATH/INDEX | cut -d":" -f1` if [ -z "$num" ]; then num=0 fi num=`expr $num + 1` line=$num":"$DESC echo $line >> $FILEPATH/INDEX cp $TMP/pdp.rbbs.$ID.$TIME $FILEPATH/ask.$num echo echo "( RECORD IS SAVED )" if [ -s "$TMP/ask.attach.$ID.$TIME" ]; then cat $TMP/ask.attach.$ID.$TIME >> $FILEPATH/ask.$num rm -f $TMP/ask.attach.$ID.$TIME echo "( ATTACHMENT ADDED )" fi } create_record_file() { if [ `whoami` = "rbbs" ]; then fullname=$ID else fullname=`grep $ID /etc/passwd | cut -d":" -f5 | cut -d";" -f1` fi DT=`date +"%h %d, 19%y"` echo >> $TMP/pdp.rbbs.$ID.$TIME echo $DESC >> $TMP/pdp.rbbs.$ID.$TIME echo -n "$DT - $fullname - $ID" >> $TMP/pdp.rbbs.$ID.$TIME echo >> $TMP/pdp.rbbs.$ID.$TIME echo >> $TMP/pdp.rbbs.$ID.$TIME echo >> $TMP/pdp.rbbs.$ID.$TIME echo "DESCRIPTION" >> $TMP/pdp.rbbs.$ID.$TIME echo "===========" >> $TMP/pdp.rbbs.$ID.$TIME } direct_editor() { finish="n" while [ "$finish" = "n" ] do echo -n ": " read entry1 if [ -z "$entry1" ]; then echo -n ": " read entry2 if [ -z "$entry2" ]; then finish="y" else echo >> $TMP/pdp.rbbs.$ID.$TIME echo $entry2 >> $TMP/pdp.rbbs.$ID.$TIME fi else echo $entry1 >> $TMP/pdp.rbbs.$ID.$TIME fi done } create_direct_file() { clear echo echo " Hit two blank (RETURN) lines when finished" echo; echo; echo echo "DESCRIPTION" echo "===========" direct_editor } attach_it() { if [ `whoami` = "rbbs" ]; then break fi ok="n" attbs="n" while [ "$ok" != "y" ] do echo; echo -n "Attach a file (y/[n]): "; read attach if [ "$attach" = "y" -o "$attach" = "Y" ]; then echo -n "Path/File: "; read attach_file if [ -r "$attach_file" ]; then cp $attach_file $TMP/ask.attach.$ID.$TIME ok="y" else echo "( THE FILE IS NOT READABLE OR DOES NOT EXIST )" fi else ok="y" fi done } editor_menu() { if [ $IBM ]; then : else attach_it fi echo echo " ______________________________" echo " /____________________________ /|" echo " | USE WHICH FORM OF INPUT | |" echo " |_____________________________|/|" echo " / 1 - Direct Line Entry /| |" echo " / 2 - Line Editor / | |" echo " / 3 - Vi Editor /__|/" echo " /_____________________________/" echo echo " The Direct editor requires no terminal emulation" echo echo -n " Make a Selection (1-3) [3]: " read editor echo } create_record() { clear echo echo "Enter a brief one line description of the record" echo "(Example: APPLICATION, Problem Type, Error, Platform)" echo "(Example: CATIA, Dynamic Rotation, System Locks up, Unix )" echo echo -n " :" read DESC if [ -z "$DESC" ]; then break fi ok="n" while [ "$ok" = "n" ] do cat /dev/null > $TMP/pdp.rbbs.$ID.$TIME editor_menu if [ -z "$editor" ]; then editor="3" fi case $editor in 1) create_record_file create_direct_file ok="y";; 2) clear create_record_file $edline $TMP/pdp.rbbs.$ID.$TIME echo ok="y";; 3) if [ $IBM ]; then echo; echo "( OPTION 3 CANNOT BE USED FROM YOUR TERMINAL )" else create_record_file $edvi $TMP/pdp.rbbs.$ID.$TIME ok="y" fi;; '') ok="y";; *) echo; echo "( CHOICES ARE 1-3 )";; esac done if [ -z "$editor" ]; then break fi ok="n" while [ "$ok" = "n" ]; do echo -n "(a)bort or (s)ave record into the database: " read pick case $pick in [aA]*) ok="y";; [sS]*) save_record ok="y";; esac done hit_return } add_record_file() { if [ `whoami` = "rbbs" ]; then fullname=$ID else fullname=`grep $ID /etc/passwd | cut -d":" -f5 | cut -d";" -f1` fi DT=`date +"%h %d, 19%y"` echo >> $TMP/pdp.rbbs.$ID.$TIME echo -n "Modified: $DT - $fullname - $ID" >> $TMP/pdp.rbbs.$ID.$TIME echo >> $TMP/pdp.rbbs.$ID.$TIME } add_direct_file() { clear add_record_file echo echo "Hit two blank (RETURN) lines when finished" echo echo echo -n "Modified: $DT - $fullname - $ID" echo direct_editor } add_record() { clear #kirkcat $FILEPATH/ask.$look | more if [ ! -f "$FILEPATH/ask.$look" -a $select_menu = 6 ]; then echo; echo "RECORD NUMBER $i DOES NOT EXIST"; echo hit_return break fi #hit_return #DESC=`grep "$look:" $FILEPATH/INDEX | cut -d":" -f2` DESC=`awk -F: '$1 == '${look}' { print $2 }' < $FILEPATH/INDEX` ok="n" clear cat /dev/null > $TMP/pdp.rbbs.$ID.$TIME echo echo "Modify: $DESC" while [ "$ok" = "n" ]; do editor_menu case $editor in 1) add_direct_file ok="y";; 2) clear cp $FILEPATH/ask.$look $TMP/pdp.rbbs.$ID.$TIME add_record_file $edline $TMP/pdp.rbbs.$ID.$TIME echo ok="y";; 3) if [ $IBM ]; then echo; echo "( OPTION 3 CANNOT BE USED FROM YOUR TERMINAL )" else cp $FILEPATH/ask.$look $TMP/pdp.rbbs.$ID.$TIME add_record_file $edvi $TMP/pdp.rbbs.$ID.$TIME ok="y" fi;; '') ok="y";; *) echo; echo "( CHOICES ARE 1-4 )" hit_return;; esac done if [ -z "$editor" ]; then break fi ok="n" while [ "$ok" = "n" ]; do echo -n "(a)bort or (s)ave record into the database: " read pick case $pick in [Aa]*) echo "( MODIFICATION IS ABORTED )" ok="y";; [Ss]*) if [ $editor = 1 ]; then cat $TMP/pdp.rbbs.$ID.$TIME >> $FILEPATH/ask.$look else cp $TMP/pdp.rbbs.$ID.$TIME $FILEPATH/ask.$look fi echo echo "( MODIFICATION IS SAVED )" if [ -s "$TMP/ask.attach.$ID.$TIME" ]; then cat $TMP/ask.attach.$ID.$TIME >> $FILEPATH/ask.$look rm -f $TMP/ask.attach.$ID.$TIME echo "( ATTACHMENT ADDED )" fi ok="y";; esac done hit_return } remove_record() { clear echo if [ $IBM ]; then cat $FILEPATH/INDEX else cat $FILEPATH/INDEX | more fi echo echo -n "Enter the record to remove #" read record record=`echo $record | sed 's/,/ /g'` if [ -n "$record" ]; then clear echo "( Searching... )" echo for i in $record do while read line do num=`echo $line | cut -d":" -f1` if [ "$num" = "$i" ]; then echo $line > $TMP/rbbs.found.$ID.$TIME break fi done < $FILEPATH/INDEX if [ -s "$TMP/rbbs.found.$ID.$TIME" ];then tmp=`cat $TMP/rbbs.found.$ID.$TIME` rm -f $TMP/rbbs.found.$ID.$TIME echo $tmp echo echo -n "Okay to remove this record (yes/[no]): " read ans else echo echo "( RECORD $i WAS NOT FOUND )" ans="no" fi if [ "$ans" = "yes" -o "$ans" = "YES" ]; then grep -v "$tmp" $FILEPATH/INDEX > $TMP/rbbs.remove mv $TMP/rbbs.remove $FILEPATH/INDEX rm -f $FILEPATH/ask.$record echo echo "( RECORD $i REMOVED )" else echo echo "( RECORD $i WAS NOT REMOVED )" fi echo done fi hit_return } renumber_database() { echo; echo "This can take some time. " echo -n "Working" count=0 cat /dev/null > $TMP/rbbs.renum while read line do count=`expr $count + 1` num=`echo $line | cut -d":" -f1` desc=`echo $line | cut -d":" -f2` echo -n "." if [ $num -ne $count ]; then #check if number is the same echo $count":"$desc >> $TMP/rbbs.renum mv $FILEPATH/ask.$num $FILEPATH/ask.$count else echo $num":"$desc >> $TMP/rbbs.renum fi done < $FILEPATH/INDEX mv $TMP/rbbs.renum $FILEPATH/INDEX echo; echo; echo "( DATABASE IS RENUMBERED )" hit_return } rebuild_index() { if [ -f "$FILEPATH/INDEX" ]; then mv $FILEPATH/INDEX $FILEPATH/INDEX.bak fi cat /dev/null > $FILEPATH/INDEX echo -n "Rebuilding Index." count=0 for i in `ls $FILEPATH/ask.* | sort -t. +1 -n` do num=`echo $i | cut -d"." -f2` count=`expr $count + 1` echo -n "." while read line do if [ "$line" != "" ]; then echo "$num:$line" >> $FILEPATH/INDEX break fi done < $FILEPATH/ask.$num done echo } maint_menu() { clear echo echo echo " _______________________________ " echo " /_____________________________ /|" echo " | | |" echo " | DATABASE MAINTENANCE MENU | |" echo " |______________________________|/|" echo " / /| |" echo " / 1 - Remove Records / | |" echo " / 2 - Renumber The Index / | |" echo " / 3 - Rebuild The Index /___|/" echo " /_____________________________/" echo echo -n " Make a Selection: " read select_maint case $select_maint in 1) remove_record;; 2) renumber_database;; 3) rebuild_index;; esac } view_index() { clear if [ -s $FILEPATH/INDEX ]; then if [ $IBM ]; then cat $FILEPATH/INDEX else cat $FILEPATH/INDEX | more fi else echo echo "THE INDEX IS COMPLETELY EMPTY." echo fi hit_return } not_implemented() { echo echo "( THIS SECTION IS NOT IMPLEMENTED YET )" echo "( PLEASE CHECK BACK AT A LATER DATE )" echo hit_return } problem_database() { if [ -z "$argv1" ]; then finish='n' while [ "$finish" = "n" ] do clear if [ -s $FILEPATH/INDEX ]; then echo "RECORDS = "`cat $FILEPATH/INDEX | wc -l` else echo fi echo echo " ___________________________________________________ " echo " /_________________________________________________ /| " echo " | | | " echo " | ONLINE PROBLEM DATABASE | | " echo " |__________________________________________________|/ " echo " / 1 - Search The Index - Fast /| |" echo " / 2 - Search The Database - Slow / | |" echo " / 3 - View Entire Index / | |" echo " / 4 - Create An Entry / | |" echo " / 5 - Read Documentation / | |" echo " / 6 - Modify An Entry /_____|/ " echo " / 7 - Maintenance Menu /" echo " / 8 - Exit the program /" echo " /_____________________________________/" echo echo -n " Make a Selection [4]: " read select_menu if [ -z "$select_menu" ]; then #break select_menu=4 fi if [ $select_menu -lt 1 -o $select_menu -gt 8 ]; then break fi case $select_menu in 1) get_search_pattern;; 2) get_search_pattern;; 3) view_index;; 4) create_record finish="n";; 5) clear cat $PRBPATH/pdb.doc.admin | more hit_return;; 6) get_search_pattern if [ -n "$look" ]; then add_record fi finish="n";; 7) maint_menu;; 8) exit;; esac done else select_menu=1 get_search_pattern exit fi } BYE_CLEAN() { echo echo " THANK YOU FOR USING THIS, HOPE IT HELPED" echo echo rm -f $TMP/*$ID.$TIME* $TMP/*.$ID* rm -f /tmp/kile_ed1_$PID /tmp/kile_ed2_$PID /tmp/kile_ed3_$PID stty echo exit 0 } END_IT() { dtout=`date | awk '{ print $2,$3,$6," ",$4 }'` # LOGOUT USERS echo "$ID $dt - $dtout" >> $TMP/ask.logout BYE_CLEAN } END_ILL() { dtout=`date | awk '{ print $2,$3,$6," ",$4 }'` # LOGOUT USERS echo "$ID $dt - $dtout ** BREAK" >> $TMP/ask.logout BYE_CLEAN } # # MAIN PROGAM # # find out who is using rbbs if [ -n "$1" ]; then argv1=$1 else argv1="" fi echo ID=`whoami` export $ID echo while [ "$ID" = "rbbs" ] do echo -n "Enter ID or Last Name: " read tmp_id if [ -n "$tmp_id" ]; then ID=`echo $tmp_id | cut -c1-7` fi done select_menu=0 ok="n" TIME=`date | cut -d" " -f4 | sed 's/://g'` dt=`date | awk '{ print $2,$3,$6," ",$4 }'` # LOGIN USERS tm=`echo $dt | cut -d" " -f4` logid=$ID" "$dt trap END_ILL 2 clear echo while [ true ] do rm -f $TMP/*$ID.$TIME problem_database done