gpsd: Update init script 8182/head
authorJeffery To <jeffery.to@gmail.com>
Mon, 11 Feb 2019 14:05:23 +0000 (22:05 +0800)
committerJeffery To <jeffery.to@gmail.com>
Mon, 11 Feb 2019 14:17:06 +0000 (22:17 +0800)
This replaces the use of uci_validate_section() with
uci_load_validate(), which removes the need to declare local variables
for every config option.

This also adds a service_triggers() function and removes some
unnecessary curly brackets.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
utils/gpsd/Makefile
utils/gpsd/files/gpsd.init

index f6433ac38623b5006e92b1116a3f1762338f7e18..4272034128da29746f156e2ab9b93be8717774b4 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=gpsd
 PKG_VERSION:=3.17
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=@SAVANNAH/$(PKG_NAME)
index c4b709c94d9a4c37a63a83bdd1b3e0807069deb7..3271d43fdc1cfaebf26c3d8238ce2e2487a77c6a 100644 (file)
@@ -8,7 +8,7 @@ NAME=gpsd
 
 validate_section_gpsd()
 {
-       uci_validate_section gpsd gpsd "${1}" \
+       uci_load_validate gpsd gpsd "$1" "$2" \
                'enabled:bool:1' \
                'device:string' \
                'listen_globally:bool:0' \
@@ -17,21 +17,19 @@ validate_section_gpsd()
 
 gpsd_instance()
 {
-       local device enabled listen_globally port
-
-       validate_section_gpsd "${1}" || {
+       [ "$2" = 0 ] || {
                echo "validation failed"
                return 1
        }
 
-       [ "${enabled}" = "0" ] && return 1
+       [ "$enabled" = "0" ] && return 1
 
        procd_open_instance
        procd_set_param command "$PROG" -N -n
 
-       [ "${listen_globally}" -ne 0 ] && procd_append_param command -G
-       procd_append_param command -S "${port}"
-       procd_append_param command "${device}"
+       [ "$listen_globally" -ne 0 ] && procd_append_param command -G
+       procd_append_param command -S "$port"
+       procd_append_param command "$device"
        procd_set_param respawn
 
        procd_close_instance
@@ -39,6 +37,11 @@ gpsd_instance()
 
 start_service()
 {
-       config_load "${NAME}"
-       config_foreach gpsd_instance gpsd
+       config_load "$NAME"
+       config_foreach validate_section_gpsd gpsd gpsd_instance
+}
+
+service_triggers() {
+       procd_add_reload_trigger "$NAME"
+       procd_add_validation validate_section_gpsd
 }