mirror of
https://github.com/pentoo/pentoo-overlay
synced 2026-02-09 08:52:31 +01:00
pentoo-system: migrate away from the local.d stuff Anton hates, fix the scripts to be better and faster, make them proper services
This commit is contained in:
parent
a80ed40f3c
commit
4cc39cfa4f
5 changed files with 184 additions and 4 deletions
27
pentoo/pentoo-system/files/pentoo-linux-symlinks.initd
Normal file
27
pentoo/pentoo-system/files/pentoo-linux-symlinks.initd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/sbin/openrc-run
|
||||
|
||||
start() {
|
||||
ebegin "Starting pentoo-linux-symlinks fixer"
|
||||
##adjust /usr/src/linux link if we are pretty sure we won't screw up the system
|
||||
RETVAL=0
|
||||
KV=$(uname -r)
|
||||
if [ -d "/usr/src/linux-${KV}" ] && [ "$(readlink -e /usr/src/linux)" != "/usr/src/linux-${KV}" ]; then
|
||||
if /usr/bin/qfile /usr/src/linux-${KV} 2>&1 > /dev/null; then
|
||||
if [ -L /usr/src/linux ]; then
|
||||
unlink /usr/src/linux
|
||||
fi
|
||||
ln -s /usr/src/linux-${KV} /usr/src/linux
|
||||
if [ -L /lib/modules/${KV}/build ]; then
|
||||
unlink /lib/modules/${KV}/build
|
||||
fi
|
||||
ln -s /usr/src/linux-${KV} /lib/modules/${KV}/build
|
||||
if [ -L /lib/modules/${KV}/source ]; then
|
||||
unlink /lib/modules/${KV}/source
|
||||
fi
|
||||
ln -s /usr/src/linux-${KV} /lib/modules/${KV}/source
|
||||
else
|
||||
RETVAL=1
|
||||
fi
|
||||
fi
|
||||
eend ${RETVAL} "/usr/src/linux symlink broken, safety check failed, unable to repair"
|
||||
}
|
||||
110
pentoo/pentoo-system/files/pentoo-powersave.initd
Normal file
110
pentoo/pentoo-system/files/pentoo-powersave.initd
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#!/sbin/openrc-run
|
||||
|
||||
##This file is mostly fixes stolen directly from the recommendations of powertop.
|
||||
# For the sake of completeness we will include the fixes we don't want and comment them out with reasoning
|
||||
# XXX: This should be rewritten into acpid and this file should just be an initial call to acpid default.sh
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
|
||||
start() {
|
||||
ebegin "Starting pentoo-powersave"
|
||||
##PM runtime (PCI Devices)
|
||||
##this links to usb and disables usb devices that suck
|
||||
#for i in `find /sys/devices/pci* -name "control"`; do echo "auto" > $i; done
|
||||
|
||||
##USB Suspend
|
||||
#currently this kills usb mice, and stops my cell phone from charging
|
||||
#for i in $(\ls -1 /sys/bus/usb/devices)
|
||||
#do
|
||||
# usb_path="/sys/bus/usb/devices/${i}"
|
||||
# if [ -L ${usb_path}/driver ]
|
||||
# then
|
||||
# if [ "$(ls -al ${usb_path}/driver | grep usbhid)" == "" ]
|
||||
# then
|
||||
# echo "Enabling power saving for non-input device ${usb_path}"
|
||||
# ls -al ${usb_path}/driver
|
||||
# [ -e ${usb_path}/power/autosuspend ] && echo 1 > ${usb_path}/power/autosuspend
|
||||
# [ -e ${usb_path}/power/level ] && echo auto > ${usb_path}/power/level
|
||||
# [ -e ${usb_path}/power/control ] && echo auto > ${usb_path}/power/control
|
||||
# else
|
||||
# echo "Not enabling power saving for input device ${usb_path}"
|
||||
# ls -al ${usb_path}/driver
|
||||
# fi
|
||||
# fi
|
||||
#done
|
||||
|
||||
# allowing to not sync the drive for longer on battery means more lost when we run out of battery, not a fan
|
||||
#echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
|
||||
|
||||
## This TANKS wifi performance way too much
|
||||
#iwconfig wlan0 power timeout 500ms
|
||||
|
||||
#intel sound
|
||||
if [ -e /sys/module/snd_hda_intel/parameters/power_save ]; then
|
||||
echo 1 > /sys/module/snd_hda_intel/parameters/power_save
|
||||
fi
|
||||
|
||||
|
||||
##Making devices take longer to power save means more draw
|
||||
#USB suspend tweaking based on Linux/Documentation/usb/power-management.txt
|
||||
#Change the default autosuspend idle value from 2sec to 60sec
|
||||
#for i in /sys/bus/usb/devices/*/power/autosuspend_delay_ms; do echo 60000 > $i; done
|
||||
#echo 60 > /sys/module/usbcore/parameters/autosuspend
|
||||
|
||||
#disable NMI watchdog (unless we are running a redundant kernel we don't need this)
|
||||
if [ -e /proc/sys/kernel/nmi_watchdog ]
|
||||
then
|
||||
echo 0 > /proc/sys/kernel/nmi_watchdog
|
||||
fi
|
||||
|
||||
if [ -e /sys/devices/system/cpu/sched_mc_power_savings ]
|
||||
then
|
||||
echo 1 > /sys/devices/system/cpu/sched_mc_power_savings
|
||||
fi
|
||||
|
||||
##then the battery specific power savings
|
||||
scsi_path="/sys/class/scsi_host/"
|
||||
cpu_path="/sys/devices/system/cpu/"
|
||||
|
||||
if [ "$(cat /sys/class/power_supply/AC*/online)" = "0" ]; then
|
||||
#battery
|
||||
for CPU in $(\ls ${cpu_path}|grep -E "cpu[0-9]+"); do
|
||||
if [ -e ${cpu_path}/${CPU}/cpufreq/scaling_governor ]; then
|
||||
echo conservative > ${cpu_path}/${CPU}/cpufreq/scaling_governor
|
||||
fi
|
||||
done
|
||||
for controller in $(\ls ${scsi_path}|grep -E "host[0-9]+"); do
|
||||
if [ -e ${scsi_path}${controller}/link_power_management_policy ]; then
|
||||
echo min_power > ${scsi_path}${controller}/link_power_management_policy
|
||||
fi
|
||||
done
|
||||
else
|
||||
#AC
|
||||
for CPU in $(\ls ${scsi_path}|grep -E "cpu[0-9]+"); do
|
||||
if [ -e ${scsi_path}${CPU}/cpufreq/scaling_governor ]; then
|
||||
echo ondemand > ${scsi_path}${CPU}/cpufreq/scaling_governor
|
||||
fi
|
||||
done
|
||||
for controller in $(\ls ${scsi_path}|grep -E "host[0-9]+"); do
|
||||
if [ -e ${scsi_path}${controller}/link_power_management_policy ]; then
|
||||
echo max_performance > ${scsi_path}${controller}/link_power_management_policy
|
||||
fi
|
||||
done
|
||||
fi
|
||||
eend 0
|
||||
}
|
||||
|
||||
stop() {
|
||||
ebegin "Stopping pentoo-powersave"
|
||||
for CPU in $(ls /sys/devices/system/cpu/|grep -E "cpu[0-9]+"); do
|
||||
if [ -e /sys/devices/system/cpu/${CPU}/cpufreq/scaling_governor ]; then
|
||||
echo performance > /sys/devices/system/cpu/${CPU}/cpufreq/scaling_governor
|
||||
fi
|
||||
done
|
||||
|
||||
for controller in $(ls /sys/class/scsi_host/|grep -E "host[0-9]+"); do
|
||||
if [ -e /sys/class/scsi_host/${controller}/link_power_management_policy ]; then
|
||||
echo max_performance > /sys/class/scsi_host/${controller}/link_power_management_policy
|
||||
fi
|
||||
done
|
||||
eend 0
|
||||
}
|
||||
11
pentoo/pentoo-system/files/pentoo-zram.confd
Normal file
11
pentoo/pentoo-system/files/pentoo-zram.confd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# /etc/init.d/pentoo-zram
|
||||
|
||||
# ZRAM creates a virtual swap device in RAM
|
||||
# the data is compressed approximately 3x
|
||||
# defaults to ZRAM_PERCENT=17 if nothing is set
|
||||
|
||||
# How large should zram be as a percentage of ram
|
||||
#ZRAM_PERCENT="17"
|
||||
|
||||
# How large should zram swap be? (overrides ZRAM_PERCENTAGE)
|
||||
#ZRAM_ABSOLUTE="128M"
|
||||
27
pentoo/pentoo-system/files/pentoo-zram.initd
Normal file
27
pentoo/pentoo-system/files/pentoo-zram.initd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/sbin/openrc-run
|
||||
# Copyright 1999-2018 Gentoo Foundation
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
start() {
|
||||
ebegin "Starting pentoo-zram"
|
||||
RETVAL=0
|
||||
if [ -z "${ZRAM_ABSOLUTE}" ]; then
|
||||
#echo $(expr $(awk '/MemTotal/ {print $2}' /proc/meminfo) / 3)k
|
||||
ZRAM_ABSOLUTE=$(echo "$(awk '/MemTotal/ {print $2}' /proc/meminfo) * 0.${ZRAM_PERCENT:-17}" | bc)k
|
||||
fi
|
||||
modprobe zram
|
||||
sleep 1
|
||||
echo $(nproc) >/sys/devices/virtual/block/zram0/max_comp_streams || REVAL=$?
|
||||
echo lz4 >/sys/devices/virtual/block/zram0/comp_algorithm || RETVAL=$?
|
||||
echo "${ZRAM_ABSOLUTE/\.??/}" > /sys/devices/virtual/block/zram0/disksize || RETVAL=$?
|
||||
mkswap /dev/zram0 > /dev/null || RETVAL=$?
|
||||
swapon /dev/zram0 -p 10 > /dev/null || RETVAL=$?
|
||||
eend ${RETVAL}
|
||||
}
|
||||
|
||||
# Swap gets torn down without help from this init script
|
||||
#stop() {
|
||||
# ebegin "Stopping pentoo-zram"
|
||||
# true
|
||||
# eend $?
|
||||
#}
|
||||
|
|
@ -189,10 +189,10 @@ src_install() {
|
|||
insinto /etc/fonts
|
||||
doins "${FILESDIR}"/local.conf
|
||||
|
||||
exeinto /etc/local.d
|
||||
doexe "${FILESDIR}"/00-linux_link.start
|
||||
newexe "${FILESDIR}"/00-speed_shutdown.stop-r2 00-speed_shutdown.stop
|
||||
newexe "${FILESDIR}"/99-power_saving.start-r3 99-power_saving.start
|
||||
newinitd "${FILESDIR}"/pentoo-linux-symlinks.initd pentoo-linux-symlinks
|
||||
newinitd "${FILESDIR}"/pentoo-powersave.initd pentoo-powersave
|
||||
newinitd "${FILESDIR}"/pentoo-zram.initd pentoo-zram
|
||||
newconfd "${FILESDIR}"/pentoo-zram.confd pentoo-zram
|
||||
|
||||
dosym /var/lib/layman/pentoo/scripts/pentoo-updater.sh /usr/sbin/pentoo-updater
|
||||
}
|
||||
|
|
@ -219,4 +219,9 @@ pkg_postinst() {
|
|||
[ "$(md5sum /etc/portage/repos.conf | awk '{ print $1 }')" = "1e1e8a6977e6d2c056cb1223f71d6b07" ] && rm -f /etc/portage/repos.conf
|
||||
fi
|
||||
fi
|
||||
if [[ "${REPLACING_VERSIONS}" < "2018.0-r8" ]]; then
|
||||
#finally removing the local.d crap and making real pentoo services
|
||||
einfo 'You likely want to run "rc-update add pentoo-linux-symlinks default" to migrate to the new symlink fixer.'
|
||||
einfo 'Check out the new /etc/init.d/pentoo-* services and enable the ones you want.'
|
||||
fi
|
||||
}
|
||||
Loading…
Reference in a new issue