mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.6 KiB

  1. #!/bin/bash
  2. rocknet_debug=0
  3. rocknet_base="/etc/network"
  4. rocknet_tmp_base="/var/run/rocknet"
  5. [ -d $rocknet_tmp_base ] || mkdir -p $rocknet_tmp_base
  6. unset code_snipplets_idx code_snipplets_dat code_snipplets_counter
  7. declare -a code_snipplets_idx='()'
  8. declare -a code_snipplets_dat='()'
  9. code_snipplets_counter=0
  10. lineno=0
  11. ignore=0
  12. global=1
  13. retcode=0
  14. if [ "$3" != "up" -a "$3" != "down" ]; then
  15. echo "Usage: $0 { profile | default } { interface | auto } { up | down }"
  16. exit 1
  17. fi
  18. profile=$1
  19. interface=$2
  20. mode=$3
  21. pmatched=0 # some profile matched ?
  22. imatched=0 # some interface matched ?
  23. #
  24. # addcode mode major-priority minor-priority code1
  25. #
  26. addcode() {
  27. [ "$mode" != "$1" ] && return
  28. [ "$ignore" -gt 0 ] && return
  29. if [ "$1" = "up" ]; then udo="+"; else udo="-"; fi
  30. code_snipplets_idx[code_snipplets_counter]="`
  31. printf '%04d.%04d.%04d' $((5000$udo$2)) $((5000$udo$lineno)) \
  32. $((5000$udo$3))` $code_snipplets_counter"
  33. code_snipplets_dat[code_snipplets_counter]="$4"
  34. (( code_snipplets_counter++ ))
  35. }
  36. #
  37. # isfirst unique-id
  38. #
  39. isfirst() {
  40. [ "$ignore" -gt 0 ] && return 0
  41. eval "\$isfirst_$1"
  42. eval "isfirst_$1='return 1'"
  43. return 0
  44. }
  45. #
  46. # error error-message
  47. #
  48. error() {
  49. echo "$*"
  50. retcode=1
  51. }
  52. status() {
  53. echo "$*"
  54. }
  55. #
  56. # register / unregister active interfaces for user input validation
  57. #
  58. register() {
  59. echo -n "${1}," >> $rocknet_tmp_base/active-interfaces
  60. }
  61. unregister () {
  62. active_interfaces="`cat $rocknet_tmp_base/active-interfaces 2>/dev/null`"
  63. active_interfaces="${active_interfaces//${1},/}"
  64. echo -n "$active_interfaces" > $rocknet_tmp_base/active-interfaces
  65. }
  66. for x in "$rocknet_base"/modules/*.sh; do . "$x"; done
  67. while read cmd para
  68. do
  69. (( lineno++ ))
  70. if [ -n "$cmd" ]; then
  71. cmd="${cmd//-/_}"
  72. para="$( echo "$para" | sed 's,[\*\?],\\&,g' )"
  73. if declare -f public_$cmd > /dev/null
  74. then
  75. # optimization: Only execute commands when they are
  76. # inside an unignored interface section ...
  77. if [ $cmd = "interface" ] ; then
  78. public_$cmd $para
  79. global=0
  80. elif [ $ignore -eq 0 -o $global -gt 0 ] ; then
  81. public_$cmd $para
  82. fi
  83. else
  84. error "Unknown statement in config file: $cmd"
  85. fi
  86. fi
  87. done < <( sed 's,\(^\|[ \t]\)#.*$,,' < "$rocknet_base"/config )
  88. while read id1 id2; do
  89. if [ "$rocknet_debug" = 1 ]; then
  90. echo ">> $id1 -> $id2: ${code_snipplets_dat[id2]}"
  91. fi
  92. eval "${code_snipplets_dat[id2]}"
  93. done < <(
  94. for x in "${code_snipplets_idx[@]}"; do echo "$x"
  95. done | sort
  96. )
  97. [ "$pmatched" = 0 -a "$profile" != "default" ] && \
  98. error "Unknown profile: '$profile'"
  99. [ "$pmatched" = 1 -a "$imatched" = 0 ] && \
  100. error "Unknown interface for profile: '$interface'"
  101. exit $retcode