1
0

gammu.init 2.8 KB

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