2018-04-20 10:46:00 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2021-10-30 12:05:48 +02:00
|
|
|
LEGACY_INSTALL_DIR="/opt/lenovo_fix"
|
|
|
|
|
INSTALL_DIR="/opt/throttled"
|
2018-04-20 10:46:00 +02:00
|
|
|
|
2019-03-05 22:50:43 +01:00
|
|
|
if pidof systemd 2>&1 1>/dev/null; then
|
2019-07-12 09:54:06 +02:00
|
|
|
systemctl stop lenovo_fix.service >/dev/null 2>&1
|
2021-10-30 12:05:48 +02:00
|
|
|
systemctl stop throttled.service >/dev/null 2>&1
|
2019-03-05 22:50:43 +01:00
|
|
|
elif pidof runit 2>&1 1>/dev/null; then
|
2019-07-12 09:54:06 +02:00
|
|
|
sv down lenovo_fix >/dev/null 2>&1
|
2021-10-30 12:05:48 +02:00
|
|
|
sv down throttled >/dev/null 2>&1
|
2020-02-20 02:03:44 +01:00
|
|
|
elif pidof openrc 2>&1 1>/dev/null; then
|
|
|
|
|
rc-service lenovo_fix stop >/dev/null 2>&1
|
2021-10-30 12:05:48 +02:00
|
|
|
rc-service throttled stop >/dev/null 2>&1
|
2019-03-05 22:50:43 +01:00
|
|
|
fi
|
2018-04-20 10:46:00 +02:00
|
|
|
|
2021-10-30 12:05:48 +02:00
|
|
|
mv "$LEGACY_INSTALL_DIR" "$INSTALL_DIR" >/dev/null 2>&1
|
|
|
|
|
rm "$INSTALL_DIR/lenovo_fix.py" >/dev/null 2>&1
|
2019-07-12 09:54:06 +02:00
|
|
|
mkdir -p "$INSTALL_DIR" >/dev/null 2>&1
|
2018-04-20 10:46:00 +02:00
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
|
2021-10-30 12:05:48 +02:00
|
|
|
if [ -f /etc/lenovo_fix.conf ]; then
|
|
|
|
|
echo "Updating config filename"
|
2021-11-05 10:17:35 +01:00
|
|
|
mv /etc/lenovo_fix.conf /etc/throttled.conf
|
2021-10-30 12:05:48 +02:00
|
|
|
fi
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Copying config file"
|
2021-10-30 12:05:48 +02:00
|
|
|
if [ ! -f /etc/throttled.conf ]; then
|
|
|
|
|
cp etc/throttled.conf /etc
|
2018-04-20 10:46:00 +02:00
|
|
|
else
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Config file already exists, skipping"
|
2018-04-20 10:46:00 +02:00
|
|
|
fi
|
|
|
|
|
|
2019-03-05 22:50:43 +01:00
|
|
|
if pidof systemd 2>&1 1>/dev/null; then
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Copying systemd service file"
|
2021-10-30 12:05:48 +02:00
|
|
|
cp systemd/throttled.service /etc/systemd/system
|
2021-11-05 13:28:12 +01:00
|
|
|
rm -f /etc/systemd/system/lenovo_fix.service >/dev/null 2>&1
|
2019-03-05 22:50:43 +01:00
|
|
|
elif pidof runit 2>&1 1>/dev/null; then
|
|
|
|
|
echo "Copying runit service file"
|
2021-10-30 12:05:48 +02:00
|
|
|
cp -R runit/throttled /etc/sv/
|
|
|
|
|
rm -r /etc/sv/lenovo_fix >/dev/null 2>&1
|
2020-02-20 02:03:44 +01:00
|
|
|
elif pidof openrc-init 2>&1 1>/dev/null; then
|
|
|
|
|
echo "Copying OpenRC service file"
|
2021-10-30 12:05:48 +02:00
|
|
|
cp -R openrc/throttled /etc/init.d/throttled
|
2021-11-05 13:28:12 +01:00
|
|
|
rm -f /etc/init.d/lenovo_fix >/dev/null 2>&1
|
2021-10-30 12:05:48 +02:00
|
|
|
chmod 755 /etc/init.d/throttled
|
2019-03-05 22:50:43 +01:00
|
|
|
fi
|
2018-04-20 10:46:00 +02:00
|
|
|
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Copying core files"
|
2021-10-30 12:05:48 +02:00
|
|
|
cp requirements.txt throttled.py mmio.py "$INSTALL_DIR"
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Building virtualenv"
|
2018-04-20 10:46:00 +02:00
|
|
|
cd "$INSTALL_DIR"
|
2018-10-19 19:48:11 +02:00
|
|
|
/usr/bin/python3 -m venv venv
|
2018-04-23 14:22:19 +02:00
|
|
|
. venv/bin/activate
|
2020-07-10 07:58:26 +02:00
|
|
|
pip install wheel
|
2018-04-20 10:46:00 +02:00
|
|
|
pip install -r requirements.txt
|
|
|
|
|
|
2019-03-05 22:50:43 +01:00
|
|
|
if pidof systemd 2>&1 1>/dev/null; then
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Enabling and starting systemd service"
|
2019-03-05 22:50:43 +01:00
|
|
|
systemctl daemon-reload
|
2021-10-30 12:05:48 +02:00
|
|
|
systemctl enable throttled.service
|
|
|
|
|
systemctl restart throttled.service
|
2019-03-05 22:50:43 +01:00
|
|
|
elif pidof runit 2>&1 1>/dev/null; then
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Enabling and starting runit service"
|
2021-10-30 12:05:48 +02:00
|
|
|
ln -sv /etc/sv/throttled /var/service/
|
|
|
|
|
sv up throttled
|
2020-02-20 02:03:44 +01:00
|
|
|
elif pidof openrc-init 2>&1 1>/dev/null; then
|
2021-01-04 10:00:56 +01:00
|
|
|
echo "Enabling and starting OpenRC service"
|
2021-10-30 12:05:48 +02:00
|
|
|
rc-update add throttled default
|
|
|
|
|
rc-service throttled start
|
2019-03-05 22:50:43 +01:00
|
|
|
fi
|
2018-04-20 10:46:00 +02:00
|
|
|
|
|
|
|
|
echo "All done."
|