apply.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/ash
  2. #
  3. # Default handlers for config files
  4. #
  5. HANDLERS_config='
  6. wireless) reload_wireless;;
  7. network) reload_network;;
  8. system) reload_system;;
  9. '
  10. HANDLERS_file='
  11. hosts) rm -f /etc/hosts; mv $config /etc/hosts; killall -HUP dnsmasq ;;
  12. ethers) rm -f /etc/ethers; mv $config /etc/ethers; killall -HUP dnsmasq ;;
  13. firewall) mv /tmp/.webif/file-firewall /etc/config/firewall && /etc/init.d/S45firewall;;
  14. '
  15. # for some reason a for loop with "." doesn't work
  16. eval "$(cat /usr/lib/webif/apply-*.sh 2>&-)"
  17. reload_network() {
  18. echo '@TR<<Reloading>> @TR<<networking settings>> ...'
  19. grep '^wan_' config-network >&- 2>&- && {
  20. ifdown wan
  21. ifup wan
  22. killall -HUP dnsmasq
  23. }
  24. grep '^lan_' config-network >&- 2>&- && {
  25. ifdown lan
  26. ifup lan
  27. killall dnsmasq
  28. /etc/init.d/S??dnsmasq
  29. }
  30. }
  31. reload_wireless() {
  32. echo '@TR<<Reloading>> @TR<<wireless settings>> ...'
  33. killall nas >&- 2>&- && sleep 2
  34. (
  35. /sbin/wifi
  36. [ -f /etc/init.d/S41wpa ] && /etc/init.d/S41wpa
  37. ) >&- 2>&- <&-
  38. }
  39. reload_system() {
  40. echo '@TR<<Applying>> @TR<<system settings>> ...'
  41. echo "$(nvram get wan_hostname)" > /proc/sys/kernel/hostname
  42. }
  43. cd /tmp/.webif
  44. # file-* other config files
  45. for config in $(ls file-* 2>&-); do
  46. name=${config#file-}
  47. echo "@TR<<Processing>> @TR<<config file>>: $name"
  48. eval 'case "$name" in
  49. '"$HANDLERS_file"'
  50. esac'
  51. done
  52. # config-* simple config files
  53. (
  54. cd /proc/self
  55. cat /tmp/.webif/config-* 2>&- | grep '=' >&- 2>&- && {
  56. cat /tmp/.webif/config-* 2>&- | tee fd/1 | xargs -n1 nvram set
  57. echo "@TR<<Committing>> NVRAM ..."
  58. nvram commit
  59. }
  60. )
  61. for config in $(ls config-* 2>&-); do
  62. name=${config#config-}
  63. eval 'case "$name" in
  64. '"$HANDLERS_config"'
  65. esac'
  66. done
  67. sleep 2
  68. rm -f config-*