-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
154 lines (137 loc) · 4.95 KB
/
install.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
red=`tput setaf 1`
reset=`tput sgr0`
# edit config file
tput setaf 2;echo "------------------------------------------------"
echo "writing i2c information to /etc/modules"
echo "------------------------------------------------"
tput sgr0
if ! grep -q "i2c-bcm2708" /etc/modules
then
echo "i2c-bcm2708" >> /etc/modules
else
echo "i2c data already added"
fi
# add soundcard
tput setaf 2;echo "------------------------------------------------"
echo "making the usb soundcard the default"
echo "------------------------------------------------"
tput sgr0
if ! grep -Pzoq "pcm.!default { \n type hw \n card 1 \n} \n \nctl.!default { \n type hw \n card 1 \n} \n" /etc/asound.conf
then
touch /etc/asound.conf
echo "pcm.!default { \n type hw \n card 1 \n} \n \nctl.!default { \n type hw \n card 1 \n} \n" >> /etc/asound.conf
amixer set PCM 80%
else
echo "soundcard configuration data already added"
fi
# update all installed packages just in case
tput setaf 2;echo "------------------------------------------------"
echo "updating all installed packages"
echo "------------------------------------------------"
tput sgr0
sudo apt-get update
sudo apt-get upgrade
# pip
tput setaf 2;echo "------------------------------------------------"
echo "installing pip"
echo "------------------------------------------------"
tput sgr0
sudo apt install python-pip
# display libraries
tput setaf 2;echo "------------------------------------------------"
echo "installing python dependencies"
echo "------------------------------------------------"
tput sgr0
sudo apt-get install python-dev
sudo apt-get install python-smbus
sudo apt-get install python-serial
sudo apt-get install python-imaging
# install spi-dev
tput setaf 2;echo "------------------------------------------------"
echo "installing spi-dev"
echo "------------------------------------------------"
tput sgr0;
$currentdir = echo pwd
cd ~
mkdir python-spi
cd python-spi
wget https://raw.github.com/doceme/py-spidev/master/setup.py
wget https://raw.github.com/doceme/py-spidev/master/spidev_module.c
wget https://raw.github.com/doceme/py-spidev/master/README.md
wget https://raw.github.com/doceme/py-spidev/master/CHANGELOG.md
sudo python setup.py install
cd $currentdir
# python libraries
tput setaf 2;echo "------------------------------------------------"
echo "installing python libraries"
echo "------------------------------------------------"
tput sgr0;
pip install Pillow
pip install pygame
# add our scripts to autostart
tput setaf 2;echo "------------------------------------------------"
echo "adding scripts to autostart"
echo "------------------------------------------------"
tput sgr0;
run_autostart_script()
{
ANSWER=$1
if [ "$ANSWER" = "master" ]
then
# if there is no such line already, add it
if ! grep -q "@sudo /usr/bin/python2.7 /home/pi/nfcradio/project/src/Master/MasterMain.py" /home/pi/.config/lxsession/LXDE-pi/autostart
then
echo "@sudo /usr/bin/python2.7 /home/pi/nfcradio/project/src/Master/MasterMain.py" >> /home/pi/.config/lxsession/LXDE-pi/autostart
else
echo "autostart data already added"
fi
elif [ "$ANSWER" = "slave" ]
then
# if there is no such line already, add it
if ! grep -q "@sudo /usr/bin/python2.7 /home/pi/nfcradio/project/src/Slave/SlaveMain.py" /home/pi/.config/lxsession/LXDE-pi/autostart
then
echo "@sudo /usr/bin/python2.7 /home/pi/nfcradio/project/src/Slave/SlaveMain.py" >> /home/pi/.config/lxsession/LXDE-pi/autostart
else
echo "autostart data already added"
fi
else
echo "wrong input! are you running on the ${red}master${reset} or ${red}slave${reset}?"
read alternative_user_input
run_autostart_script $alternative_user_input
fi
}
echo "setting up autostart. are you running on the ${red}master${reset} or ${red}slave${reset}?"
read user_input
run_autostart_script $user_input
# completed
tput setaf 2;echo "------------------------------------------------"
echo "installation completed."
echo "------------------------------------------------${reset}"
# now reboot
reboot_prompt()
{
if [ "$1" = "yes" ]
then
echo "${red}rebooting in 5 seconds."
sleep 1
echo "rebooting in 4 seconds."
sleep 1
echo "rebooting in 3 seconds."
sleep 1
echo "rebooting in 2 seconds."
sleep 1
echo "rebooting in 1 seconds.${reset}"
sleep 1
reboot
elif [ "$1" = "no" ]
then
echo "not rebooting. not all changes will take effect."
else
echo "wrong input! a reboot is necessary for the changes to change effect. do you want to reboot now? ${red}yes${reset} or ${red}no${reset}?"
read reboot_input
reboot_prompt $reboot_input
fi
}
echo "a reboot is necessary for the changes to change effect. do you want to reboot now? ${red}yes${reset} or ${red}no${reset}?"
read reboot_input
reboot_prompt $reboot_input