migrations.sh 734 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. migrate_led_sysfs() {
  4. local cfg="$1"; shift
  5. local tuples="$@"
  6. local sysfs
  7. local name
  8. config_get sysfs ${cfg} sysfs
  9. config_get name ${cfg} name
  10. [ -z "${sysfs}" ] && return
  11. for tuple in ${tuples}; do
  12. local old=${tuple%=*}
  13. local new=${tuple#*=}
  14. local new_sysfs
  15. new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
  16. [ "${new_sysfs}" = "${sysfs}" ] && continue
  17. uci set system.${cfg}.sysfs="${new_sysfs}"
  18. logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
  19. done;
  20. }
  21. migrate_leds() {
  22. config_load system
  23. config_foreach migrate_led_sysfs led "$@"
  24. }
  25. migrations_apply() {
  26. local realm="$1"
  27. [ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
  28. }