install.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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
  5. elif pidof runit 2>&1 1>/dev/null; then
  6. sv down lenovo_fix &>/dev/null
  7. fi
  8. mkdir -p "$INSTALL_DIR" &>/dev/null
  9. set -e
  10. cd "$(dirname "$0")"
  11. echo "Copying config file..."
  12. if [ ! -f /etc/lenovo_fix.conf ]; then
  13. cp etc/lenovo_fix.conf /etc
  14. else
  15. echo "Config file already exists, skipping."
  16. fi
  17. if pidof systemd 2>&1 1>/dev/null; then
  18. echo "Copying systemd service file..."
  19. cp systemd/lenovo_fix.service /etc/systemd/system
  20. elif pidof runit 2>&1 1>/dev/null; then
  21. echo "Copying runit service file"
  22. cp -R runit/lenovo_fix /etc/sv/
  23. fi
  24. echo "Building virtualenv..."
  25. cp -n requirements.txt lenovo_fix.py mmio.py "$INSTALL_DIR"
  26. cd "$INSTALL_DIR"
  27. /usr/bin/python3 -m venv venv
  28. . venv/bin/activate
  29. pip install -r requirements.txt
  30. if pidof systemd 2>&1 1>/dev/null; then
  31. echo "Enabling and starting systemd service..."
  32. systemctl daemon-reload
  33. systemctl enable lenovo_fix.service
  34. systemctl restart lenovo_fix.service
  35. elif pidof runit 2>&1 1>/dev/null; then
  36. echo "Enabling and starting runit service..."
  37. ln -sv /etc/sv/lenovo_fix /var/service/
  38. sv up lenovo_fix
  39. fi
  40. echo "All done."