-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·87 lines (60 loc) · 1.82 KB
/
setup.sh
File metadata and controls
executable file
·87 lines (60 loc) · 1.82 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
#!/bin/sh
set -exu
ROOT="$1"
echo "rpi3" > "${ROOT}/etc/hostname"
#chroot "$ROOT" usermod -p '*' root
chroot "$ROOT" passwd -d root
cat << END >> "${ROOT}/etc/ssh/sshd_config"
PermitEmptyPasswords yes
PermitRootLogin yes
END
cat << END > "${ROOT}/etc/network/interfaces.d/eth0"
auto eth0
iface eth0 inet dhcp
END
cat << 'END' > "${ROOT}/usr/sbin/rpi3-resizerootfs"
#!/bin/sh
roottmp=$(lsblk -l -o NAME,MOUNTPOINT | grep '/$')
rootpart=/dev/${roottmp%% */}
rootdev=${rootpart%2}
rootdev=${rootdev%p}
flock $rootdev sfdisk -f $rootdev -N 2 <<EOF
,+
EOF
sleep 5
udevadm settle
sleep 5
flock $rootdev partprobe $rootdev
mount -o remount,rw $rootpart
resize2fs $rootpart
exit 0
END
chmod +x "${ROOT}/usr/sbin/rpi3-resizerootfs"
cat << END > "${ROOT}/etc/systemd/system/rpi3-resizerootfs.service"
[Unit]
Description=resize root file system
Before=local-fs-pre.target
DefaultDependencies=no
[Service]
Type=oneshot
TimeoutSec=infinity
ExecStart=/usr/sbin/rpi3-resizerootfs
ExecStart=/bin/systemctl --no-reload disable %n
[Install]
RequiredBy=local-fs-pre.target
END
mkdir -p "${ROOT}/etc/systemd/system/systemd-remount-fs.service.requires/"
ln -s /etc/systemd/system/rpi3-resizerootfs.service "${ROOT}/etc/systemd/system/systemd-remount-fs.service.requires/rpi3-resizerootfs.service"
cat << END > "${ROOT}/etc/systemd/system/rpi3-generate-ssh-host-keys.service"
[Unit]
Description=generate SSH host keys
ConditionPathExistsGlob=!/etc/ssh/ssh_host_*_key
[Service]
Type=oneshot
ExecStart=/usr/sbin/dpkg-reconfigure -fnoninteractive openssh-server
[Install]
RequiredBy=multi-user.target
END
mkdir -p "${ROOT}/etc/systemd/system/multi-user.target.requires/"
ln -s /etc/systemd/system/rpi3-generate-ssh-host-keys.service "${ROOT}/etc/systemd/system/multi-user.target.requires/rpi3-generate-ssh-host-keys.service"
rm -f ${ROOT}/etc/ssh/ssh_host_*_key*