1#! @SCRIPT_SH@ 2# 3# $Id$ 4# 5# @WARNING@ 6# 7# HylaFAX Facsimile Software 8# 9# Copyright (c) 2003 Multitalents 10# Portions Copyright (c) 1990-1996 Sam Leffler 11# Portions Copyright (c) 1991-1996 Silicon Graphics, Inc. 12# HylaFAX is a trademark of Silicon Graphics 13# 14# Permission to use, copy, modify, distribute, and sell this software and 15# its documentation for any purpose is hereby granted without fee, provided 16# that (i) the above copyright notices and this permission notice appear in 17# all copies of the software and related documentation, and (ii) the names of 18# Sam Leffler and Silicon Graphics may not be used in any advertising or 19# publicity relating to the software without the specific, prior written 20# permission of Sam Leffler and Silicon Graphics. 21# 22# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 23# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 24# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 25# 26# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 27# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 28# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 29# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 30# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 31# OF THIS SOFTWARE. 32# 33 34# 35# edit-faxcover [options] 36# 37# This script interactively edits the 10 header lines at the top of faxcover.ps 38# 39PATH=/bin:/usr/bin:/etc 40test -d /usr/ucb && PATH=$PATH:/usr/ucb # Sun and others 41test -d /usr/bsd && PATH=$PATH:/usr/bsd # Silicon Graphics 42test -d /usr/5bin && PATH=/usr/5bin:$PATH:/usr/etc # Sun and others 43test -d /usr/sbin && PATH=/usr/sbin:$PATH # 4.4BSD-derived 44test -d /usr/local/bin && PATH=$PATH:/usr/local/bin # for GNU tools 45 46CAT=@CAT@ # cat command for use below 47GREP=@GREP@ # grep command for use below 48SED=@SED@ # sed for use below 49 50VERSION="@VERSION@" # configured version 51DATE="@DATE@" # data software was configured 52TARGET="@TARGET@" # configured target 53 54FAXCOVER=${FAXCOVER:="@LIBDATA@/faxcover.ps"} 55QUIET=no 56INTERACTIVE=${INTERACTIVE:="yes"} 57 58# 59# Error diagnostics that should go to the terminal are 60# done with this interface or cat. 61# 62bitch() 63{ 64 echo "$@" 1>&2 65} 66 67# 68# This is the preferred interface for 69# configure to terminate abnormally. 70# 71boom() 72{ 73 exit 1 74} 75 76usage() 77{ 78 $CAT<<EOF 79Usage: edit-faxcover [options] 80Options: 81 --with-LINEx="string" set variable LINEx for lines 1 - 10 82 Warning null strings will not blank out existing lines. 83 Use --with-LINE1=" " to blank out line 1 (actually it'll be a single space) 84 85 --with-FAXCOVER=ARG Edit some other faxcover.ps file 86 --help print this message 87 --nointeractive do not prompt for input [INTERACTIVE=no] 88 --quiet do not print 'Using ...' messages 89 --verbose opposite of -quiet 90EOF 91} 92 93# 94# Crack command line arguments. We purposely 95# use syntax and options that are compatible 96# with GNU autoconf. 97# 98WITHARGS=no 99ac_prev= 100for ac_option 101do 102 if [ -n "$ac_prev" ]; then # assign the argument to previous option 103 eval "$ac_prev=\$ac_option" 104 ac_prev= 105 continue 106 fi 107 case "$ac_option" in # collect optional argument 108 -*=*) ac_optarg=`echo "$ac_option" | $SED 's/[-_a-zA-Z0-9]*=//'`;; 109 *) ac_optarg=;; 110 esac 111 case "$ac_option" in 112 -with-*|--with-*) 113 ac_with=`echo $ac_option|$SED -e 's/-*with-//' -e 's/=.*//'` 114 # Reject names that are not valid shell variable names. 115 if [ -n "`echo $ac_with| $SED 's/[-_a-zA-Z0-9]//g'`" ]; then 116 bitch "configure: $ac_with: invalid parameter name." 117 boom 118 fi 119 ac_with=`echo $ac_with| $SED 's/-/_/g'` 120 case "$ac_option" in 121 *=*) ;; 122 *) ac_optarg=yes;; 123 esac 124 eval "${ac_with}='$ac_optarg'" 125 WITHARGS=yes 126 ;; 127 128 -quiet|--quiet) QUIET=yes;; 129 -verbose|--verbose) QUIET=no;; 130 -nointeractive|--nointeractive) INTERACTIVE=no;; 131 -help|--help) usage; exit 0;; 132 -*) 133 bitch "edit-faxcover: $ac_option: invalid option; use -help for usage." 134 boom 135 ;; 136 esac 137done 138 139if [ -n "$ac_prev" ]; then 140 bitch "edit-faxcover: missing argument to --`echo $ac_prev | $SED 's/_/-/g'`" 141 boom 142fi 143 144# 145# Descriptor usage: 146# 1: ??? 147# 2: messages that should be seen even if we're in the background. 148# 3: [stdout from test runs] 149# 4: verbose-style messages (Using ...) 150# 151if [ "$QUIET" = yes ]; then 152 exec 4>/dev/null # chuck messages 153else 154 exec 4>&1 # messages go to stdout 155fi 156 157Note() 158{ 159 echo "$@" 1>&4 160} 161 162Note "" 163Note "This is a program to edit faxcover.ps" 164Note "" 165Note "HylaFAX (tm) $VERSION." 166Note "" 167Note "Created for $TARGET on $DATE." 168Note "" 169 170# 171# Figure out which brand of echo we have and define prompt 172# and printf shell functions accordingly. Note that we 173# assume that if the System V-style echo is not present, 174# then the BSD printf program is available. These functions 175# are defined here so that they can be tailored on a per-site, 176# etc. basis. 177# 178if [ `echo foo\\\c`@ = "foo@" ]; then 179 # System V-style echo supports \r 180 # and \c which is all that we need 181 prompt() 182 { 183 echo "$* \\c" 184 } 185 printf() 186 { 187 echo "$*\\c" 188 } 189 dumpPromptFuncs() 190 { 191 $CAT<<-'EOF' 192 prompt() 193 { 194 echo "$* \\c" 195 } 196 printf() 197 { 198 echo "$*\\c" 199 } 200 EOF 201 } 202elif [ "`echo -n foo`@" = "foo@" ]; then 203 # BSD-style echo; use echo -n to get 204 # a line without the trailing newline 205 prompt() 206 { 207 echo -n "$* " 208 } 209 dumpPromptFuncs() 210 { 211 $CAT<<-'EOF' 212 prompt() 213 { 214 echo -n "$* " 215 } 216 EOF 217 } 218else 219 # something else; do without 220 prompt() 221 { 222 echo "$*" 223 } 224 dumpPromptFuncs() 225 { 226 $CAT<<-'EOF' 227 prompt() 228 { 229 echo "$*" 230 } 231 EOF 232 } 233fi 234 235# 236# Prompt the user for a string that can be null. 237# 238promptForStringParameter() 239{ 240 prompt "$2 [$1]?" 241 OIFS=$IFS 242 IFS=" 243" 244 read x 245 IFS=$OIFS 246 case "$x" in 247 " ") x="" ;; 248 "") x="$1" ;; 249 *) # strip leading and trailing white space 250 x=`echo "$x" | $SED -e 's/^[ ]*//' -e 's/[ ]*$//'` 251 ;; 252 esac 253 param="$x" 254} 255 256# ed faxcover.ps search_patern replace_this with_that 257ed_faxcover() { 258 ed - ${FAXCOVER} <<_EOF 259g~^${1} ~s~(${2})~(${3})~ 260w 261q 262_EOF 263} 264 265printConfig() 266{ 267 $CAT<<EOF 268 269 Faxcover header lines are: 270 271 [1] Line 1: $LINE1 272 [2] Line 2: $LINE2 273 [3] Line 3: $LINE3 274 [4] Line 4: $LINE4 275 [5] Line 5: $LINE5 276 [6] Line 6: $LINE6 277 [7] Line 7: $LINE7 278 [8] Line 8: $LINE8 279 [9] Line 9: $LINE9 280 [10] Line 10: $LINE10 281 282 Enter a single space to clear an existing line. 283EOF 284} 285 286promptForParameter() 287{ 288 case $1 in 289 1) promptForStringParameter "$LINE1" \ 290 "Line 1"; LINE1="$param" 291 ;; 292 2) promptForStringParameter "$LINE2" \ 293 "Line 2"; LINE2="$param" 294 ;; 295 3) promptForStringParameter "$LINE3" \ 296 "Line 3"; LINE3="$param" 297 ;; 298 4) promptForStringParameter "$LINE4" \ 299 "Line 4"; LINE4="$param" 300 ;; 301 5) promptForStringParameter "$LINE5" \ 302 "Line 5"; LINE5="$param" 303 ;; 304 6) promptForStringParameter "$LINE6" \ 305 "Line 6"; LINE6="$param" 306 ;; 307 7) promptForStringParameter "$LINE7" \ 308 "Line 7"; LINE7="$param" 309 ;; 310 8) promptForStringParameter "$LINE8" \ 311 "Line 8"; LINE8="$param" 312 ;; 313 9) promptForStringParameter "$LINE9" \ 314 "Line 9"; LINE9="$param" 315 ;; 316 10) promptForStringParameter "$LINE10" \ 317 "Line 10"; LINE10="$param" 318 ;; 319 esac 320} 321 322# main() 323# sanity check 324[ -f ${FAXCOVER} ] || { 325 bitch "${FAXCOVER} not found" 326 boom 327} 328[ -w ${FAXCOVER} ] || { 329 bitch "No write permissions on ${FAXCOVER}" 330 boom 331} 332 333ORIG_LINE1="`$GREP '^/orig-line1 ' $FAXCOVER | $SED -e 's~/orig-line1 (~~' \ 334 -e 's~) def~~'`" 335ORIG_LINE2="`$GREP '^/orig-line2 ' $FAXCOVER | $SED -e 's~/orig-line2 (~~' \ 336 -e 's~) def~~'`" 337ORIG_LINE3="`$GREP '^/orig-line3 ' $FAXCOVER | $SED -e 's~/orig-line3 (~~' \ 338 -e 's~) def~~'`" 339ORIG_LINE4="`$GREP '^/orig-line4 ' $FAXCOVER | $SED -e 's~/orig-line4 (~~' \ 340 -e 's~) def~~'`" 341ORIG_LINE5="`$GREP '^/orig-line5 ' $FAXCOVER | $SED -e 's~/orig-line5 (~~' \ 342 -e 's~) def~~'`" 343ORIG_LINE6="`$GREP '^/orig-line6 ' $FAXCOVER | $SED -e 's~/orig-line6 (~~' \ 344 -e 's~) def~~'`" 345ORIG_LINE7="`$GREP '^/orig-line7 ' $FAXCOVER | $SED -e 's~/orig-line7 (~~' \ 346 -e 's~) def~~'`" 347ORIG_LINE8="`$GREP '^/orig-line8 ' $FAXCOVER | $SED -e 's~/orig-line8 (~~' \ 348 -e 's~) def~~'`" 349ORIG_LINE9="`$GREP '^/orig-line9 ' $FAXCOVER | $SED -e 's~/orig-line9 (~~' \ 350 -e 's~) def~~'`" 351ORIG_LINE10="`$GREP '^/orig-line10 ' $FAXCOVER | $SED -e 's~/orig-line10 (~~' \ 352 -e 's~) def~~'`" 353 354LINE1=${LINE1:="$ORIG_LINE1"} 355LINE2=${LINE2:="$ORIG_LINE2"} 356LINE3=${LINE3:="$ORIG_LINE3"} 357LINE4=${LINE4:="$ORIG_LINE4"} 358LINE5=${LINE5:="$ORIG_LINE5"} 359LINE6=${LINE6:="$ORIG_LINE6"} 360LINE7=${LINE7:="$ORIG_LINE7"} 361LINE8=${LINE8:="$ORIG_LINE8"} 362LINE9=${LINE9:="$ORIG_LINE9"} 363LINE10=${LINE10:="$ORIG_LINE10"} 364 365if [ $QUIET = no ]; then 366 ok=skip 367 while [ "$ok" != y ] && [ "$ok" != yes ]; do 368 if [ "$ok" != skip ]; then 369 for i in 1 2 3 4 5 6 7 8 9 10; do 370 promptForParameter $i; 371 done 372 fi 373 printConfig 374 if [ $INTERACTIVE = no ]; then 375 ok=yes 376 else 377 prompt "Are these ok [yes]?"; read ok 378 test -z "$ok" && ok=yes 379 case "$ok" in 380 [1-9]|10) promptForParameter $ok;; 381 [yY]*|[nN]*) continue;; 382 ?*) 383 echo "" 384 echo "\"y\", \"yes\", or <RETURN> accepts the displayed parameters." 385 echo "A number lets you change the numbered parameter." 386 echo "" 387 ;; 388 esac 389 ok=skip 390 fi 391 done 392fi 393 394# Replace any lines that have changed 395[ "$ORIG_LINE1" = "$LINE1" ] || \ 396 ed_faxcover /orig-line1 "$ORIG_LINE1" "$LINE1" 397[ "$ORIG_LINE2" = "$LINE2" ] || \ 398 ed_faxcover /orig-line2 "$ORIG_LINE2" "$LINE2" 399[ "$ORIG_LINE3" = "$LINE3" ] || \ 400 ed_faxcover /orig-line3 "$ORIG_LINE3" "$LINE3" 401[ "$ORIG_LINE4" = "$LINE4" ] || \ 402 ed_faxcover /orig-line4 "$ORIG_LINE4" "$LINE4" 403[ "$ORIG_LINE5" = "$LINE5" ] || \ 404 ed_faxcover /orig-line5 "$ORIG_LINE5" "$LINE5" 405[ "$ORIG_LINE6" = "$LINE6" ] || \ 406 ed_faxcover /orig-line6 "$ORIG_LINE6" "$LINE6" 407[ "$ORIG_LINE7" = "$LINE7" ] || \ 408 ed_faxcover /orig-line7 "$ORIG_LINE7" "$LINE7" 409[ "$ORIG_LINE8" = "$LINE8" ] || \ 410 ed_faxcover /orig-line8 "$ORIG_LINE8" "$LINE8" 411[ "$ORIG_LINE9" = "$LINE9" ] || \ 412 ed_faxcover /orig-line9 "$ORIG_LINE9" "$LINE9" 413[ "$ORIG_LINE10" = "$LINE10" ] || \ 414 ed_faxcover /orig-line10 "$ORIG_LINE10" "$LINE10" 415 416