Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ "$(id -u)" != "0" ]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- function setBrightness {
- su -c 'echo '$1' > '$B
- }
- function setAll {
- su -c 'echo '$1' > '$L
- su -c 'echo '$1' > '$R
- su -c 'echo '$1' > '$M
- }
- function getRandomColor {
- colors="111
- 100
- 010
- 001
- 101
- 110
- 011"
- color=($colors)
- num_colors=${#color[*]}
- echo "${color[$((RANDOM%num_colors))]}"
- }
- L="/sys/devices/platform/clevo_wmi/kbled/left"
- M="/sys/devices/platform/clevo_wmi/kbled/middle"
- R="/sys/devices/platform/clevo_wmi/kbled/right"
- B="/sys/devices/platform/clevo_wmi/kbled/brightness"
- LAST=0
- while true
- do
- VOL=$(parec --device=1 --latency=1 --channels=16 | od -N2 -td2 | head -n1 | cut -d' ' -f2- | tr -d ' ' | perl -pe 's/^-//')
- MUL=$(printf "%.0f" $(echo "$(printf "%.0f" $(echo "($VOL/16000.0)*10" | bc -l)) * 1.0" | bc))
- if [ "$MUL" == "0" ];
- then
- MUL=1
- fi
- TOOLARGE=$(echo "10 < $MUL" | bc)
- if [ "$TOOLARGE" == "1" ];
- then
- MUL=10
- fi
- EQUAL=$(echo "$MUL==$LAST" | bc)
- if [ "$EQUAL" == "0" ];
- then
- echo $MUL
- setBrightness $MUL &
- LARGER=$(echo "7 < $MUL" | bc)
- if [ "$LARGER" == "1" ];
- then
- PREVPF=$(echo "7 < $LAST" | bc)
- if [ "$PREVPF" == "0" ];
- then
- C=$(getRandomColor)
- setAll "$C" &
- sudo k "$C" "$C" "$C" &
- fi
- fi
- LAST=$MUL
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement