No Description
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.

pi-touch-cam.sh 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/bash
  2. if [ $(id -u) -ne 0 ]; then
  3. echo "Installer must be run as root."
  4. echo "Try 'sudo bash $0'"
  5. exit 1
  6. fi
  7. clear
  8. echo "This script will install and/or modify"
  9. echo "packages needed for the Adafruit Pi"
  10. echo "Camera project. It requires that the"
  11. echo "adafruit-pitft.sh installer script (for"
  12. echo "PiTFT display support) was run first."
  13. echo
  14. echo "Operations performed include:"
  15. echo "- In /boot/config.txt, enable camera"
  16. echo "- apt-get update"
  17. echo "- Install Python libraries:"
  18. echo " picamera, pygame, PIL"
  19. echo "- Downgrade SDL library for pygame"
  20. echo " touch compatibility"
  21. echo "- Download Dropbox Updater and"
  22. echo " Adafruit Pi Cam software"
  23. echo
  24. echo "Run time 5+ minutes. Reboot required."
  25. echo
  26. if [ "$1" != '-y' ]; then
  27. echo -n "CONTINUE? [y/N]"
  28. read
  29. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  30. echo "Canceled."
  31. exit 0
  32. fi
  33. fi
  34. echo "Continuing..."
  35. if ! grep -q "dtoverlay=pitft" /boot/config.txt ; then
  36. echo "PiTFT overlay not in /boot/config.txt."
  37. echo "Download & run adafruit-pitft.sh first."
  38. echo "Canceling."
  39. exit 1
  40. fi
  41. echo "Configuring camera + PiTFT settings..."
  42. # Set PiTFT speed to 80 MHz, 60 Hz
  43. sed -i 's/speed=.*,fps=.*/speed=80000000,fps=60/g' /boot/config.txt
  44. # Check if Pi camera is enabled. If not, add it...
  45. if ! grep -q "^start_x=" /boot/config.txt ; then
  46. # start_x (camera) line not present, add it
  47. echo "start_x=1" >> /boot/config.txt
  48. else
  49. # start_x exists, make sure it's set to 1
  50. sed -i 's/^start_x=.*/start_x=1/g' /boot/config.txt
  51. fi
  52. # gpu_mem must be >= 128 MB for camera to work
  53. NUMBER=$(grep "^gpu_mem=" /boot/config.txt | sed 's/[^0-9]*//g')
  54. if [ -z $NUMBER ]; then
  55. # gpu_mem isn't set. Add to config
  56. echo "gpu_mem=128" >> /boot/config.txt
  57. elif [ $NUMBER -lt 128 ] ; then
  58. # gpu_mem present but too small; increase to 128MB
  59. sed -i 's/^gpu_mem=.*/gpu_mem=128/g' /boot/config.txt
  60. fi # else gpu_mem OK as-is
  61. echo "Installing prerequisite packages..."
  62. # Enable Wheezy package sources (for SDL downgrade)
  63. echo "deb http://archive.raspbian.org/raspbian wheezy main
  64. " > /etc/apt/sources.list.d/wheezy.list
  65. # Set 'stable' as default package source (current OS)
  66. echo "APT::Default-release \"stable\";
  67. " > /etc/apt/apt.conf.d/10defaultRelease
  68. # Set priority for libsdl from Wheezy higher than current package
  69. echo "Package: libsdl1.2debian
  70. Pin: release n=stretch
  71. Pin-Priority: -10
  72. Pin: release n=jessie
  73. Pin-Priority: -10
  74. Package: libsdl1.2debian
  75. Pin: release n=wheezy
  76. Pin-Priority: 900
  77. " > /etc/apt/preferences.d/libsdl
  78. # Update the APT package index files, install Python libraries
  79. sudo apt-get update
  80. sudo apt-get -y --force-yes install python-picamera python-pygame python-imaging
  81. echo "Downgrading SDL library..."
  82. apt-get -y --force-yes install libsdl1.2debian/wheezy
  83. echo "Downloading Dropbox uploader and"
  84. echo "Adafruit Pi Cam to home directory..."
  85. cd ~pi
  86. wget https://github.com/andreafabrizi/Dropbox-Uploader/archive/master.zip
  87. unzip master.zip
  88. rm master.zip
  89. mv Dropbox-Uploader-master Dropbox-Uploader
  90. wget https://github.com/adafruit/adafruit-pi-cam/archive/master.zip
  91. unzip master.zip
  92. rm master.zip
  93. chown -R pi:pi Dropbox-Uploader adafruit-pi-cam-master
  94. # Add lines to /etc/rc.local (commented out by default):
  95. sed -i 's/^exit 0/# Enable this line to run camera at startup:\n# cd \/home\/pi\/adafruit-pi-cam-master ; sudo python cam.py\n\nexit 0/g' /etc/rc.local
  96. # Prompt to reboot!
  97. echo
  98. echo "Camera and PiTFT settings won't take"
  99. echo "effect until next boot."
  100. echo
  101. echo -n "REBOOT NOW? [y/N]"
  102. read
  103. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  104. echo "Exiting without reboot."
  105. exit 0
  106. fi
  107. echo "Reboot started..."
  108. reboot