You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4 KiB

  1. try:
  2. from adafruit_shell import Shell
  3. except ImportError:
  4. raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
  5. shell = Shell()
  6. shell.group = 'ADAFRUIT'
  7. def main():
  8. shell.clear()
  9. print("""This script will install Adafruit
  10. fan service, which will turn on an
  11. external fan controlled by a given pin
  12. Operations performed include:
  13. - In /boot/config.txt, enable camera
  14. - apt-get update
  15. - Install Python libraries:
  16. picamera, pygame, PIL
  17. - Downgrade SDL library for pygame
  18. touch compatibility
  19. - Download Dropbox Updater and
  20. Adafruit Pi Cam software
  21. Run time 1+ minutes. Reboot not required.
  22. """)
  23. if not shell.argument_exists('y'):
  24. if not shell.prompt("CONTINUE?", default='n'):
  25. print("Canceled.")
  26. shell.exit()
  27. print("Continuing...")
  28. # check init system (technique borrowed from raspi-config):
  29. shell.group = 'FAN'
  30. shell.info('Checking init system...')
  31. if shell.run_command("which systemctl", True) and shell.run_command("systemctl | grep '\-\.mount'", True):
  32. print("Found systemd, OK!")
  33. elif os.path.isfile("/etc/init.d/cron") and not os.path.islink("/etc/init.d/cron"):
  34. shell.bail("Found sysvinit, but we require systemd")
  35. else:
  36. shell.bail("Unrecognised init system")
  37. shell.info('Adding adafruit_fan.service')
  38. contents = """[Unit]
  39. Description=Fan service for some Adafruit boards
  40. After=network.target
  41. [Service]
  42. Type=oneshot
  43. ExecStartPre=-/bin/bash -c 'echo 4 >/sys/class/gpio/export'
  44. ExecStartPre=/bin/bash -c 'echo out >/sys/class/gpio/gpio4/direction'
  45. ExecStart=/bin/bash -c 'echo 1 >/sys/class/gpio/gpio4/value'
  46. RemainAfterExit=true
  47. ExecStop=/bin/bash -c 'echo 0 >/sys/class/gpio/gpio4/value'
  48. StandardOutput=journal
  49. [Install]
  50. WantedBy=multi-user.target"""
  51. shell.write_text_file("/etc/systemd/system/adafruit_fan.service", contents, append=False)
  52. shell.info('Enabling adafruit_fan.service')
  53. shell.run_command("sudo systemctl enable adafruit_fan.service")
  54. shell.run_command("sudo systemctl start adafruit_fan.service")
  55. shell.info('Done!')
  56. print("You can stop the fan service with 'sudo systemctl stop adafruit_fan.service'")
  57. print("You can start the fan service with 'sudo systemctl start adafruit_fan.service'")
  58. # Main function
  59. if __name__ == "__main__":
  60. shell.require_root()
  61. main()