distribution/packages/sysutils/sleep/sources/sleep.sh

60 lines
1.3 KiB
Bash
Raw Normal View History

2022-02-05 14:23:32 +00:00
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
. /etc/profile
2022-02-05 14:23:32 +00:00
case $1 in
pre)
if [ "${DEVICE_FAKE_JACKSENSE}" == "true" ]
then
2022-09-29 20:44:45 +00:00
nohup systemctl stop headphones & >/dev/null 2>&1
fi
if [ "${DEVICE_VOLUMECTL}" == "true" ]
then
2022-09-29 20:44:45 +00:00
nohup systemctl stop volume & >/dev/null 2>&1
fi
# RG351x devices are notorious for losing USB when they sleep.
if [[ "${HW_DEVICE}" =~ RG351 ]]
then
modprobe -r dwc2
fi
2022-09-29 20:44:45 +00:00
nohup alsactl store -f /storage/.config/asound.state >/dev/null 2>&1
2022-09-29 20:44:45 +00:00
wait
2022-02-05 14:23:32 +00:00
touch /run/.last_sleep_time
;;
post)
alsactl restore -f /storage/.config/asound.state
if [[ "${HW_DEVICE}" =~ RG351 ]]
then
modprobe -i dwc2
fi
if [ "${DEVICE_FAKE_JACKSENSE}" == "true" ]
then
2022-09-29 20:44:45 +00:00
nohup systemctl start headphones & >/dev/null 2>&1
fi
if [ "${DEVICE_VOLUMECTL}" == "true" ]
then
2022-09-29 20:44:45 +00:00
nohup systemctl start volume & >/dev/null 2>&1
fi
DEVICE_VOLUME=$(get_setting "audio.volume" 2>/dev/null)
2022-09-29 20:44:45 +00:00
nohup amixer -M set "${DEVICE_AUDIO_MIXER}" ${DEVICE_VOLUME}% & >/dev/null 2>&1
BRIGHTNESS_DEV="$(ls /sys/class/backlight | head -n 1)"
BRIGHTNESS=$(get_setting system.brightness)
echo ${BRIGHTNESS} >/sys/class/backlight/${BRIGHTNESS_DEV}/brightness
2022-09-29 20:44:45 +00:00
wait
;;
2022-02-05 14:23:32 +00:00
esac