distribution/packages/sysutils/system-utils/sources/scripts/system_utils

88 lines
2.3 KiB
Text
Raw Normal View History

2022-08-31 01:26:25 +00:00
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Shanti Gilbert (https://github.com/shantigilbert)
# THESE NEEDS TO BE CLEANED UP, MAYBE WITH CASE OR FUNCTIONS
# Source predefined functions and variables
. /etc/profile
if [ "${1}" == "toggleaudio" ];then
# Toggle audio output
CURRENTAUDIO=$(get_setting "audio.device")
case "${CURRENTAUDIO}" in
"headphone")
echo "setting speakers"
2022-08-31 10:39:50 +00:00
amixer cset name='Playback Path' SPK
2022-08-31 01:26:25 +00:00
set_setting "audio.device" "speakers"
;;
"auto"|"speakers"|*)
echo "setting headphones"
2022-08-31 10:39:50 +00:00
amixer cset name='Playback Path' HP
2022-08-31 01:26:25 +00:00
set_setting "audio.device" "headphone"
;;
esac
fi
if [ "${1}" == "setaudio" ];then
# Set audio output second parameter is either headphones or speakers
case "${2}" in
"headphone")
echo "setting headphones"
2022-08-31 10:39:50 +00:00
amixer cset name='Playback Path' HP
2022-08-31 01:26:25 +00:00
set_setting "audio.device" "headphone"
;;
"auto"|"speakers"|*)
echo "setting speakers"
2022-08-31 10:39:50 +00:00
amixer cset name='Playback Path' SPK
2022-08-31 01:26:25 +00:00
set_setting "audio.device" "speakers"
;;
esac
fi
if [ "${1}" == "vol" ];then
VOLSTEP=1
if [ -n "${3}" ]; then
VOLSTEP="${3}"
fi
CURRENTVOL=$(get_setting "audio.volume")
MAXVOL=100
MINVOL=0
if [ "${2}" == "+" ]; then
STEPVOL=$(($CURRENTVOL+$VOLSTEP))
elif [ "${2}" == "-" ]; then
STEPVOL=$(($CURRENTVOL-$VOLSTEP))
else
STEPVOL=${2}
fi
[ "$STEPVOL" -ge "$MAXVOL" ] && STEPVOL="$MAXVOL"
[ "$STEPVOL" -le "$MINVOL" ] && STEPVOL="$MINVOL"
amixer set "${DEVICE_AUDIO_MIXER}" ${STEPVOL}%
alsactl store -f /storage/.config/asound.state
set_setting "audio.volume" ${STEPVOL}
fi
if [ "${1}" == "bright" ]; then
STEPS="5"
2022-08-31 11:00:57 +00:00
BRIGHTNESS_DEV="$(ls /sys/class/backlight)"
CURRENTBRIGHT=$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/brightness)
MAXBRIGHT="100" #$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/max_brightness)
2022-08-31 01:26:25 +00:00
MINBRIGHT="2"
if [ "${2}" == "+" ]; then
STEPBRIGHT=$(($CURRENTBRIGHT+$STEPS))
elif [ "${2}" == "-" ]; then
STEPBRIGHT=$(($CURRENTBRIGHT-$STEPS))
else
STEPBRIGHT=${2}
fi
[ "$STEPBRIGHT" -ge "$MAXBRIGHT" ] && STEPBRIGHT="$MAXBRIGHT"
[ "$STEPBRIGHT" -le "$MINBRIGHT" ] && STEPBRIGHT="$MINBRIGHT"
#echo "Setting bright to $STEPBRIGHT"
2022-08-31 11:00:57 +00:00
echo "${STEPBRIGHT}" > /sys/class/backlight/${BRIGHTNESS_DEV}/brightness
set_setting "system.brightness" $(cat /sys/class/backlight/${BRIGHTNESS_DEV}/brightness)
2022-08-31 01:26:25 +00:00
fi