File: specialcommands

package info (click to toggle)
ifupdown-scripts-zg2 0.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 484 kB
  • ctags: 55
  • sloc: sh: 4,037; makefile: 37
file content (64 lines) | stat: -rwxr-xr-x 2,171 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# $Header:$

# IFACE      = Logical interface name
# MODE       = start | stop
# METHOD     = manual, otherwise exit!
# IF_SCRUPn  = commands to be executed on iface up
# IF_SCRDNn  = commands to be executed on iface down

# this script allows to write special commands in /etc/network/interfaces.
# This is similiar to ifupdown's built-in up/down command, but allows the
# special commands to be issued in the middle of our scripts instead of
# before the first or after the last script. Additionally, we do some magic
# on the values, and save the "down" commands to the state file. This way,
# changes made to /e/n/i while the interface is up are not immediately valid.

# If the first parameter for a IF_SCRUP line begins with a single quote ',
# everything until the second single quote ' is treated as a sed expression
# to modify the command to be executed on iface down.
# - scrup1 ':' echo comment   - will execute the echo command unchanged on
#                               iface up and iface down
# - scrup1 echo comment       - will execute the echo command on iface up only
# - scrup1 's/add /del /' ip addr add dev eth0 127.0.0.1/8
#                           - will execute "ip addr add dev..." on iface up
#                             and "ip addr del dev..." on iface down
# - scrdn1 ip link set dev eth0 down
#                           - will execute the ip command on iface down only

. /etc/network/if.d/common-functions

case "$MODE" in
  start)
    # execute scrup lines and store appropriate "down" lines
    for R in `set | sort | awk 'BEGIN { FS="=";} /^IF_SCRUP/ { print $1; }'`; do
      eval S=\$$R
      
      CMD="${S##\'*\' }"
      if [ "$CMD" != "$S" ]; then
      	# modifier given
	# apply modifier	
	MOD="${S%\'*}"
	MOD="${MOD#\'}"
	DOWN="`echo $CMD | sed \"$MOD\"`"
	add_down "scrup" "$DOWN"
      fi
      cmd "$CMD"
    done

    # store scrdn lines
    for R in `set | sort | awk 'BEGIN { FS="=";} /^IF_SCRDN/ { print $1; }'`; do
      eval S=\$$R
      add_down "scrdn" "$S"
      cmd "$CMD"
    done
    ;;
  stop)
    exec_down "scrup" "exec"
    exec_down "scrdn" "exec"
    ;;
  *)
    ;;
esac

# end of file