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.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 villy@sft.ru
  3. START=98
  4. USE_PROCD=1
  5. PROG=/usr/bin/gammu-smsd
  6. CONFPFX=/var/gammu
  7. start_instance() {
  8. local conf="$1"
  9. local item
  10. local conffile="$CONFPFX-$conf.conf"
  11. config_get_bool item "$conf" enabled 0
  12. [ "$item" = 0 ] && return
  13. {
  14. printf "; don't edit. instead look into /etc/config/gammu\n[gammu]\n\n"
  15. config_get item "$conf" device
  16. [ -z "$item" ] && return
  17. echo "device = $item"
  18. config_get item "$conf" connection
  19. [ -z "$item" ] && return
  20. echo "connection = $item"
  21. config_get item "$conf" logfile
  22. [ -z "$item" ] && item=syslog
  23. echo "logfile = $item"
  24. printf "\n[smsd]\nphoneid = %s\nservice = files\nlogfile = %s\n" "$conf" "$item"
  25. printf "checkbattery = 0\nhangupcalls = 1\n"
  26. config_get item "$conf" pin
  27. [ -n "$item" ] && echo "pin = $item"
  28. config_get item "$conf" phonecode
  29. [ -n "$item" ] && echo "phonecode = $item"
  30. config_get item "$conf" send
  31. [ -n "$item" ] && echo "send = $item"
  32. config_get item "$conf" receive
  33. [ -n "$item" ] && echo "receive = $item"
  34. config_get item "$conf" timeout
  35. [ -n "$item" ] && echo "commtimeout = $item"
  36. config_get item "$conf" sleep
  37. [ -n "$item" ] && echo "loopsleep = $item"
  38. config_get item "$conf" report
  39. [ -n "$item" ] && echo "deliveryreport = $item"
  40. config_get item "$conf" onreceive
  41. [ -n "$item" ] && echo "runonreceive = $item"
  42. config_get item "$conf" onerror
  43. [ -n "$item" ] && echo "runonfailure = $item"
  44. config_get item "$conf" spool
  45. [ -z "$item" ] && item=/var/sms
  46. [ -d "$item" ] || {
  47. mkdir "$item"
  48. mkdir "$item/inbox"
  49. mkdir "$item/outbox"
  50. mkdir "$item/sent"
  51. mkdir "$item/error"
  52. }
  53. printf "inboxpath = %s/inbox/\noutboxpath = %s/outbox/\n" "$item" "$item"
  54. printf "sentsmspath = %s/sent/\nerrorsmspath = %s/error/\n" "$item" "$item"
  55. } > "$conffile"
  56. config_get item "$conf" allow
  57. [ -n "$item" ] && {
  58. local data
  59. local allowfile=$CONFPFX-$conf.allow
  60. for data in $item ; do
  61. echo $data >> "$allowfile"
  62. done
  63. echo "includenumbersfile = $allowfile" >> "$conffile"
  64. }
  65. config_get item "$conf" deny
  66. [ -n "$item" ] && {
  67. local data
  68. local denyfile=$CONFPFX-$conf.deny
  69. for data in $item ; do
  70. echo $data >> "$denyfile"
  71. done
  72. echo "excludenumbersfile = $denyfile" >> "$conffile"
  73. }
  74. procd_open_instance
  75. config_get_bool item "$conf" respawn 0
  76. [ "$item" = 0 ] || procd_set_param respawn
  77. procd_set_param command $PROG --config="$conffile"
  78. config_get item "$conf" pidfile
  79. [ -n "$item" ] && procd_append_param command --pid=$item
  80. procd_close_instance
  81. }
  82. start_service() {
  83. config_load gammu
  84. config_foreach start_instance daemon
  85. }
  86. service_triggers() {
  87. procd_add_reload_trigger "gammu"
  88. }