Browse Source

gammu: add uci config and procd service control

Signed-Off-By: Vitaly Protsko <villy@sft.ru>
---
 Makefile   |    8 +++++---
aTanW 10 years ago
parent
commit
c450e69fb1
4 changed files with 128 additions and 41 deletions
  1. 7
    4
      utils/gammu/Makefile
  2. 0
    37
      utils/gammu/files/gammurc
  3. 5
    0
      utils/gammu/files/smsd
  4. 116
    0
      utils/gammu/files/smsd.init

+ 7
- 4
utils/gammu/Makefile View File

@@ -1,5 +1,6 @@
1 1
 #
2
-# Copyright (C) 2006-2014 OpenWrt.org
2
+# Copyright (C) 2006-2015 OpenWrt.org
3
+#		2014-2015 Vitaly Protsko
3 4
 #
4 5
 # This is free software, licensed under the GNU General Public License v2.
5 6
 # See /LICENSE for more information.
@@ -63,12 +64,14 @@ define Package/gammu/install
63 64
 	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/gammu-{smsd,smsd-inject,smsd-monitor} $(1)/usr/bin
64 65
 	$(INSTALL_DIR) $(1)/usr/lib
65 66
 	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/lib{Gammu*,gsmsd*} $(1)/usr/lib
66
-	$(INSTALL_DIR) $(1)/etc
67
-	$(INSTALL_CONF) ./files/gammurc $(1)/etc/gammurc
67
+	$(INSTALL_DIR) $(1)/etc/init.d
68
+	$(INSTALL_DIR) $(1)/etc/config
69
+	$(INSTALL_CONF) ./files/smsd $(1)/etc/config/smsd
70
+	$(INSTALL_BIN) ./files/smsd.init $(1)/etc/init.d/smsd
68 71
 endef
69 72
 
70 73
 define Package/gammu/conffiles
71
-/etc/gammurc
74
+/etc/config/smsd
72 75
 endef
73 76
 
74 77
 $(eval $(call BuildPackage,gammu))

+ 0
- 37
utils/gammu/files/gammurc View File

@@ -1,37 +0,0 @@
1
-# Port		: "/dev/ttyS%" or "/dev/ircomm%" ("irda" connection), "/dev/ttyUSB%"
2
-#		  (instead of "%" please put "0", "1", "2", etc.)
3
-# Model		: use only, when Gammu doesn't recognize your phone model.
4
-#		  Put it here. Example values: "6110", "6150", "6210", "8210"
5
-# Connection	: type of connection. Use "fbus" or "mbus" or "dlr3" or
6
-#		  "irda" (Infrared over sockets) or "infrared" (DirectIR)
7
-#		  or "at19200" (AT commands on 19200, 8 bits, None parity,
8
-#		  1 stop bit, no flow control) or "at115200" (AT commands on
9
-#		  115200, 8 bits, None parity, 1 stop bit, no flow control)
10
-#		  or "atblue" (AT over BlueTooth) or "dlr3blue" (FBUS
11
-#		  over BlueTooth)
12
-# SynchronizeTime: If you want to set time from computer to phone during
13
-#		  starting connection. Do not rather use this option when want
14
-#		  to reset phone during connection (in some phones need to
15
-#		  set time again after restart)
16
-# Logfile	: Use, when want to have logfile from communication.
17
-# Logformat	: What debug info and format should be used:
18
-#		  "nothing" - no debug level, "text" - transmission dump in
19
-#		  text format, "textall" - all possible info in text format,
20
-#		  "errors"  - errors in text format, "binary" - transmission
21
-#		  dump in binary format
22
-# Use_Locking	: under Unix/Linux use "yes", if want to lock used device
23
-#		  to prevent using it by other applications
24
-# GammuLoc	: name of localisation file
25
-
26
-[gammu]
27
-
28
-port = /dev/ttyUSB0
29
-#model =
30
-connection = at
31
-#synchronizetime = yes
32
-#logfile =
33
-#logformat = errors
34
-use_locking = yes
35
-#gammuloc =
36
-
37
-# EOF /etc/gammurc

+ 5
- 0
utils/gammu/files/smsd View File

@@ -0,0 +1,5 @@
1
+config daemon default
2
+	option enabled		0
3
+	option device		/dev/ttyUSB0
4
+	option connection	at
5
+	option logfile		syslog

+ 116
- 0
utils/gammu/files/smsd.init View File

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