migrations.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. . /lib/functions.sh
  2. migrate_led_sysfs() {
  3. local cfg="$1"; shift
  4. local tuples="$@"
  5. local sysfs
  6. local name
  7. config_get sysfs ${cfg} sysfs
  8. config_get name ${cfg} name
  9. [ -z "${sysfs}" ] && return
  10. for tuple in ${tuples}; do
  11. local old=${tuple%=*}
  12. local new=${tuple#*=}
  13. local new_sysfs
  14. new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
  15. [ "${new_sysfs}" = "${sysfs}" ] && continue
  16. uci set system.${cfg}.sysfs="${new_sysfs}"
  17. logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
  18. done;
  19. }
  20. remove_devicename_led_sysfs() {
  21. local cfg="$1"; shift
  22. local exceptions="$@"
  23. local sysfs
  24. local name
  25. local new_sysfs
  26. config_get sysfs ${cfg} sysfs
  27. config_get name ${cfg} name
  28. # only continue if two or more colons are present
  29. echo "${sysfs}" | grep -q ":.*:" || return
  30. for exception in ${exceptions}; do
  31. # no change if exceptions provided as argument are found for devicename
  32. echo "${sysfs}" | grep -q "^${exception}:" && return
  33. done
  34. new_sysfs=$(echo ${sysfs} | sed "s/^[^:]*://")
  35. uci set system.${cfg}.sysfs="${new_sysfs}"
  36. logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
  37. }
  38. migrate_leds() {
  39. config_load system
  40. config_foreach migrate_led_sysfs led "$@"
  41. }
  42. remove_devicename_leds() {
  43. config_load system
  44. config_foreach remove_devicename_led_sysfs led "$@"
  45. }
  46. migrations_apply() {
  47. local realm="$1"
  48. [ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
  49. }