Revision 1108,
1.7 KB
checked in by daisuke, 14 years ago
(diff) |
import initscripts-8.90.6 from internal cvs repository
|
Rev | Line | |
---|
[1108] | 1 | #! /bin/bash |
---|
| 2 | # |
---|
| 3 | # adds static routes which go through device $1 |
---|
| 4 | if [ -z "$1" ]; then |
---|
| 5 | echo $"usage: ifup-routes <net-device> [<nickname>]" |
---|
| 6 | exit 1 |
---|
| 7 | fi |
---|
| 8 | |
---|
| 9 | handle_file () { |
---|
| 10 | . $1 |
---|
| 11 | routenum=0 |
---|
| 12 | while [ "x$(eval echo '$'ADDRESS$routenum)x" != "xx" ]; do |
---|
| 13 | eval `ipcalc -p $(eval echo '$'ADDRESS$routenum) $(eval echo '$'NETMASK$routenum)` |
---|
| 14 | line="$(eval echo '$'ADDRESS$routenum)/$PREFIX" |
---|
| 15 | if [ "x$(eval echo '$'GATEWAY$routenum)x" != "xx" ]; then |
---|
| 16 | line="$line via $(eval echo '$'GATEWAY$routenum)" |
---|
| 17 | fi |
---|
| 18 | line="$line dev $2" |
---|
| 19 | /sbin/ip route add $line |
---|
| 20 | routenum=$(($routenum+1)) |
---|
| 21 | done |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | FILES="/etc/sysconfig/network-scripts/route-$1" |
---|
| 25 | if [ -n "$2" -a "$2" != "$1" ]; then |
---|
| 26 | FILES="$FILES /etc/sysconfig/network-scripts/route-$2" |
---|
| 27 | fi |
---|
| 28 | |
---|
| 29 | MATCH='^[[:space:]]*(\#.*)?$' |
---|
| 30 | |
---|
| 31 | for file in $FILES; do |
---|
| 32 | if [ -f "$file" ]; then |
---|
| 33 | if egrep -q '^[[:space:]]*ADDRESS[0-9]+=' $file ; then |
---|
| 34 | # new format |
---|
| 35 | handle_file $file ${1%:*} |
---|
| 36 | else |
---|
| 37 | # older format |
---|
| 38 | { cat "$file" ; echo ; } | while read line; do |
---|
| 39 | if [[ ! "$line" =~ $MATCH ]]; then |
---|
| 40 | /sbin/ip route add $line |
---|
| 41 | fi |
---|
| 42 | done |
---|
| 43 | fi |
---|
| 44 | fi |
---|
| 45 | done |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | # Red Hat network configuration format |
---|
| 49 | NICK=${2:-$1} |
---|
| 50 | CONFIG="/etc/sysconfig/network-scripts/$NICK.route" |
---|
| 51 | [ -f $CONFIG ] && handle_file $CONFIG $1 |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | # Routing rules |
---|
| 55 | FILES="/etc/sysconfig/network-scripts/rule-$1" |
---|
| 56 | if [ -n "$2" -a "$2" != "$1" ]; then |
---|
| 57 | FILES="$FILES /etc/sysconfig/network-scripts/rule-$2" |
---|
| 58 | fi |
---|
| 59 | |
---|
| 60 | for file in $FILES; do |
---|
| 61 | if [ -f "$file" ]; then |
---|
| 62 | { cat "$file" ; echo ; } | while read line; do |
---|
| 63 | if [[ ! "$line" =~ $MATCH ]]; then |
---|
| 64 | /sbin/ip rule add $line |
---|
| 65 | fi |
---|
| 66 | done |
---|
| 67 | fi |
---|
| 68 | done |
---|
Note: See
TracBrowser
for help on using the repository browser.