install.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh
  2. INSTALL_DIR="/opt/lenovo_fix"
  3. if pidof systemd 2>&1 1>/dev/null; then
  4. systemctl stop lenovo_fix.service >/dev/null 2>&1
  5. elif pidof runit 2>&1 1>/dev/null; then
  6. sv down lenovo_fix >/dev/null 2>&1
  7. elif pidof openrc 2>&1 1>/dev/null; then
  8. rc-service lenovo_fix stop >/dev/null 2>&1
  9. fi
  10. mkdir -p "$INSTALL_DIR" >/dev/null 2>&1
  11. set -e
  12. cd "$(dirname "$0")"
  13. echo "Copying config file..."
  14. if [ ! -f /etc/lenovo_fix.conf ]; then
  15. cp etc/lenovo_fix.conf /etc
  16. else
  17. echo "Config file already exists, skipping."
  18. fi
  19. if pidof systemd 2>&1 1>/dev/null; then
  20. echo "Copying systemd service file..."
  21. cp systemd/lenovo_fix.service /etc/systemd/system
  22. elif pidof runit 2>&1 1>/dev/null; then
  23. echo "Copying runit service file"
  24. cp -R runit/lenovo_fix /etc/sv/
  25. elif pidof openrc-init 2>&1 1>/dev/null; then
  26. echo "Copying OpenRC service file"
  27. cp -R openrc/lenovo_fix /etc/init.d/lenovo_fix
  28. chmod 755 /etc/init.d/lenovo_fix
  29. fi
  30. echo "Building virtualenv..."
  31. cp -n requirements.txt lenovo_fix.py mmio.py "$INSTALL_DIR"
  32. cd "$INSTALL_DIR"
  33. /usr/bin/python3 -m venv venv
  34. . venv/bin/activate
  35. pip install wheel
  36. pip install -r requirements.txt
  37. if pidof systemd 2>&1 1>/dev/null; then
  38. echo "Enabling and starting systemd service..."
  39. systemctl daemon-reload
  40. systemctl enable lenovo_fix.service
  41. systemctl restart lenovo_fix.service
  42. elif pidof runit 2>&1 1>/dev/null; then
  43. echo "Enabling and starting runit service..."
  44. ln -sv /etc/sv/lenovo_fix /var/service/
  45. sv up lenovo_fix
  46. elif pidof openrc-init 2>&1 1>/dev/null; then
  47. echo "Enabling and starting OpenRC service..."
  48. rc-update add lenovo_fix default
  49. rc-service lenovo_fix start
  50. fi
  51. echo "All done."