#!/usr/bin/env bash # Copyright (c) 2013-2106 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. # # # NB These Scripts support Pi Raspian (Debian) export UPDATE_LABEL="Updated_$(date +%F)" setConfigOption() { CONFIG_FILE=/boot/config.txt if grep "$1=" $CONFIG_FILE ; then sudo sed --in-place -re "s/^#?$1=.+$/$1=$2 #$UPDATE_LABEL/" $CONFIG_FILE else echo $1=$2' #'$UPDATE_LABEL| sudo tee -a $CONFIG_FILE fi } export -f setConfigOption ask() { read -p "$1" -r < /dev/tty echo $REPLY } # Get updated package list sudo apt-get update # Make sure we using the lastest version of config script sudo apt-get install -y raspi-config echo echo I suggest removing the Wolframe engine as it\'s of limited use in IoT echo projects. It will save about 1/2G of disk space and a *lot* of time echo during upgrades if [[ $(ask "Do you wish to remove Wolframe engine? [y/N] ") =~ ^[Yy]$ ]] then #save 1/2G of space sudo apt-get -y purge wolfram-engine fi echo echo echo 'About to start the Raspbery Pi config program (raspi-config).' echo When you are happy with the configuration exit the program and echo we will continue with the rest of the setup. echo At a miniumum you should configure locale, keyboard and timezone. echo Also consider setting up memory GPU split and CPU clocking echo Depending on your project you may also want to set up camera, i2c etc. echo echo echo NOTE: If you are prompted to reboot when running this program answer NO. echo If you make a mistake and say \"yes\" to reboot, don\'t worry. Just run this process again. echo read -p "Press enter when ready" < /dev/tty sudo raspi-config oldhostname=$(cat /etc/hostname) echo echo It is highly recommended that the hostname is changed to something unique on the network. echo If you can\'t think of anything I suggest something like \pi\ where echo n is some single digit number. The current hostname is \"$oldhostname\" echo if [[ $(ask "Do you wish to change the hostname?[y/N] ") =~ ^[Yy]$ ]] then read -p "Please enter the hostname (lowercase letters, \"-\" and numbers only) " -r < /dev/tty echo $REPLY | sudo tee /etc/hostname > /dev/null sudo sed -ie 's/^\(..*\)'$oldhostname'\(.*\)$/\1'$REPLY'\2/' /etc/hosts else echo fi # Rename the pi user account echo echo "You will now be offered to the chance to change the user name of the current user account" echo "from $USER to something of your own choosing" echo echo "N.B. If this process fails you will probably have to re-image your SD card" echo if [[ $(ask "Do you wish to rename the $USER user account?[y/N] ") =~ ^[Yy]$ ]] then read -p "Please enter the new user name " -r < /dev/tty cat <<'EOF' | sudo bash -s $USER $REPLY $HOME for i in /etc/group /etc/passwd /etc/sudoers /etc/shadow ; do sed -rie '/\b'$1'\b/s/\b'$1'\b/'$2'/g' $i done mv $3 /home/$2 EOF USER=$REPLY echo "User name changed to $USER" else echo fi echo If all has gone well you will be able to access this device using ssh $USER@$(cat /etc/hostname).local echo assuming you have Bonjour support on your ssh terminal workstation echo "System will now reboot. Afterwards please login as $USER and the setup process will continue" read -p "Press any key to continue " -n 1 -r < /dev/tty