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.

104 lines
1.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=50
  3. BIN=uanytun
  4. DAEMON=/usr/sbin/$BIN
  5. DESC=$BIN
  6. RUN_D=/var/run
  7. option_cb() {
  8. local varname="$1"
  9. local value="$2"
  10. if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then
  11. CONFIG_OPTIONS="$CONFIG_OPTIONS $varname "
  12. fi
  13. }
  14. foreach_config_forced() {
  15. foreach_config $1 "forced"
  16. }
  17. foreach_config() {
  18. local cfg="$1"
  19. local name
  20. local option
  21. local value
  22. local args=""
  23. local forced=0
  24. if [ -n "$2" ] && [ "x$2" == "xforced" ]; then
  25. forced=1
  26. fi
  27. config_get name "$cfg" TYPE
  28. for option in $CONFIG_OPTIONS
  29. do
  30. config_get value "$cfg" "$option"
  31. if [ "x$option" == "xdisabled" ]; then
  32. if [ $forced -eq 0 ] && [ $value -eq 1 ]; then
  33. echo -n " $name(disabled)"
  34. return
  35. fi
  36. continue
  37. fi
  38. option=`echo $option | tr '_' '-'`
  39. if [ -n "$value" ]; then
  40. args="$args --$option $value"
  41. fi
  42. done
  43. echo -n " $name"
  44. local status="OK"
  45. $DAEMON --write-pid "$RUN_D/$BIN.$name.pid" $args || status="failed"
  46. echo -n "($status)"
  47. }
  48. stop_vpn() {
  49. local name=$1
  50. local pidfile=$RUN_D/$BIN.$name.pid
  51. echo -n " $name"
  52. local status="OK"
  53. if [ ! -f "$pidfile" ]; then
  54. status="tunnel not active"
  55. else
  56. kill `cat $pidfile` > /dev/null 2>&1 || status="failed"
  57. rm -f $pidfile
  58. fi
  59. echo -n "($status)"
  60. }
  61. start() {
  62. echo -n "Starting $DESC:"
  63. config_load $BIN
  64. if [ $# -gt 0 ]; then
  65. while [ $# -gt 0 ]; do
  66. config_foreach foreach_config_forced "$1"
  67. shift
  68. done
  69. else
  70. config_foreach foreach_config ""
  71. fi
  72. echo "."
  73. }
  74. stop() {
  75. echo -n "Stopping $DESC:"
  76. local name
  77. local pidfile
  78. if [ $# -gt 0 ]; then
  79. while [ $# -gt 0 ]; do
  80. stop_vpn $1
  81. shift
  82. done
  83. else
  84. for pidfile in `ls $RUN_D/$BIN.*.pid 2> /dev/null`; do
  85. name=${pidfile%%.pid}
  86. name=${name##$RUN_D/$BIN.}
  87. stop_vpn $name
  88. done
  89. fi
  90. echo "."
  91. }