#!/bin/sh

CURRENT=$(sudo cpupower frequency-info | grep 'current policy: frequency should be within 400 MHz and' | awk '{printf "%.2f%s", $10, substr($11, 1, length($11)-1)}')

echo Current freq is $CURRENT

set_cmd() {
  sudo cpupower frequency-set --max $1MHz
  notify-send -t 800 "$1MHz CPU Power"
}

if [ $CURRENT = "400.00MHz" ]; then
  set_cmd 600
  exit 0
fi

if [ $CURRENT = "600.00MHz" ]; then
  set_cmd 1000
  exit 0
fi

if [ $CURRENT = "1000.00MHz" ]; then
  set_cmd 2000
  exit 0
fi

if [ $CURRENT = "2.00GHz" ]; then
  set_cmd 4200
  exit 0
fi

if [ $CURRENT = "4.20GHz" ]; then
  set_cmd 400
  exit 0
fi

notify-send CPU-Power Error: value is $CURRENT
exit 1
