forked from adafruit/Raspberry-Pi-Installer-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi-touch-cam.sh
executable file
·137 lines (115 loc) · 3.81 KB
/
pi-touch-cam.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
if [ $(id -u) -ne 0 ]; then
echo "Installer must be run as root."
echo "Try 'sudo bash $0'"
exit 1
fi
clear
echo "This script will install and/or modify"
echo "packages needed for the Adafruit Pi"
echo "Camera project. It should be installed"
echo "atop one of Adafruit's PiTFT-enabled"
echo "Raspbian setups (either resistive or"
echo "capacitive), NOT a stock Raspbian OS."
echo
echo "Operations performed include:"
echo "- In /boot/config.txt, enable Pi"
echo " camera and boost PiTFT speed"
echo "- apt-get update"
echo "- Install Python libraries:"
echo " picamera, pygame, PIL"
echo "- Downgrade SDL library for pygame"
echo " touch compatibility"
echo "- Download Dropbox Updater and"
echo " Adafruit Pi Cam software"
echo
echo "NEVER perform an 'apt-get upgrade' on"
echo "a PiTFT-enabled system; it may fail to"
echo "boot. Upgrades, if necessary, should"
echo "be done by downloading & installing"
echo "the latest PiTFT-enabled OS image from"
echo "Adafruit and running this script."
echo
echo "Run time 10+ minutes. Reboot required."
echo
if [ "$1" != '-y' ]; then
echo -n "CONTINUE? [y/N]"
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
fi
echo "Continuing..."
if ! grep -q "dtoverlay=pitft" /boot/config.txt ; then
echo "PiTFT overlay not in /boot/config.txt."
echo "Run script on Adafruit PiTFT-enabled OS."
echo "Canceling."
exit 1
fi
echo "Configuring camera + PiTFT settings..."
# Set PiTFT speed to 80 MHz, 60 Hz
sed -i 's/speed=.*,fps=.*/speed=80000000,fps=60/g' /boot/config.txt
# Check if Pi camera is enabled. If not, add it...
if ! grep -q "^start_x=" /boot/config.txt ; then
# start_x (camera) line not present, add it
echo "start_x=1" >> /boot/config.txt
else
# start_x exists, make sure it's set to 1
sed -i 's/^start_x=.*/start_x=1/g' /boot/config.txt
fi
# gpu_mem must be >= 128 MB for camera to work
NUMBER=$(grep "^gpu_mem=" /boot/config.txt | sed 's/[^0-9]*//g')
if [ -z $NUMBER ]; then
# gpu_mem isn't set. Add to config
echo "gpu_mem=128" >> /boot/config.txt
elif [ $NUMBER -lt 128 ] ; then
# gpu_mem present but too small; increase to 128MB
sed -i 's/^gpu_mem=.*/gpu_mem=128/g' /boot/config.txt
fi # else gpu_mem OK as-is
echo "Installing prerequisite packages..."
# Enable Wheezy package sources
echo "deb http://archive.raspbian.org/raspbian wheezy main
" > /etc/apt/sources.list.d/wheezy.list
# Set stable as default package source (currently jessie)
echo "APT::Default-release \"stable\";
" > /etc/apt/apt.conf.d/10defaultRelease
# Set priority for libsdl from wheezy higher then the jessie package
echo "Package: libsdl1.2debian
Pin: release n=jessie
Pin-Priority: -10
Package: libsdl1.2debian
Pin: release n=wheezy
Pin-Priority: 900
" > /etc/apt/preferences.d/libsdl
# Update the APT package index files, install Python libraries
sudo apt-get update
sudo apt-get -y --force-yes install python-picamera python-pygame python-imaging
echo "Downgrading SDL library..."
apt-get -y --force-yes install libsdl1.2debian/wheezy
echo "Downloading Dropbox uploader and"
echo "Adafruit Pi Cam to home directory..."
cd ~pi
wget https://github.com/andreafabrizi/Dropbox-Uploader/archive/master.zip
unzip master.zip
rm master.zip
mv Dropbox-Uploader-master Dropbox-Uploader
wget https://github.com/adafruit/adafruit-pi-cam/archive/master.zip
unzip master.zip
rm master.zip
chown -R pi:pi Dropbox-Uploader adafruit-pi-cam-master
# Add lines to /etc/rc.local (commented out by default):
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
# Prompt to reboot!
echo
echo "Camera and PiTFT settings won't take"
echo "effect until next boot."
echo
echo -n "REBOOT NOW? [y/N]"
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Exiting without reboot."
exit 0
fi
echo "Reboot started..."
reboot