|
@@ -1,53 +1,91 @@
|
1
|
1
|
#!/bin/sh /etc/rc.common
|
2
|
|
-# Copyright (C) 2013-2014 OpenWrt.org
|
3
|
2
|
|
4
|
|
-START=50
|
5
|
|
-USE_PROCD=1
|
|
3
|
+NAME=shairport
|
|
4
|
+START=94
|
6
|
5
|
|
7
|
|
-config_shairport() {
|
|
6
|
+SERVICE_DAEMONIZE=1
|
|
7
|
+SERVICE_WRITE_PID=1
|
|
8
|
+
|
|
9
|
+AP_PIDDIR=/var/run
|
|
10
|
+AP_BIN=/usr/bin/shairport
|
|
11
|
+
|
|
12
|
+append_arg() {
|
|
13
|
+ local cfg="$1"
|
|
14
|
+ local var="$2"
|
|
15
|
+ local opt="$3"
|
|
16
|
+ local def="$4"
|
|
17
|
+ local val
|
|
18
|
+
|
|
19
|
+ config_get val "$cfg" "$var"
|
|
20
|
+ [ -n "$val" -o -n "$def" ] && append AP_ARGS "$opt ${val:-$def}"
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+append_bool() {
|
|
24
|
+ local cfg="$1"
|
|
25
|
+ local var="$2"
|
|
26
|
+ local opt="$3"
|
|
27
|
+ local def="$4"
|
|
28
|
+ local val
|
|
29
|
+
|
|
30
|
+ config_get_bool val "$cfg" "$var" "$def"
|
|
31
|
+ [ "$val" = 1 ] && append AP_ARGS "$opt"
|
|
32
|
+}
|
|
33
|
+
|
|
34
|
+start_instance() {
|
|
35
|
+ AP_ARGS=""
|
|
36
|
+ local cfg="$1"
|
|
37
|
+ local ao dev
|
|
38
|
+
|
|
39
|
+ append_arg "$cfg" bname "-a" "AirPort"
|
|
40
|
+ append_arg "$cfg" log "-l"
|
|
41
|
+ append_arg "$cfg" initbuf "-b" "256"
|
|
42
|
+ append_arg "$cfg" port "-p" "5002"
|
|
43
|
+ append_arg "$cfg" password "-k"
|
|
44
|
+ append_arg "$cfg" mdns "-m"
|
|
45
|
+
|
|
46
|
+ append_arg "$cfg" cmd_start "-B"
|
|
47
|
+ append_arg "$cfg" cmd_stop "-E"
|
|
48
|
+ append_bool "$cfg" cmd_wait "-w"
|
|
49
|
+
|
|
50
|
+ append_arg "$cfg" audio_output "-o"
|
|
51
|
+
|
|
52
|
+ config_get ao "$cfg" audio_output ""
|
|
53
|
+ if [ "$ao" = "alsa" ]; then
|
|
54
|
+ config_get dev "$cfg" output_device ""
|
|
55
|
+ if [ -n "$dev" ]; then
|
|
56
|
+ append AP_ARGS "--"
|
|
57
|
+ append_arg "$cfg" output_device "-d"
|
|
58
|
+ append_arg "$cfg" mixer_device "-m"
|
|
59
|
+ append_arg "$cfg" mixer_type "-t"
|
|
60
|
+ append_arg "$cfg" mixer-control "-c"
|
|
61
|
+ append_arg "$cfg" mixer-index "-i"
|
|
62
|
+ fi
|
|
63
|
+ fi
|
|
64
|
+
|
|
65
|
+ SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
|
|
66
|
+ service_start $AP_BIN $AP_ARGS
|
|
67
|
+
|
|
68
|
+ # Check if daemon is running, if not then
|
|
69
|
+ # re-execute in foreground to display error.
|
|
70
|
+ sleep 1 && service_check $AP_BIN || \
|
|
71
|
+ $AP_BIN $AP_ARGS
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+stop_instance()
|
|
75
|
+{
|
8
|
76
|
local cfg="$1"
|
9
|
77
|
|
10
|
|
- local cfg_name
|
11
|
|
- local cfg_password
|
12
|
|
- local cfg_port
|
13
|
|
- local cfg_buffer
|
14
|
|
- local cfg_log
|
15
|
|
- local cfg_cmd_start
|
16
|
|
- local cfg_cmd_stop
|
17
|
|
- local cfg_cmd_wait
|
18
|
|
- local cfg_audio_output
|
19
|
|
- local cfg_mdns
|
20
|
|
-
|
21
|
|
- config_get cfg_name $cfg 'name' 'AirPort'
|
22
|
|
- config_get cfg_password $cfg 'password' ''
|
23
|
|
- config_get cfg_port $cfg 'port' '5002'
|
24
|
|
- config_get cfg_buffer $cfg 'buffer' '256'
|
25
|
|
- config_get cfg_log $cfg 'log' '/var/log/shairport'
|
26
|
|
- config_get cfg_cmd_start $cfg 'cmd_start' ''
|
27
|
|
- config_get cfg_cmd_stop $cfg 'cmd_stop' ''
|
28
|
|
- config_get_bool cfg_cmd_wait $cfg 'cmd_wait' '0'
|
29
|
|
- config_get cfg_audio_output $cfg 'audio_output' ''
|
30
|
|
- config_get cfg_mdns $cfg 'mdns' ''
|
31
|
|
-
|
32
|
|
- procd_open_instance
|
33
|
|
-
|
34
|
|
- procd_set_param command /usr/sbin/shairport
|
35
|
|
- procd_append_param command -a "$cfg_name"
|
36
|
|
- [ ! -z "$cfg_password" ] && procd_append_param command -k "$cfg_password"
|
37
|
|
- procd_append_param command -p $cfg_port
|
38
|
|
- procd_append_param command -b $cfg_buffer
|
39
|
|
- procd_append_param command -l $cfg_log
|
40
|
|
- [ ! -z "$cfg_cmd_start" ] && procd_append_param command -B "$cfg_cmd_start"
|
41
|
|
- [ ! -z "$cfg_cmd_stop" ] && procd_append_param command -E "$cfg_cmd_stop"
|
42
|
|
- [ "$cfg_cmd_wait" -eq 1 ] && procd_append_param command -w
|
43
|
|
- [ ! -z "$cfg_audio_output" ] && procd_append_param command -o "$cfg_audio_output"
|
44
|
|
- [ ! -z "$cfg_mdns" ] && procd_append_param command -m "$cfg_mdns"
|
45
|
|
-
|
46
|
|
- procd_set_param respawn
|
47
|
|
- procd_close_instance
|
|
78
|
+ SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
|
|
79
|
+ SERVICE_SIG_STOP="INT"
|
|
80
|
+ service_stop $AP_BIN
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+start() {
|
|
84
|
+ config_load shairport
|
|
85
|
+ config_foreach start_instance shairport
|
48
|
86
|
}
|
49
|
87
|
|
50
|
|
-start_service() {
|
|
88
|
+stop() {
|
51
|
89
|
config_load shairport
|
52
|
|
- config_foreach config_shairport shairport
|
|
90
|
+ config_foreach stop_instance shairport
|
53
|
91
|
}
|