Changeset cb45bc1 in freewrt


Ignore:
Timestamp:
Jun 26, 2007, 8:47:14 PM (18 years ago)
Author:
Christian Fischer <spaetzle@…>
Children:
b7c164d
Parents:
34bf5b5
Message:

some fixes to make shell code portable

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2945 afb5a338-a214-0410-bd46-81f09a774fd1

Location:
package/fwifupdown/files
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • package/fwifupdown/files/ifupdown.sh

    r34bf5b5 rcb45bc1  
    88#
    99
    10 what=$(basename $0)
     10what=${0##*/}
    1111case $what in
    1212ifup)
  • package/fwifupdown/files/main.sh

    r34bf5b5 rcb45bc1  
    3636
    3737__exit() {
    38         [ "$1" != "0" ] && echo "H_ERR=1" >> $ENVFILE
     38        [ x"$1" != x"0" ] && echo "RT_ERR=1" >> $ENVFILE
    3939        exit $1
    4040}
     
    6161
    6262main_env_update() {
    63         local t_mdent lastmatch=""
     63        local t_mdent lastmatch=
    6464
    6565        # get submode from calling hook script
    66         SUBMODE=$(dirname $0|sed '{ s/\(.*\/\)*//; s/\.d$//}')
     66        SUBMODE=$(echo ${0%/*} |sed '{ s/\(.*\/\)*//; s/\.d$//}')
    6767
    6868        # create env file
    6969        if ! [ -f "$ENVFILE" ]
    7070        then
    71                 [ -d $(dirname $ENVFILE) ] || mkdir -p $(dirname $ENVFILE)
     71                [ -d ${ENVFILE%/*} ] || mkdir -p ${ENVFILE%/*}
    7272                echo "MDENT=0" >> $ENVFILE
    7373                echo "LASTLOG=0" >> $ENVFILE
    7474
    75                 if is_up
    76                 then
    77                         IFACE_STATE="up"
    78                 else
    79                         IFACE_STATE="down"
    80                 fi
     75                is_up && IFACE_STATE="up" || IFACE_STATE="down"
    8176                echo "IFACE_STATE=$IFACE_STATE" >> $ENVFILE
    8277
    83                 if [ "$IFACE" != "lo" ]
     78                if [ x"$IFACE" != x"lo" ]
    8479                then
    8580                        # search for existing lib files end evaluate iface type by using the appropriate
     
    8782                        for lib in ${LIBDIR}/iftypes/*
    8883                        do
    89                                 if [ -f $lib ]
     84                                [ -f $lib ] && (. $lib; iface_type 2>&-) || continue
     85                                if [ -n "$lastmatch" ]
    9086                                then
    91                                         if (. $lib; iface_type 2>&-)
     87                                        if [ ${lib##*/} = ${lastmatch##*/} ]
    9288                                        then
    93                                                 if [ "$lastmatch" != "" ]
    94                                                 then
    95                                                         if [ "$(basename $lib)" = "$(basename $lastmatch)" ]
    96                                                         then
    97                                                                 mprint -s "Warning: $lib overlays $lastmatch"
    98                                                         else
    99                                                                 mprint -s "Error: iface type $lib overlays $lastmatch"
    100                                                         fi
    101                                                 fi
    102                                                 lastmatch=$lib
     89                                                mprint -s "Warning: $lib overlays $lastmatch"
     90                                        else
     91                                                mprint -s "Error: iface type $lib overlays $lastmatch"
    10392                                        fi
    10493                                fi
     94                                lastmatch=$lib
    10595                        done
    10696                fi
    10797
    108                 if [ "$lastmatch" != "" ]
    109                 then
    110                         IFACE_TYPE=$(basename $lastmatch)
    111                 else
    112                         # if iface type isn't evaluated type "iface" is default
    113                         IFACE_TYPE="iface"
    114                 fi
     98                # if iface type isn't evaluated type "iface" is default
     99                [ -n "$lastmatch" ] && IFACE_TYPE=${lastmatch##*/} || IFACE_TYPE="iface"
    115100
    116101                # update env
     
    131116
    132117main_pos_update() {
    133         if [ "${MDENT:-0}" = "0" ]
    134         then
    135                 STARTCOL=""
    136         else
    137                 STARTCOL="[$(expr ${MDENT:-0} \* ${TAB})C"
    138         fi
     118        [ x"$MDENT" = x"0" ] && STARTCOL= || STARTCOL="[$(expr ${MDENT:-0} \* ${TAB})C"
    139119        sed 's/MDENT=[0-9]*/'MDENT=$MDENT'/' -i $ENVFILE
    140120}
     
    157137        retval=$?
    158138
    159         if [ $retval != 0 ]
    160         then
    161                 if [ $retval != 127 ]
    162                 then
    163                         fail_preup 2>&- || exit 1
    164                 fi
    165         fi
     139        [ x"$retval" != x"0" -a x"$retval" != x"127" ] && {
     140                fail_preup 2>&- || exit 1
     141        }
    166142
    167143        config $RT_PREUP_PRINTING_OFF || mup
     
    174150                retval=$?
    175151
    176                 if [ $retval != 0 ]
     152                if [ x"$retval" != x"0" ]
    177153                then
    178154
     
    191167        retval=$?
    192168
    193         if [ $retval != 0 ]
    194         then
    195                 if [ $retval != 127 ]
    196                 then
    197                         fail_up 2>&- || exit 1
    198                 fi
    199         fi
     169        [ x"$retval" != x"0" -a x"$retval" != x"127" ] && {
     170                fail_up 2>&- || exit 1
     171        }
    200172
    201173        if [ -d /tmp/ifupdown/pcode/${IFACE} ]
     
    203175                for dir in /tmp/ifupdown/pcode/${IFACE}/*
    204176                do
    205                         if [ -f ${dir}/postup ]
    206                         then
    207                                 . ${dir}/postup
    208                         fi
     177                        [ -f ${dir}/postup ] || continue
     178                        . ${dir}/postup
    209179                done
    210180        fi
     
    218188                for dir in /tmp/ifupdown/pcode/${IFACE}/*
    219189                do
    220                         if [ -f ${dir}/predown ]
    221                         then
    222                                 . ${dir}/predown
    223                         fi
     190                        [ -f ${dir}/predown ] || continue
     191                        . ${dir}/predown
    224192                done
    225193        fi
     
    228196        retval=$?
    229197
    230         if [ $retval != 0 ]
    231         then
    232                 if [ $retval != 127 ]
    233                 then
    234                         fail_down 2>&- || exit 1
    235                 fi
    236         fi
     198        [ x"$retval" != x"0" -a x"$retval" != x"127" ] && {
     199                fail_down 2>&- || exit 1
     200        }
    237201
    238202        config $RT_DOWN_PRINTING_OFF || mdown
     
    268232        retval=$?
    269233
    270         if [ $retval != 0 ]
    271         then
    272                 if [ $retval != 127 ]
    273                 then
    274                         fail_postdown 2>&- || exit 1
    275                 fi
    276         fi
     234        [ x"$retval" != x"0" -a  x"$retval" != x"127" ] && {
     235                fail_postdown 2>&- || exit 1
     236        }
    277237
    278238        # pcode cleanup
     
    283243        for hook in ${LIBDIR}/${1}/${2}
    284244        do
    285                 if [ -f $hook ]
    286                 then
    287                         . $hook
    288                         eval $3 2>&-
    289                         retval=$?
    290                         [ $retval != 0 -a $retval != 127 ] && exit 1
    291                         return
    292                 fi
     245                [ -f $hook ] || continue
     246                . $hook
     247                eval $3 2>&-
     248                retval=$?
     249                [ x"$retval" != x"0" -a x"$retval" != x"127" ] && exit 1
     250                return
    293251        done
    294252}
     
    300258                eval "${plugin##*/}_${1}" 2>&-
    301259                retval=$?
    302                 [ $retval != 0 -a $retval != 127 ] && exit 1
     260                [ x"$retval" != x"0" -a x"$retval" != x"127" ] && exit 1
    303261        done
    304262}
     
    307265        case $SUBMODE in
    308266                if-pre-up)
    309                         [ "${IF_PRE_UP:-""}" != "" ] && eval $IF_PRE_UP
     267                        [ -n "$IF_PRE_UP" ] && eval $IF_PRE_UP
    310268                ;;
    311269                if-up)
    312                         [ "${IF_UP:-""}" != "" ] && eval $IF_UP
     270                        [ -n "$IF_UP" ] && eval $IF_UP
    313271                ;;
    314272                if-down)
    315                         [ "${IF_DOWN:-""}" != "" ] && eval $IF_DOWN
     273                        [ -n "$IF_DOWN" ] && eval $IF_DOWN
    316274                ;;
    317275                if-post-down)
    318                         [ "${IF_POST_DOWN:-""}" != "" ] && eval $IF_POST_DOWN
     276                        [ -n "$IF_POST_DOWN" ] && eval $IF_POST_DOWN
    319277                ;;
    320278        esac
     
    330288. /etc/rc.conf
    331289
    332 config ${FWIFUPDOWN_DEBUG:=""} && set -x
     290config $FWIFUPDOWN_DEBUG && set -x
    333291
    334292RT_PREUP_PRINTING_OFF=0
     
    340298RT_POSTDOWN_IFDOWN_CHECK_OFF=0
    341299RT_BB_NOEXEC=0
     300RT_ERR=0
    342301readonly ENVFILE="/tmp/ifupdown/env"
    343 readonly INSTALLDIR="/lib/network"
    344302readonly LIBDIR="/etc/network"
    345303IFACE_TYPE="none"
    346 H_ERR=0
    347304
    348305alias exit="__exit"
    349306alias ifup="__ifupdown ifup"
    350307alias ifdown="__ifupdown ifdown"
    351 [ -z "${KSH_VERSION:-""}" ] || alias which='whence -p'
     308[ -z "$KSH_VERSION" ] || alias which='whence -p'
    352309
    353310if ! [ -f /etc/network/mfunctions.sh ]
     
    360317main_env_update
    361318
    362 config $H_ERR && built_in exit 1
    363 
    364 if [ "$IFACE_TYPE" != "iface" ]
     319config $RT_ERR && built_in exit 1
     320
     321if [ x"$IFACE_TYPE" != x"iface" ]
    365322then
    366323        if [ -f "${LIBDIR}/iftypes/${IFACE_TYPE}" ]
Note: See TracChangeset for help on using the changeset viewer.