#!/usr/bin/env bash # Copyright (c) 2013-2016 All Right Reserved Alec Clews # # author: Alec Clews # alecclews@gmail.com # # 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 < # 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