source: src-sh/libsh/functions.sh @ 3b0aba7

9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 3b0aba7 was 3b0aba7, checked in by Kris Moore <kris@…>, 7 months ago

Fix some possible warning messages during download parsing

  • Property mode set to 100755
File size: 17.0 KB
Line 
1#!/bin/sh
2# Functions we can source for pc-bsd scripts
3# Author: Kris Moore
4# Copyright: 2012
5# License: BSD
6##############################################################
7
8PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
9
10download_cache_packages()
11{
12  if [ ! -e "/usr/local/etc/pkg.conf" ] ; then
13    exit_err "No /usr/local/etc/pkg.conf!"
14  fi
15
16  # Tickle pkg update first
17  pkg-static update
18  local ARCH="`uname -m`"
19
20  ${1} > /tmp/.pkgUpList.$$
21
22  while read line
23  do
24     lTag=`echo $line | awk '{print $1}'` 
25     case $lTag in
26    Upgrading|Downgrading) pkgList="`echo $line | awk '{print $2}' | sed 's|:||g'`-`echo $line | awk '{print $5}'`.txz $pkgList" ;;
27 Reinstalling) pkgList="`echo $line | awk '{print $2}'`.txz $pkgList" ;;
28   Installing) pkgList="`echo $line | awk '{print $2}' | sed 's|:||g'`-`echo $line | awk '{print $3}'`.txz $pkgList" ;;
29                    *) continue ;;
30     esac
31
32  done < /tmp/.pkgUpList.$$
33  rm /tmp/.pkgUpList.$$
34
35  # Get the PKG_CACHEDIR
36  PKG_CACHEDIR="/var/cache/pkg"
37  cat /usr/local/etc/pkg.conf | grep -q "^PKG_CACHEDIR:"
38  if [ $? -eq 0 ] ; then
39    PKG_CACHEDIR="`grep '^PKG_CACHEDIR:' /usr/local/etc/pkg.conf | awk '{print $2}'`"
40  fi
41  if [ -z "$PKG_CACHEDIR" ] ; then
42     exit_err "Failed getting PKG_CACHEDIR"
43  fi
44  export PKG_CACHEDIR
45
46  # Where are the packages on our mirrors?
47  cat /usr/local/etc/pkg.conf | grep -q "^packagesite:"
48  if [ $? -ne 0 ] ; then
49     exit_err "Failed getting packagesite:"
50  fi
51  pkgUrl="`grep '^packagesite:' /usr/local/etc/pkg.conf | awk '{print $2}'`"
52
53  if [ ! -d "$PKG_CACHEDIR/All" ] ; then
54     mkdir -p ${PKG_CACHEDIR}/All
55  fi
56
57  for i in $pkgList
58  do
59    # Does the package already exist?
60    if [ -e "${PKG_CACHEDIR}/All/${i}" ] ; then 
61        # Once bapt gives us a working rquery string, we can add a check here to skip
62        # re-downloading already valid files
63        #pName=`echo $i | sed 's|.txz$||g'`
64        # Check the sizes
65        #eSize=`pkg rquery "%sb" $pName`
66        #dSize=`ls -al `
67        #rm ${PKG_CACHEDIR}/All/${i} ;
68    fi
69    get_file "${pkgUrl}/All/${i}" "${PKG_CACHEDIR}/All/${i}"
70    if [ $? -ne 0 ] ; then
71      echo "Failed downloading: ${pkgUrl}/All/${i}"
72      return 1
73    fi
74  done
75  return 0
76}
77
78get_mirror() {
79
80  # Check if we already looked up a mirror we can keep using
81  if [ -n "$CACHED_PCBSD_MIRROR" ] ; then
82     VAL="$CACHED_PCBSD_MIRROR"
83     export VAL
84     return
85  fi
86
87  # Set the mirror URL
88  VAL="`cat ${PCBSD_ETCCONF} 2>/dev/null | grep 'PCBSD_MIRROR: ' | sed 's|PCBSD_MIRROR: ||g'`"
89  if [ -n "$VAL" ] ; then
90     echo "Using mirror: $VAL"
91     CACHED_PCBSD_MIRROR="$VAL"
92     export VAL CACHED_PCBSD_MIRROR
93     return
94  fi
95
96  echo "Getting regional mirror..."
97  . /etc/profile
98
99  # No URL? Lets get one from the master server
100  local mFile="${HOME}/.mirrorUrl.$$"
101  touch $mFile
102  fetch -o $mFile http://getmirror.pcbsd.org >/dev/null 2>/dev/null
103  VAL="`cat $mFile | grep 'URL: ' | sed 's|URL: ||g'`"
104  rm $mFile
105  if [ -n "$VAL" ] ; then
106     echo "Using mirror: $VAL"
107     CACHED_PCBSD_MIRROR="$VAL"
108     export VAL CACHED_PCBSD_MIRROR
109     return
110  fi
111
112  # Still no mirror? Lets try the PC-BSD FTP server...
113  VAL="ftp://ftp.pcbsd.org/pub/mirror"
114  CACHED_PCBSD_MIRROR="$VAL"
115  export VAL CACHED_PCBSD_MIRROR
116  echo "Using mirror: $VAL"
117  return 
118}
119
120# Function which returns the installed list of PC-BSD mirrors for use
121# with the aria2c command
122# Will return just a single mirror, if the user has manually specified one
123# in /usr/local/etc/pcbsd.conf
124get_aria_mirror_list()
125{
126  if [ -z $1 ] ; then
127     exit_err "Need to supply file to grab from mirrors..."
128  fi
129  if [ -z $2 ] ; then
130     exit_err "Need to supply which mirror to fetch from..."
131  fi
132
133  case $2 in
134    pkg) mirrorTag="PKG_MIRROR" 
135         mirrorFile="/usr/local/share/pcbsd/conf/pkg-mirror"
136         ;;
137    pbi) mirrorTag="PBI_MIRROR" 
138         mirrorFile="/usr/local/share/pcbsd/conf/pbi-mirror"
139         ;;
140    iso) mirrorTag="ISO_MIRROR" 
141         mirrorFile="/usr/local/share/pcbsd/conf/iso-mirror"
142         ;;
143  update) mirrorTag="UPDATE_MIRROR" 
144         mirrorFile="/usr/local/share/pcbsd/conf/update-mirror"
145         ;;
146    *) exit_err "Bad mirror type!" ;;
147  esac
148
149  # Set the mirror URL
150  local VAL=`cat ${PCBSD_ETCCONF} 2>/dev/null | grep "^${mirrorTag}:" | sed "s|^${mirrorTag}: ||g"`
151  if [ -n "$VAL" ] ; then
152     echo "${VAL}${1}"
153     return
154  fi
155
156  if [ ! -e "${mirrorFile}" ] ; then
157     exit_err "Missing mirror list: ${mirrorFile}"
158  fi
159
160  # Build the mirror list
161  while read line
162  do
163    VAL="$VAL ${line}${1}"
164  done < ${mirrorFile}
165  echo ${VAL}
166}
167
168# Function to download a file from the pcbsd mirrors
169# Arg1 = Remote File URL
170# Arg2 = Where to save file
171get_file_from_mirrors()
172{
173   _rf="${1}"
174   _lf="${2}"
175   _mtype="${3}"
176
177   case $_mtype in
178      iso|pbi|pkg|update) ;;
179      *) exit_err "Fixme! Missing mirror type in get_file_from_mirrors" ;;
180   esac
181
182   # Get any proxy information
183   . /etc/profile
184
185   # Split up the dir / file name
186   local aDir=`dirname $_lf`
187   local aFile=`basename $_lf`
188
189   # Server status flag
190   if [ `id -u` = "0" ] ; then
191      aStatFile=/root/.pcbsd-aria-stat
192   else
193      aStatFile=${HOME}/.pcbsd-aria-stat
194   fi
195
196   if [ -e "$aStatFile" ] ; then
197     local aStat="--server-stat-of=$aStatFile --server-stat-if=$aStatFile --uri-selector=adaptive --server-stat-timeout=864000"
198   else
199     local aStat="--server-stat-of=$aStatFile --uri-selector=adaptive"
200   fi
201   touch $aStatFile
202
203   # Get mirror list
204   local mirrorList="$(get_aria_mirror_list ${_rf} ${_mtype})"
205   
206   # Running from a non GUI?
207   if [ "$GUI_FETCH_PARSING" != "YES" -a "$PBI_FETCH_PARSING" != "YES" -a -z "$PCFETCHGUI" ] ; then
208      aria2c ${aStat} --check-certificate=false --file-allocation=none -d "${aDir}" -o "${aFile}" ${mirrorList}
209      return $?
210   fi
211
212   echo "FETCH: ${_rf}"
213
214   # Doing a front-end download, parse the output of fetch
215   _eFile="/tmp/.fetch-exit.$$"
216   fetch -s "`echo ${mirrorList} | awk '{print $1}'`" > /tmp/.fetch-size.$$ 2>/dev/null
217   _fSize=`cat /tmp/.fetch-size.$$ 2>/dev/null`
218   _fSize="`expr ${_fSize} / 1024 2>/dev/null`"
219   rm "/tmp/.fetch-size.$$" 2>/dev/null
220   _time=1
221   if [ -z "$_fSize" ] ; then _fSize=0; fi
222
223   ( aria2c -o ${aFile} -d ${aDir} ${aStat} --check-certificate=false --file-allocation=none ${mirrorList} >/dev/null 2>/dev/null ; echo "$?" > ${_eFile} ) &
224   FETCH_PID=$!
225   while :
226   do
227      if [ -e "${_lf}" ] ; then
228         sync
229         _dSize=`du -k ${_lf} | tr -d '\t' | cut -d '/' -f 1`
230         if [ $(is_num "$_dSize") ] ; then
231            if [ ${_fSize} -lt ${_dSize} ] ; then _dSize="$_fSize" ; fi
232            _kbs=`expr ${_dSize} \/ $_time`
233            echo "SIZE: ${_fSize} DOWNLOADED: ${_dSize} SPEED: ${_kbs} KB/s"
234         fi
235      fi
236
237      # Make sure download isn't finished
238      jobs -l >/tmp/.jobProcess.$$
239      cat /tmp/.jobProcess.$$ | awk '{print $3}' | grep -q ${FETCH_PID}
240      if [ "$?" != "0" ] ; then rm /tmp/.jobProcess.$$ ; break ; fi
241      sleep 1
242      _time=`expr $_time + 1`
243   done
244
245   _err="`cat ${_eFile} 2>/dev/null`"
246   if [ -z "$_err" ] ; then _err="0"; fi
247   rm ${_eFile} 2>/dev/null
248   if [ "$_err" = "0" ]; then echo "FETCHDONE" ; fi
249   unset FETCH_PID
250   return $_err
251
252}
253
254# Function to download a file from remote using fetch
255# Arg1 = Remote File URL
256# Arg2 = Where to save file
257# Arg3 = Number of attempts to make before failing
258get_file() {
259
260        _rf="${1}"
261        _lf="${2}"
262        _ftries=${3}
263        if [ -z "$_ftries" ] ; then _ftries=3; fi
264
265        # Get any proxy information
266        . /etc/profile
267
268        if [ -e "${_lf}" ] ; then
269                echo "Resuming download of: ${_lf}"
270        fi
271
272        if [ "$GUI_FETCH_PARSING" != "YES" -a -z "$PCFETCHGUI" ] ; then
273                fetch -r -o "${_lf}" "${_rf}"
274                _err=$?
275        else
276                echo "FETCH: ${_rf}"
277
278                # Doing a front-end download, parse the output of fetch
279                _eFile="/tmp/.fetch-exit.$$"
280                fetch -s "${_rf}" > /tmp/.fetch-size.$$ 2>/dev/null
281                _fSize=`cat /tmp/.fetch-size.$$ 2>/dev/null`
282                _fSize="`expr ${_fSize} / 1024 2>/dev/null`"
283                rm "/tmp/.fetch-size.$$" 2>/dev/null
284                _time=1
285                if [ -z "$_fSize" ] ; then _fSize=0; fi
286
287                ( fetch -r -o "${_lf}" "${_rf}" >/dev/null 2>/dev/null ; echo "$?" > ${_eFile} ) &
288                FETCH_PID=`ps -auwwwx | grep -v grep | grep "fetch -r -o ${_lf}" | awk '{print $2}'`
289                while :
290                do
291                        if [ -e "${_lf}" ] ; then
292                                _dSize=`du -k ${_lf} | tr -d '\t' | cut -d '/' -f 1`
293                                if [ $(is_num "$_dSize") ] ; then
294                                        if [ ${_fSize} -lt ${_dSize} ] ; then _dSize="$_fSize" ; fi
295                                        _kbs=`expr ${_dSize} \/ $_time`
296                                        echo "SIZE: ${_fSize} DOWNLOADED: ${_dSize} SPEED: ${_kbs} KB/s"
297                                fi
298                        fi
299
300                        # Make sure download isn't finished
301                        ps -p $FETCH_PID >/dev/null 2>/dev/null
302                        if [ "$?" != "0" ] ; then break ; fi
303                        sleep 2
304                        _time=`expr $_time + 2`
305                done
306
307                _err="`cat ${_eFile} 2>/dev/null`"
308                if [ -z "$_err" ] ; then _err="0"; fi
309                rm ${_eFile} 2>/dev/null
310                if [ "$_err" = "0" ]; then echo "FETCHDONE" ; fi
311                unset FETCH_PID
312        fi
313
314        echo ""
315        if [ $_err -ne 0 -a $_ftries -gt 0 ] ; then
316                sleep 30
317                _ftries=`expr $_ftries - 1`
318
319                # Remove the local file if we failed
320                if [ -e "${_lf}" ]; then rm "${_lf}"; fi
321
322                get_file "${_rf}" "${_lf}" $_ftries     
323                _err=$?
324        fi
325        return $_err
326}
327
328# Check if a value is a number
329is_num()
330{
331        expr $1 + 1 2>/dev/null
332        return $?
333}
334
335# Exit with a error message
336exit_err() {
337        if [ -n "${LOGFILE}" ] ; then
338           echo "ERROR: $*" >> ${LOGFILE}
339        fi
340        echo >&2 "ERROR: $*"
341        exit 1
342}
343
344
345### Print an error on STDERR and bail out
346printerror() {
347  exit_err $*
348}
349
350
351# Check if the target directory is on ZFS
352# Arg1 = The dir to check
353# Arg2 = If set to 1, don't dig down to lower level directory
354isDirZFS() {
355  local _chkDir="$1"
356  while :
357  do
358     # Is this dir a ZFS mount
359     mount | grep -w "on $_chkDir " | grep -qw "(zfs," && return 0
360
361     # If this directory is mounted, but NOT ZFS
362     if [ "$2" != "1" ] ; then
363       mount | grep -qw "on $_chkDir " && return 1
364     fi
365     
366     # Quit if not walking down
367     if [ "$2" = "1" ] ; then return 1 ; fi
368 
369     if [ "$_chkDir" = "/" ] ; then break ; fi
370     _chkDir=`dirname $_chkDir`
371  done
372 
373  return 1
374}
375
376# Gets the mount-point of a particular zpool / dataset
377# Arg1 = zpool to check
378getZFSMount() {
379  local zpool="$1"
380  local mnt=`mount | grep "^${zpool} on" | grep "(zfs," | awk '{print $3}'`
381  if [ -n "$mnt" ] ; then
382     echo "$mnt"
383     return 0
384  fi
385  return 1
386}
387
388# Get the ZFS dataset of a particular directory
389getZFSDataset() {
390  local _chkDir="$1"
391  while :
392  do
393    local zData=`mount | grep " on ${_chkDir} " | grep "(zfs," | awk '{print $1}'`
394    if [ -n "$zData" ] ; then
395       echo "$zData"
396       return 0
397    fi
398    if [ "$2" != "rec" ] ; then return 1 ; fi
399    if [ "$_chkDir" = "/" ] ; then return 1 ; fi
400    _chkDir=`dirname $_chkDir`
401  done
402  return 1
403}
404
405# Get the ZFS tank name for a directory
406# Arg1 = Directory to check
407getZFSTank() {
408  local _chkDir="$1"
409
410  _chkdir=${_chkDir%/}
411  while :
412  do
413     zpath=`zfs list | awk -v path="${_chkDir}" '$5 == path { print $1 }'`
414     if [ -n "${zpath}" ] ; then
415        echo $zpath | cut -f1 -d '/'
416        return 0
417     fi
418
419     if [ "$_chkDir" = "/" ] ; then return 1 ; fi
420     _chkDir=`dirname $_chkDir`
421  done
422
423  return 1
424}
425
426# Get the mountpoint for a ZFS name
427# Arg1 = name
428getZFSMountpoint() {
429   local _chkName="${1}"
430   if [ -z "${_chkName}" ]; then return 1 ; fi
431
432   zfs list "${_chkName}" | tail -1 | awk '{ print $5 }'
433}
434
435# Get the ZFS relative path for a path
436# Arg1 = Path
437getZFSRelativePath() {
438   local _chkDir="${1}"
439   local _tank=`getZFSTank "$_chkDir"`
440   local _mp=`getZFSMountpoint "${_tank}"`
441
442   if [ -z "${_tank}" ] ; then return 1 ; fi
443
444   local _name="${_chkDir#${_mp}}"
445   echo "${_name}"
446   return 0
447}
448
449# Check if an address is IPv6
450isV6() {
451  echo ${1} | grep -q ":"
452  return $?
453}
454   
455# Is a mount point, or any of its parent directories, a symlink?
456is_symlinked_mountpoint()
457{
458        local _dir
459        _dir=$1
460        [ -L "$_dir" ] && return 0
461        [ "$_dir" = "/" ] && return 1
462        is_symlinked_mountpoint `dirname $_dir`
463        return $?
464}
465
466# Function to ask the user to press Return to continue
467rtn()
468{
469  echo -e "Press ENTER to continue\c";
470  read garbage
471};
472
473# Function to check if an IP address passes a basic sanity test
474check_ip()
475{
476  ip="$1"
477 
478  # If this is a V6 address, skip validation for now
479  isV6 "${ip}"
480  if [ $? -eq 0 ] ; then return ; fi
481
482  # Check if we can cut this IP into the right segments
483  SEG="`echo $ip | cut -d '.' -f 1 2>/dev/null`"
484  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
485  if [ "$?" != "0" ]
486  then
487     return 1
488  fi
489  if [ $SEG -gt 255 -o $SEG -lt 0 ]
490  then
491     return 1
492  fi
493 
494  # Second segment
495  SEG="`echo $ip | cut -d '.' -f 2 2>/dev/null`"
496  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
497  if [ "$?" != "0" ]
498  then
499     return 1
500  fi
501  if [ $SEG -gt 255 -o $SEG -lt 0 ]
502  then
503     return 1
504  fi
505
506  # Third segment
507  SEG="`echo $ip | cut -d '.' -f 3 2>/dev/null`"
508  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
509  if [ "$?" != "0" ]
510  then
511     return 1
512  fi
513  if [ $SEG -gt 255 -o $SEG -lt 0 ]
514  then
515     return 1
516  fi
517 
518  # Fourth segment
519  SEG="`echo $ip | cut -d '.' -f 4 2>/dev/null`"
520  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
521  if [ "$?" != "0" ]
522  then
523     return 1
524  fi
525  if [ $SEG -gt 255 -o $SEG -lt 0 ]
526  then
527     return 1
528  fi
529
530  return 0
531};
532
533check_pkg_conflicts()
534{
535  # Lets test if we have any conflicts
536  pkg-static ${1} 2>/tmp/.pkgConflicts.$$ >/tmp/.pkgConflicts.$$
537  if [ $? -eq 0 ] ; then rm /tmp/.pkgConflicts.$$ ; return ; fi
538 
539  # Found conflicts, suprise suprise, yet another reason I hate packages
540  # Lets start building a list of the old packages we can prompt to remove
541
542  # Nice ugly sed line, sure this can be neater
543  cat /tmp/.pkgConflicts.$$ | grep 'WARNING: locally installed' \
544        | sed 's|.*installed ||g' | sed 's| conflicts.*||g' | sort | uniq \
545        > /tmp/.pkgConflicts.$$.2
546  while read line
547  do
548    cList="$line $cList"
549  done < /tmp/.pkgConflicts.$$.2
550  rm /tmp/.pkgConflicts.$$.2
551  rm /tmp/.pkgConflicts.$$
552
553  if [ "$GUI_FETCH_PARSING" != "YES" -a "$PBI_FETCH_PARSING" != "YES" -a -z "$PCFETCHGUI" ] ; then
554        echo "The following packages will conflict with your pkg command:"
555        echo "-------------------------------------"
556        echo "$cList" | more
557        echo "Do you wish to remove them automatically?"
558        echo -e "Default yes: (y/n)\c"
559        read tmp
560        if [ "$tmp" != "y" -a "$tmp" != "Y" -a -n "$tmp" ] ; then return 1 ; fi
561  else
562        echo "PKGCONFLICTS: $cList"
563        echo "PKGREPLY: /tmp/pkgans.$$"
564        while :
565        do
566          if [ -e "/tmp/pkgans.$$" ] ; then
567            ans=`cat /tmp/pkgans.$$`
568            if [ "$ans" = "yes" ] ; then
569               break
570            else
571               return 1
572            fi
573          fi
574          sleep 3
575        done
576  fi
577
578  # Lets auto-resolve these bad-boys
579  # Right now the logic is pretty simple, you conflict, you die
580  for bPkg in $cList
581  do
582     # Nuked!
583     echo "Removing conflicting package: $bPkg"
584     pkg delete -q -y -f ${bPkg}
585  done
586
587  # Lets test if we still have any conflicts
588  pkg-static ${1} 2>/dev/null >/dev/null
589  if [ $? -eq 0 ] ; then return 0; fi
590
591  # Crapola, we still have conflicts, lets warn and bail
592  echo "ERROR: pkg ${1} is still reporting conflicts... Resolve these manually and try again"
593  return 1
594}
595
596# Run the first boot wizard
597# Should be called from a .xinitrc script, after fluxbox is already running
598run_firstboot()
599{
600  # Is the trigger file set?
601  if [ ! -e "/var/.pcbsd-firstgui" ] ; then return; fi
602
603  # Set all our path variables
604  PATH="/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/bin:/usr/local/sbin"
605  HOME="/root"
606  export PATH HOME
607
608  # Unset the PROGDIR variable
609  PROGDIR=""
610  export PROGDIR
611
612  if [ -e "/root/.xprofile" ] ; then . /root/.xprofile ; fi
613
614  # Figure out which intro video to play
615  res=`xdpyinfo | grep dimensions: | awk "{print $2}"`
616  h=`echo $res | cut -d "x" -f 1`
617  w=`echo $res | cut -d "x" -f 2`
618  h=`expr 100 \* $h`
619  ratio=`expr $h \/ $w | cut -c 1-2`
620  case $ratio in
621    13) mov="PCBSD9_4-3_UXGA.flv";;
622    16) mov="PCBSD9_16-10_WUXGA.flv";;
623    17) mov="PCBSD9_16-9_1080p.flv";;
624     *) mov="PCBSD9_4-3_UXGA.flv";;
625  esac
626
627  # Play the video now
628  mplayer -fs -nomouseinput -zoom /usr/local/share/pcbsd/movies/$mov
629
630  # Setting a language
631  if [ -e "/etc/pcbsd-lang" ] ; then
632    LANG=`cat /etc/pcbsd-lang`
633    export LANG
634  fi
635
636  # Start first-boot wizard
637  /usr/local/bin/pc-firstboot >/var/log/pc-firstbootwiz 2>/var/log/pc-firstbootwiz
638  if [ $? -eq 0 ] ; then
639    rm /var/.pcbsd-firstgui
640  fi
641}
642
643# Run-command, don't halt if command exits with non-0
644rc_nohalt()
645{
646  CMD="$1"
647
648  if [ -z "${CMD}" ] ; then
649    exit_err "Error: missing argument in rc_nohalt()"
650  fi
651
652  ${CMD}
653}
654
655# Run-command, halt if command exits with non-0
656rc_halt()
657{
658  CMD="$@"
659
660  if [ -z "${CMD}" ] ; then
661    exit_err "Error: missing argument in rc_halt()"
662  fi
663
664  ${CMD}
665  STATUS=$?
666  if [ ${STATUS} -ne 0 ] ; then
667    exit_err "Error ${STATUS}: ${CMD}"
668  fi
669}
670
671# Run-command silently, only display / halt if command exits with non-0
672rc_halt_s()
673{
674  CMD="$@"
675
676  if [ -z "${CMD}" ] ; then
677    exit_err "Error: missing argument in rc_halt()"
678  fi
679
680  TMPRCLOG=`mktemp /tmp/.rc_halt.XXXXXX`
681  ${CMD} >${TMPRCLOG} 2>${TMPRCLOG}
682  STATUS=$?
683  if [ ${STATUS} -ne 0 ] ; then
684    cat ${TMPRCLOG}
685    rm ${TMPRCLOG}
686    exit_err "Error ${STATUS}: ${CMD}"
687  fi
688  rm ${TMPRCLOG}
689}
Note: See TracBrowser for help on using the repository browser.