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.

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