#!/bin/sh
set -x

wifi=`cat /sys/devices/platform/sony-laptop/wifipower`
wwan=`cat /sys/devices/platform/sony-laptop/wwanpower`
bluetooth=`cat /sys/devices/platform/sony-laptop/bluetoothpower`

if test $wifi -eq 1; then
	if test $bluetooth -eq 1; then
		if test $wwan -eq 1; then
			echo 0 > /sys/devices/platform/sony-laptop/wwanpower
			echo 0 > /sys/devices/platform/sony-laptop/bluetoothpower
		else
			echo 0 > /sys/devices/platform/sony-laptop/bluetoothpower
		fi
	else
		if test $wwan -eq 1; then
			echo 0 > /sys/devices/platform/sony-laptop/wwanpower
		else
			echo 0 > /sys/devices/platform/sony-laptop/wifipower
			echo 1 > /sys/devices/platform/sony-laptop/bluetoothpower
		fi
	fi
else
	if test $bluetooth -eq 1; then
		if test $wwan -eq 1; then
			echo 0 > /sys/devices/platform/sony-laptop/wwanpower
		else
			echo 0 > /sys/devices/platform/sony-laptop/bluetoothpower
			echo 1 > /sys/devices/platform/sony-laptop/wwanpower
		fi
	else
		if test $wwan -eq 1; then
			echo 0 > /sys/devices/platform/sony-laptop/wwanpower
			echo 1 > /sys/devices/platform/sony-laptop/wifipower
			echo 1 > /sys/devices/platform/sony-laptop/bluetoothpower
		else
			echo 1 > /sys/devices/platform/sony-laptop/wifipower
		fi
	fi
fi
