forked from DieterReuter/make-rootfs-debian-arm64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·118 lines (93 loc) · 3.3 KB
/
build.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
#!/bin/bash -e
set -x
# This script only works on Linux
if [ "$(uname -s)" != "Linux" ]; then
echo "ERROR: scripts works on Linux only, not on $(uname -s)!"
exit 1
fi
# Redefine sudo command, when not available
if [ "$(whoami)" == "root" ]; then
SUDO_CMD=""
else
SUDO_CMD="sudo"
fi
# Build Debian rootfs for ARCH={armhf,arm64}
# - Debian armhf = ARMv6/ARMv7
# - Debian arm64 = ARMv8/Aarch64
BUILD_ARCH="${BUILD_ARCH:-armhf}"
ROOTFS_DIR="debian-${BUILD_ARCH}"
# Cleanup
rm -fr "${ROOTFS_DIR}"
# Debootstrap a minimal Debian Jessie rootfs
# --keyring /usr/share/keyrings/debian-ports-archive-keyring.gpg \
# --no-check-gpg \
# --variant=buildd \
qemu-debootstrap \
--arch="${BUILD_ARCH}" \
--include="apt-transport-https,avahi-daemon,ca-certificates,curl,htop,locales,net-tools,openssh-server,usbutils" \
--exclude="debfoster" \
jessie \
"${ROOTFS_DIR}" \
http://ftp.debian.org/debian
### Configure Debian ###
# Use standard Debian apt repositories
cat << EOM | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee /etc/apt/sources.list
deb http://httpredir.debian.org/debian bookworm main
deb-src http://httpredir.debian.org/debian bookworm main
deb http://httpredir.debian.org/debian bookworm-updates main
deb-src http://httpredir.debian.org/debian bookworm-updates main
deb http://security.debian.org/ bookworm/updates main
deb-src http://security.debian.org/ bookworm/updates main
EOM
### Configure network and systemd services ###
# Set ethernet interface eth0 to dhcp
cat << EOM | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee /etc/systemd/network/eth0.network
[Match]
Name=eth0
[Network]
DHCP=yes
EOM
# Enable networkd
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
systemctl enable systemd-networkd
# Configure and enable resolved
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
systemctl enable systemd-resolved
# Enable SSH root login
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
sed -i 's|PermitRootLogin without-password|PermitRootLogin yes|g' /etc/ssh/sshd_config
# Enable NTP with timesyncd
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
sed -i 's|#Servers=|Servers=|g' /etc/systemd/timesyncd.conf
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
systemctl enable systemd-timesyncd
# Set default locales to 'en_US.UTF-8'
echo 'en_US.UTF-8 UTF-8' | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee -a /etc/locale.gen
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
locale-gen
echo 'locales locales/default_environment_locale select en_US.UTF-8' | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
debconf-set-selections
${SUDO_CMD} chroot "${ROOTFS_DIR}" \
dpkg-reconfigure -f noninteractive locales
### HypriotOS specific settings ###
# set hostname to 'black-pearl'
echo 'black-pearl' | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee /etc/hostname
# set root password to 'hypriot'
echo 'root:hypriot' | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
/usr/sbin/chpasswd
# set HypriotOS bash prompt for root user
cat /vagrant/files/bash_prompt/bashrc | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee /root/.bashrc
cat /vagrant/files/bash_prompt/bash_prompt | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee /root/.bash_prompt
cat /vagrant/files/bash_prompt/profile | ${SUDO_CMD} chroot "${ROOTFS_DIR}" \
tee /root/.profile
# Package rootfs tarball
umask 0000
tar -czf "rootfs-${BUILD_ARCH}.tar.gz" -C "${ROOTFS_DIR}/" .