-
Notifications
You must be signed in to change notification settings - Fork 1
/
runme1st
executable file
·133 lines (103 loc) · 3.97 KB
/
runme1st
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
#!/usr/bin/env bash
# Copyright (c) 2013-2106 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.
#
#
# 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 \<yourName\>pi\<n\> 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