OpenSDE Packages Database (without history before r20070)
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.

142 lines
3.3 KiB

  1. #!/bin/bash
  2. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # T2 SDE: package/.../rocknet/rocknet.sh
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- T2-COPYRIGHT-NOTE-END ---
  15. rocknet_debug=0
  16. rocknet_base="/lib/network"
  17. rocknet_config="/etc/conf"
  18. rocknet_tmp_base="/var/run/rocknet"
  19. [ -d $rocknet_tmp_base ] || mkdir -p $rocknet_tmp_base
  20. unset code_snipplets_idx code_snipplets_dat code_snipplets_counter
  21. declare -a code_snipplets_idx='()'
  22. declare -a code_snipplets_dat='()'
  23. code_snipplets_counter=0
  24. lineno=0
  25. ignore=0
  26. global=1
  27. if [ "$3" != "up" -a "$3" != "down" ]; then
  28. echo "Usage: $0 { profile | default } { interface | auto } { up | down }"
  29. exit 1
  30. fi
  31. if [ ! -f $rocknet_config/network ]; then
  32. echo "Configuration file \"$rocknet_config/network\" missing."
  33. exit 2
  34. fi
  35. profile=$1
  36. interface=$2
  37. mode=$3
  38. pmatched=0 # some profile matched ?
  39. imatched=0 # some interface matched ?
  40. #
  41. # addcode mode major-priority minor-priority code1
  42. #
  43. addcode() {
  44. [ "$mode" != "$1" ] && return
  45. [ "$ignore" -gt 0 ] && return
  46. if [ "$1" = "up" ]; then udo="+"; else udo="-"; fi
  47. code_snipplets_idx[code_snipplets_counter]="`
  48. printf '%04d.%04d.%04d' $((5000$udo$2)) $((5000$udo$lineno)) \
  49. $((5000$udo$3))` $code_snipplets_counter"
  50. code_snipplets_dat[code_snipplets_counter]="$4"
  51. (( code_snipplets_counter++ ))
  52. }
  53. #
  54. # isfirst unique-id
  55. #
  56. isfirst() {
  57. [ "$ignore" -gt 0 ] && return 0
  58. eval "\$isfirst_$1"
  59. eval "isfirst_$1='return 1'"
  60. return 0
  61. }
  62. #
  63. # error error-message
  64. #
  65. error() {
  66. echo "$*"
  67. }
  68. status() {
  69. echo "$*"
  70. }
  71. #
  72. # register / unregister active interfaces for user input validation
  73. #
  74. register() {
  75. echo -n "${1}," >> $rocknet_tmp_base/active-interfaces
  76. }
  77. unregister () {
  78. active_interfaces="`cat $rocknet_tmp_base/active-interfaces 2>/dev/null`"
  79. active_interfaces="${active_interfaces//${1},/}"
  80. echo -n "$active_interfaces" > $rocknet_tmp_base/active-interfaces
  81. }
  82. for x in $rocknet_base/*.sh; do . "$x"; done
  83. errno=0
  84. while read cmd para
  85. do
  86. (( lineno++ ))
  87. if [ -n "$cmd" ]; then
  88. cmd="${cmd//-/_}"
  89. para="$( echo "$para" | sed 's,[\*\?],\\&,g' )"
  90. if declare -f public_$cmd > /dev/null
  91. then
  92. # optimization: Only execute commands when they are
  93. # inside an unignored interface section ...
  94. if [ $cmd = "interface" ] ; then
  95. public_$cmd $para
  96. global=0 ip=
  97. elif [ $ignore -eq 0 -o $global -gt 0 ] ; then
  98. public_$cmd $para
  99. fi
  100. else
  101. error "Unknown statement in config file: $cmd"
  102. fi
  103. fi
  104. done < <( sed 's,\(^\|[ \t]\)#.*$,,' < $rocknet_config/network )
  105. while read id1 id2; do
  106. if [ "$rocknet_debug" = 1 ]; then
  107. echo ">> $id1 -> $id2: ${code_snipplets_dat[id2]}"
  108. fi
  109. eval "${code_snipplets_dat[id2]}"
  110. done < <(
  111. for x in "${code_snipplets_idx[@]}"; do echo "$x"
  112. done | sort
  113. )
  114. if [ "$pmatched" = 0 -a "$profile" != "default" ]; then
  115. error "Unknown profile: '$profile'"
  116. errno=1
  117. fi
  118. if [ "$imatched" = 0 ]; then
  119. error "Unknown interface for profile: '$interface'"
  120. errno=1
  121. fi
  122. exit $errno