-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathchroot-script.sh
More file actions
227 lines (188 loc) · 6.53 KB
/
chroot-script.sh
File metadata and controls
227 lines (188 loc) · 6.53 KB
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
#!/bin/bash
set -ex
KEYSERVER="ha.pool.sks-keyservers.net"
function clean_print(){
local fingerprint="${2}"
local func="${1}"
nospaces=${fingerprint//[:space:]/}
tolowercase=${nospaces,,}
KEYID_long=${tolowercase:(-16)}
KEYID_short=${tolowercase:(-8)}
if [[ "${func}" == "fpr" ]]; then
echo "${tolowercase}"
elif [[ "${func}" == "long" ]]; then
echo "${KEYID_long}"
elif [[ "${func}" == "short" ]]; then
echo "${KEYID_short}"
elif [[ "${func}" == "print" ]]; then
if [[ "${fingerprint}" != "${nospaces}" ]]; then
printf "%-10s %50s\n" fpr: "${fingerprint}"
fi
# if [[ "${nospaces}" != "${tolowercase}" ]]; then
# printf "%-10s %50s\n" nospaces: $nospaces
# fi
if [[ "${tolowercase}" != "${KEYID_long}" ]]; then
printf "%-10s %50s\n" lower: "${tolowercase}"
fi
printf "%-10s %50s\n" long: "${KEYID_long}"
printf "%-10s %50s\n" short: "${KEYID_short}"
echo ""
else
echo "usage: function {print|fpr|long|short} GPGKEY"
fi
}
function get_gpg(){
GPG_KEY="${1}"
KEY_URL="${2}"
clean_print print "${GPG_KEY}"
GPG_KEY=$(clean_print fpr "${GPG_KEY}")
if [[ "${KEY_URL}" =~ ^https?://* ]]; then
echo "loading key from url"
KEY_FILE=temp.gpg.key
wget -q -O "${KEY_FILE}" "${KEY_URL}"
elif [[ -z "${KEY_URL}" ]]; then
echo "no source given try to load from key server"
# gpg --keyserver "${KEYSERVER}" --recv-keys "${GPG_KEY}"
apt-key adv --keyserver "${KEYSERVER}" --recv-keys "${GPG_KEY}"
return $?
else
echo "keyfile given"
KEY_FILE="${KEY_URL}"
fi
FINGERPRINT_OF_FILE=$(gpg --with-fingerprint --with-colons "${KEY_FILE}" | grep fpr | rev |cut -d: -f2 | rev)
if [[ ${#GPG_KEY} -eq 16 ]]; then
echo "compare long keyid"
CHECK=$(clean_print long "${FINGERPRINT_OF_FILE}")
elif [[ ${#GPG_KEY} -eq 8 ]]; then
echo "compare short keyid"
CHECK=$(clean_print short "${FINGERPRINT_OF_FILE}")
else
echo "compare fingerprint"
CHECK=$(clean_print fpr "${FINGERPRINT_OF_FILE}")
fi
if [[ "${GPG_KEY}" == "${CHECK}" ]]; then
echo "key OK add to apt"
apt-key add "${KEY_FILE}"
rm -f "${KEY_FILE}"
return 0
else
echo "key invalid"
exit 1
fi
}
## examples:
# clean_print {print|fpr|long|short} {GPGKEYID|FINGERPRINT}
# get_gpg {GPGKEYID|FINGERPRINT} [URL|FILE]
# device specific settings
HYPRIOT_DEVICE="Raspberry Pi"
# set up /etc/resolv.conf
DEST=$(readlink -m /etc/resolv.conf)
export DEST
mkdir -p "$(dirname "${DEST}")"
echo "nameserver 8.8.8.8" > "${DEST}"
# set up hypriot rpi repository for rpi specific kernel- and firmware-packages
PACKAGECLOUD_FPR=418A7F2FB0E1E6E7EABF6FE8C2E73424D59097AB
PACKAGECLOUD_KEY_URL=https://packagecloud.io/gpg.key
get_gpg "${PACKAGECLOUD_FPR}" "${PACKAGECLOUD_KEY_URL}"
echo 'deb https://packagecloud.io/Hypriot/rpi/debian/ stretch main' > /etc/apt/sources.list.d/hypriot.list
# set up Docker CE repository
DOCKERREPO_FPR=9DC858229FC7DD38854AE2D88D81803C0EBFCD88
DOCKERREPO_KEY_URL=https://download.docker.com/linux/raspbian/gpg
get_gpg "${DOCKERREPO_FPR}" "${DOCKERREPO_KEY_URL}"
CHANNEL=edge # stable, test or edge
echo "deb [arch=armhf] https://download.docker.com/linux/raspbian stretch $CHANNEL" > /etc/apt/sources.list.d/docker.list
RPI_ORG_FPR=CF8A1AF502A2AA2D763BAE7E82B129927FA3303E RPI_ORG_KEY_URL=http://archive.raspberrypi.org/debian/raspberrypi.gpg.key
get_gpg "${RPI_ORG_FPR}" "${RPI_ORG_KEY_URL}"
echo 'deb http://archive.raspberrypi.org/debian/ stretch main' | tee /etc/apt/sources.list.d/raspberrypi.list
# reload package sources
apt-get update
# apt-get upgrade -y
# install packages
apt-get -o Dpkg::Options::=--force-confdef \
install -y \
--no-install-recommends \
firmware-atheros \
firmware-brcm80211 \
firmware-libertas \
firmware-misc-nonfree \
firmware-realtek \
raspberrypi-bootloader \
libraspberrypi0 \
libraspberrypi-bin \
raspi-config \
wpasupplicant \
wireless-tools \
crda \
raspberrypi-net-mods \
dnsmasq \
hostapd \
fake-hwclock \
screen \
lighttpd \
php7.0-fpm \
php-cgi \
dialog\
pi-bluetooth \
lsb-release \
gettext \
cloud-init \
pt-ui-mods \
git
# install special Docker enabled kernel
if [ -z "${KERNEL_URL}" ]; then
apt-get install -y \
--no-install-recommends \
"raspberrypi-kernel=${KERNEL_BUILD}"
else
curl -L -o /tmp/kernel.deb "${KERNEL_URL}"
dpkg -i /tmp/kernel.deb
rm /tmp/kernel.deb
fi
# enable serial console
printf "# Spawn a getty on Raspberry Pi serial line\nT0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100\n" >> /etc/inittab
# boot/cmdline.txt
echo "dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 cgroup_enable=cpuset cgroup_enable=memory swapaccount=1 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh" > /boot/cmdline.txt
# create a default boot/config.txt file (details see http://elinux.org/RPiconfig)
echo "
hdmi_force_hotplug=1
enable_uart=0
" > boot/config.txt
echo "# camera settings, see http://elinux.org/RPiconfig#Camera
start_x=1
disable_camera_led=1
gpu_mem=128
" >> boot/config.txt
# /etc/modules
echo "snd_bcm2835
" >> /etc/modules
# create /etc/fstab
echo "
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 0
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
" > /etc/fstab
# Fix cloud-init package mirrors
sed -i '/disable_root: true/a apt_preserve_sources_list: true' /etc/cloud/cloud.cfg
# Link cloud-init config to VFAT /boot partition
mkdir -p /var/lib/cloud/seed/nocloud-net
ln -s /boot/user-data /var/lib/cloud/seed/nocloud-net/user-data
ln -s /boot/meta-data /var/lib/cloud/seed/nocloud-net/meta-data
# Fix duplicate IP address for eth0, remove file from os-rootfs
rm -f /etc/network/interfaces.d/eth0
lighttpd-enable-mod fastcgi-php
systemctl disable dhcpcd
systemctl disable hciuart
echo "Installing rpi-serial-console script"
wget -q https://raw.githubusercontent.com/lurch/rpi-serial-console/master/rpi-serial-console -O usr/local/bin/rpi-serial-console
chmod +x usr/local/bin/rpi-serial-console
# fix eth0 interface name
ln -s /dev/null /etc/systemd/network/99-default.link
# cleanup APT cache and lists
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# set device label and version number
echo "HYPRIOT_DEVICE=\"$HYPRIOT_DEVICE\"" >> /etc/os-release
echo "HYPRIOT_IMAGE_VERSION=\"$HYPRIOT_IMAGE_VERSION\"" >> /etc/os-release
cp /etc/os-release /boot/os-release
# Integrate camera development work (see https://publiclab.org/notes/MaggPi/08-09-2018/raspberry-pi-manual-camera-control )
git clone https://github.com/MargaretAN9/Peggy/ /home/publiclab/Peggy