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.

88 lines
3.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. STOP=00
  4. USE_PROCD=1
  5. PROG=/usr/bin/tvheadend
  6. TEMP_CONFIG=/tmp/tvheadend
  7. PERSISTENT_CONFIG=/etc/tvheadend
  8. # If you change the user, update the owner of tvheadend configuration directory and files!
  9. # If you change the group, update USB hotplug script for DVB devices in /dev/hotplug.d/usb/
  10. # otherwise, tvheadend won't have permissions to open newly connected tuners!
  11. # Also update all other packages that use the dvb group.
  12. TVH_USER=tvheadend
  13. TVH_GROUP=dvb
  14. execute_first_run() {
  15. mkdir -p "$1"
  16. chown -R $TVH_USER "$1"
  17. # This should create a new configuration including an admin account with no name and no password,
  18. # but it aborts (-A) without saving it:
  19. #"$PROG" -c "$1" -B -C -A -u $TVH_USER -g $TVH_GROUP >/dev/null 2>&1
  20. # Instead, run it for 10s then kill it:
  21. "$PROG" -c "$1" -B -C -u $TVH_USER -g $TVH_GROUP & TVH_PID=$! ; sleep 10 ; kill $TVH_PID ; sleep 2
  22. }
  23. ensure_config_exists() {
  24. local config_path
  25. config_load tvheadend
  26. config_get config_path service config_path
  27. if [ -z "$config_path" ]; then
  28. [ -d "$PERSISTENT_CONFIG" ] || execute_first_run "$PERSISTENT_CONFIG"
  29. else
  30. # if the configuration directory is empty, empty config with grant-all ACL is created
  31. [ -d "$config_path" ] && [ "$(ls -A $config_path)" ] || execute_first_run "$config_path"
  32. fi
  33. # if use_temp_epgdb is enabled (default), most of the config is put to config_path
  34. # (or /etc/config), except for epgdb.v2, which grows quite large and is write-heavy,
  35. # so it's put into volatile tmpfs
  36. # epgdb.v2 is created and symlinked to main config dir upon each start (if it doesn't exist)
  37. config_get_bool use_temp_epgdb service use_temp_epgdb 1
  38. if [ "$use_temp_epgdb" == "1" ]; then
  39. TEMP_EPG="${TEMP_CONFIG}/epgdb.v2"
  40. [ ! -f "$TEMP_EPG" ] && mkdir -p "$TEMP_CONFIG" && touch "$TEMP_EPG" && chmod 700 "$TEMP_EPG"
  41. [ -z "$config_path" ] && config_path="$PERSISTENT_CONFIG"
  42. ln -sf "$TEMP_EPG" "${config_path}/epgdb.v2"
  43. fi
  44. }
  45. load_uci_config() {
  46. config_load tvheadend
  47. config_get config_path service config_path "$PERSISTENT_CONFIG"
  48. [ -n "$config_path" ] && procd_append_param command -c "$config_path"
  49. config_get_bool nosyslog service nosyslog 0
  50. [ "$nosyslog" -eq 1 ] && procd_append_param command --nosyslog
  51. config_get_bool ipv6 server ipv6 0
  52. [ "$ipv6" -eq 1 ] && procd_append_param command --ipv6
  53. config_get bindaddr server bindaddr
  54. [ -z "$bindaddr" ] && bindaddr=$(uci get network.lan.ipaddr)
  55. [ -n "$bindaddr" ] && procd_append_param command --bindaddr "$bindaddr"
  56. config_get http_port server http_port
  57. [ -n "$http_port" ] && procd_append_param command --http_port "$http_port"
  58. config_get http_root server http_root
  59. [ -n "$http_root" ] && procd_append_param command --http_root "$http_root"
  60. config_get htsp_port server htsp_port
  61. [ -n "$htsp_port" ] && procd_append_param command --htsp_port "$htsp_port"
  62. config_get htsp_port2 server htsp_port2
  63. [ -n "$htsp_port2" ] && procd_append_param command --htsp_port "$htsp_port2"
  64. config_get xspf server xspf 0
  65. [ "$xspf" -eq 1 ] && procd_append_param command --xspf
  66. }
  67. start_service() {
  68. ensure_config_exists
  69. procd_open_instance
  70. procd_set_param file /etc/config/tvheadend
  71. chgrp -R $TVH_GROUP /dev/dvb/*
  72. chmod -R g+rwX /dev/dvb/*
  73. procd_set_param command "$PROG" -B -u $TVH_USER -g $TVH_GROUP
  74. load_uci_config
  75. procd_close_instance
  76. }