-
Notifications
You must be signed in to change notification settings - Fork 1
/
runme2nd
executable file
·262 lines (197 loc) · 8.71 KB
/
runme2nd
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env bash
# Copyright (c) 2013-2016 All Right Reserved Alec Clews
#
# author: Alec Clews
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
#Calulate the absoloute of the where we are called from
LOC=$(cd $(dirname "$0") ; pwd)
# Add Check to encourage users to keep system up to date
echo 'APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};' | \
sudo tee -a /etc/apt/apt.conf.d/15update-stamp > /dev/null
# Set initial check to every 7 days
echo About to add a user prompt to suggest package update after 7 days
echo '# Check apt-get is run every few days' |sudo tee /etc/profile.d/checkUpgrade.sh > /dev/null
echo 'no_of_days=7' |sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo 'no_of_seconds=$(($no_of_days*24*60*60))' |sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo 'if [[ ! -e /var/lib/apt/periodic/update-success-stamp ]] ||\' |sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo ' (( ( $(date +%s) - $(stat -c %Y /var/lib/apt/periodic/update-success-stamp) ) > $no_of_seconds )) ; then' |\
sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo ' echo It has been at least $no_of_days days since the last update' |sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo ' echo Please run \"sudo apt-get update \&\& sudo apt-get -y upgrade\"' |\
sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo fi | sudo tee -a /etc/profile.d/checkUpgrade.sh > /dev/null
echo
echo About to fully upgrade all relevant packages and optionally install others
echo This will take some time
echo
# In case the upgrade does nothing create the masrker file
sudo touch /var/lib/apt/periodic/update-success-stamp
# Make sure system is fully up to date
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
ask() {
read -p "$@" -r < /dev/tty
echo $REPLY
}
echo 'We will now install a few useful development tools (editors, source code control etc.)'
sudo apt-get -y install vim git git-gui git-doc tmux ack-grep locate python-setuptools
sudo easy_install pip
sudo pip install virtualenv virtualenvwrapper
echo
echo We can do put some host setttings in the /boot/machine.local and you can edit them on your laptop as needed
if [[ $(ask "Do you wish to configure the /boot/machine.local file?[y/N] ") =~ ^[Yy]$ ]]
then
if [[ $(ask 'Do you wish to use an initial hostname of a) '$(hostname)' or a b) CPU serial number based hostname?[A/b] ') =~ ^[Aa]$ ]]
then
newhostname=$(hostname)
else
newhostname=$'rpi$(sed -nEe \'/^Serial\t\t: ........(........)$/s//\\1/p\' /proc/cpuinfo)'
fi
cat <<EOF | sudo tee /boot/machine.local
# Edit this file and reboot the Pi.
# NB Insert the SD card into a workstation and you can edit the file as well
newhostname=$newhostname # Host for /etc/host
#newhostname=<my alternative hostname> # Host for /etc/host use instead if wanted
#wifihostname=wfipi # Hostname for wifi interface
#wifiSSID=wifipi-ap
#wifipsk=secretpsk
#wifi_ap_network=16 # 01-254
#interface=wlan0
#channel=6
#driver=hostpad
#
EOF
cat <<'EOF' | sudo tee /usr/local/sbin/config-hostname
#!/bin/sh
if [ -f /boot/machine.local ] ; then
. /boot/machine.local # dash does not support `source` keyword
oldhostname=$(hostname)
if [ -n "$newhostname" -a "$newhostname" != "$oldhostname" ] ; then
sudo hostname $newhostname
echo $newhostname | sudo tee /etc/hostname > /dev/null
sudo sed -ie 's/^\(..*\)'$oldhostname'\(.*\)$/\1'$newhostname'\2/' /etc/hosts
sudo invoke-rc.d hostname.sh start
sudo invoke-rc.d networking force-reload
sudo invoke-rc.d avahi-daemon force-reload
sudo /etc/init.d/ssh restart
logger "Changed hostname to $(hostname) on $interface"
logger "About to reboot"
sudo init 6
fi
#todo Add wifihostname to interface
fi
EOF
sudo chmod +x /usr/local/sbin/config-hostname
sudo sed -ie '/exit 0/i\
[ -x /usr/local/sbin/config-hostname ] && /usr/local/sbin/config-hostname
' /etc/rc.local
fi
if [[ $(ask "Do you wish to install support for the Freetronics Pileven board?[y/N] ") =~ ^[Yy]$ ]] ; then
$LOC/installPiLeven.sh
fi
echo
if [[ $(ask "Do you wish to install support for webdav so you can use Box.com or other services?[y/N] ") =~ ^[Yy]$ ]] ; then
echo When asked \"Should unprivileged users be allowed to mount WebDAV resources?\" say yes
echo
echo
sudo apt-get install -y davfs2 # Answer yes to price question
echo \#https://dav.box.com/dav /home/$USER/Box davfs user,noauto,uid=$USER,file_mode=600,dir_mode=700 0 1 | sudo tee -a /etc/fstab
sudo usermod -aG davfs2 $USER
mkdir ~/.davfs2/
echo "#https://dav.box.com/dav usere@mail boxpassword" >> ~/.davfs2/secrets
chmod 0600 ~/.davfs2/secrets
echo you will need to login again and edit /etc/fstab and ~/.davfs2/secrets
ask 'You can then mount your serice using "mount ~/Box" for instance. Press any key to continue...'
fi
echo
if [[ $(ask "Do you wish to install the Robot OS? (http://ros.org)[y/N] ") =~ ^[Yy]$ ]]; then
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu trusty main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 0xB01FA116
sudo apt-get update
sudo apt-get install -y ros-jade-ros-base
sudo rosdep init
rosdep update
echo You will need to install individual ROS Packages. There are currently $(apt-cache search ros-jade|wc -l) packages.
echo To see a list run the command \"apt-cache search ros-jade\"
echo "source /opt/ros/jade/setup.bash" | tee /etc/profile.d/ros_setup.sh
fi
echo
if [[ $(ask "Do you wish to install the Arduino Dev Tools? [y/N] ") =~ ^[Yy]$ ]] ; then
sudo apt-get -y install arduino arduino-mk libdevice-serialport-perl
sudo pip install ino
fi
echo
if [[ $(ask "Do you wish to install node.js environment manager (nvm) and other dev tools? [y/N] ") =~ ^[Yy]$ ]]
then
sudo apt-get -y install minicom arduino arduino-mk libdevice-serialport-perl
curl -o - https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
source ~/.nvm/nvm.sh
nvm install 5.11.1 # 6.x might work. Needs to be tested
npm -g install gulp
fi
echo
if [[ $(ask "Do you wish to install firmata etc for Simplebot? [y/N] ") =~ ^[Yy]$ ]] ; then
cd ~
[ -d simplebot ] && rm -rf simplebot
git clone https://github.com/nodebotsau/simplebot
cd simplebot
npm install
npm install nodebots-interchange # To be removed in the future
interchange install hcsr04 -f -a nano -p /dev/ttyUSB0
cd ~
fi
echo
if [[ $(ask "Do you wish to install Robotnik ? [y/N] ") =~ ^[Yy]$ ]] ; then
echo
if [[ $(ask "Do you prefer the componentEnhancement branch from @ajfisher? [y/N] ") =~ ^[Yy]$ ]] ; then
git clone -b componentEnhancement https://github.com/ajfisher/robotnik.git ~/robotnik
else
git clone https://github.com/makenai/robotnik.git ~/robotnik
fi
cd ~/robotnik
npm install
gulp
sudo apt-get install -y iceweasel
echo
echo 'N.B. To run the Robotnik user interface "cd ~/robotnik && npm run webserver & sleep 10 && iceweasel http://localhost:3000 &"'
cd
fi
echo
if [[ $(ask "Do you wish to install Go lang and gobot (e.g. for SimpleBot dev) Note: Takes an hour or two...? [y/N] ") =~ ^[Yy]$ ]] ; then
bash <(wget -O - https://raw.githubusercontent.com/alecthegeek/CCHS_Raspian_for_IoT/master/installGo)
mkdir -p ~/gobot/{src,bin,pkg}
export GOPATH=~/gobot
cd $GOPATH
#sudo apt-get -y install mercurial
source /etc/profile.d/golang.sh
go get -d -u github.com/hybridgroup/gobot/...
go install github.com/hybridgroup/gobot/platforms/raspi
go get -u github.com/hybridgroup/gobot/gobot
fi
echo
# Remove anything out of date
sudo apt-get autoremove
# Save a few hundred Mb of disk space by removing downloaded deb archives
sudo apt-get clean
# Stop raspi-config from running on next reboot
echo Please use sudo raspi-config to configure additional options and use sudo apt-get dist-upgrade on a regular basis
read -p "System will reboot. Press any key to continue" -n 1 -r < /dev/tty
sed -ie '/runme2nd/d' ~/.profile
sudo touch /forcefsck
sudo init 6