-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaspianConfig.sh
142 lines (138 loc) · 3.81 KB
/
RaspianConfig.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
#!/bin/bash
#
# ----------------------------------------------------------------------------
# Miniumum configuration Raspberry PI running raspian
# Written by: Phil Huhn
# Version 6
# 2019-03-18 Phil Lint with www.shellcheck.net
#
# Varialbes:
COUNTRY=US
TIMEZONE="michigan"
SERIAL_BT=false
#
if [ "$1" == "-h" ]; then
cat <<EOF
Usage: $0 [options]
-h this help text.
-c country code, default value: ${COUNTRY}
-t timezone code, default value: ${TIMEZONE}
-s serial bluetooth, default value: ${SERIAL_BT}
Example: $0 -c canada -t eastern -s true
EOF
exit
fi
#
echo "=- Configure Raspberry PI -="
date
#
# process of arguments
#
while getopts ":c:s:t:" option
do
case "${option}"
in
c) COUNTRY=${OPTARG};;
t) TIMEZONE=${OPTARG};;
s) SERIAL_BT=$(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]');;
*) echo "Invalid option: ${option} arg: ${OPTARG}"
exit 1
;;
esac
done
#
# Change pi password
#
echo "=- Change password -="
echo " ^d to break out of passwd..."
passwd
#
COUNTRY_L=$(echo "${COUNTRY}" | tr '[:upper:]' '[:lower:]')
COUNTRY_U=$(echo "${COUNTRY}" | tr '[:lower:]' '[:upper:]')
COUNTRY_M="${COUNTRY_U:0:1}${COUNTRY_L:1}"
# echo "${COUNTRY_L} ${COUNTRY_U} ${COUNTRY_M}"
#
TIMEZONE_L=$(echo "${TIMEZONE}" | tr '[:upper:]' '[:lower:]')
TIMEZONE_U=$(echo "${TIMEZONE}" | tr '[:lower:]' '[:upper:]')
TIMEZONE_M="${TIMEZONE_U:0:1}${TIMEZONE_L:1}"
# echo "${TIMEZONE_L} ${TIMEZONE_U} ${TIMEZONE_M}"
#
# Some countries are just uppercase and some are mixed case,
# some are directories and some are files.
echo "=- Set timezone -="
if [ -d "/usr/share/zoneinfo/${COUNTRY_U}" ]; then
echo "${COUNTRY_U}/${TIMEZONE_M}"
sudo ln -sf "/usr/share/zoneinfo/${COUNTRY_U}/${TIMEZONE_M}" /etc/localtime
else
if [ -d "/usr/share/zoneinfo/${COUNTRY_M}" ]; then
echo "${COUNTRY_M}/${TIMEZONE_M}"
sudo ln -sf "/usr/share/zoneinfo/${COUNTRY_M}/${TIMEZONE_M}" /etc/localtime
else
if [ -f "/usr/share/zoneinfo/${COUNTRY_U}" ]; then
echo "${COUNTRY_U}"
sudo ln -sf "/usr/share/zoneinfo/${COUNTRY_U}" /etc/localtime
else
if [ -f "/usr/share/zoneinfo/${COUNTRY_M}" ]; then
echo "${COUNTRY_M}"
sudo ln -sf "/usr/share/zoneinfo/${COUNTRY_M}" /etc/localtime
else
echo "Timezone of ${COUNTRY_U} and ${TIMEZONE_M}, not set."
fi
fi
fi
fi
if [ ! -e /etc/localtime ] ; then
ls -l /etc/localtime
echo "Broken timezone link."
echo sudo ln -sf "/usr/share/zoneinfo/{COUNTRY}/{TIMEZONE}" /etc/localtime
ls /usr/share/zoneinfo/
fi
#
# Configure bluetooth serial connection
#
if [ "${SERIAL_BT}" == "true" ]; then
BT_DIR=/usr/local/bluetooth
if [ ! -d "${BT_DIR}" ]; then
echo "=- Created ${BT_DIR} directory -="
sudo mkdir ${BT_DIR}
fi
if [ ! -f "${BT_DIR}/btserial.sh" ]; then
cd "${BT_DIR}" || exit
sudo wget https://raw.githubusercontent.com/PHuhn/RaspberryPI/master/btserial.sh
sudo chmod 755 ./btserial.sh
echo "=- Created ${BT_DIR}/btserial.sh file -="
# now edit /etc/rc.local
grep btserial /etc/rc.local > /dev/null
if [ $? != 0 ]; then
# go to the last line and come up one line and insert commands and then save.
sudo ed /etc/rc.local <<EOF
$
.-1i
# Launch bluetooth service startup script /home/pi/btserial.sh
sudo /usr/local/bluetooth/btserial.sh &
.
w
q
EOF
echo "=- Added ${BT_DIR}/btserial.sh to /etc/rc.local -="
fi
fi
fi
#
# Set keyboard locale
#
echo "=- Set keyboard locale -="
sudo sed -i -e "s/^XKBLAYOUT=\"gb\"/XKBLAYOUT=\"${COUNTRY_L}\"/" /etc/default/keyboard
# sudo dpkg-reconfigure keyboard-configuration
# sudo service keyboard-setup restart
grep "XKBLAYOUT" /etc/default/keyboard
#
# Update various Raspian packages
#
echo "=- Update the Raspian O/S -="
sudo apt-get update
sudo apt-get dist-upgrade
#
date
echo "=- End of Configure Raspberry PI -="
# End of script