#!/bin/sh

# Migrate WiFi path from 19.07 to 21.02+

WIFI_PATH_CHANGED=0

. /lib/functions.sh

migrate_wifi_path() {
	local section="$1"
	local path

	config_get path ${section} path
	case ${path} in
		"pci0000:00/0000:00:00.0/0000:01:00.0")
			path="1e140000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0"
			WIFI_PATH_CHANGED=1
		;;
		"pci0000:00/0000:00:01.0/0000:02:00.0")
			path="1e140000.pcie/pci0000:00/0000:00:01.0/0000:02:00.0"
			WIFI_PATH_CHANGED=1
		;;
		*)
			return 0
		;;
	esac

	uci set wireless.${section}.path=${path}
}

[ "${ACTION}" = "add" ] && {
	[ ! -e /etc/config/wireless ] && return 0

	config_load wireless
	config_foreach migrate_wifi_path wifi-device

	[ "${WIFI_PATH_CHANGED}" = "1" ] && uci commit wireless
}
