This commit is contained in:
oliver
2026-05-27 16:28:42 -03:00
parent eb4d83e9e9
commit ce01dd64f7
9 changed files with 609 additions and 0 deletions
+135
View File
@@ -0,0 +1,135 @@
#!/bin/sh
set -eu
# ---------------------------------------------------------------------------
# chroot-setup.sh — Runs inside the Alpine chroot to configure the system
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# 1. APK repositories
# ---------------------------------------------------------------------------
echo "==> Configuring APK repositories"
cat > /etc/apk/repositories <<'EOF'
https://dl-cdn.alpinelinux.org/alpine/latest-stable/main
https://dl-cdn.alpinelinux.org/alpine/latest-stable/community
EOF
apk update
# ---------------------------------------------------------------------------
# 2. Install packages
# ---------------------------------------------------------------------------
echo "==> Installing packages"
apk add --no-cache \
linux-lts \
mkinitfs \
openrc \
busybox \
musl \
libc-utils \
util-linux \
e2fsprogs \
dosfstools \
btrfs-progs \
parted \
sfdisk \
openssh \
dhcpcd \
iproute2 \
iputils \
net-tools \
curl \
wget \
ca-certificates \
vim \
mc \
bind-tools \
nmap \
rsync \
alpine-conf
# ---------------------------------------------------------------------------
# 3. Generate initramfs
# ---------------------------------------------------------------------------
echo "==> Generating initramfs with mkinitfs"
mkinitfs $(ls /lib/modules/ | tail -1)
# ---------------------------------------------------------------------------
# 4. Network configuration
# ---------------------------------------------------------------------------
echo "==> Configuring network interfaces"
mkdir -p /etc/network
cat > /etc/network/interfaces <<'EOF'
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF
# ---------------------------------------------------------------------------
# 5. SSH configuration
# ---------------------------------------------------------------------------
echo "==> Configuring sshd"
sed -i \
-e 's/^#*\s*PermitRootLogin.*/PermitRootLogin yes/' \
-e 's/^#*\s*PasswordAuthentication.*/PasswordAuthentication yes/' \
/etc/ssh/sshd_config
# Ensure the directives exist if sed found nothing to replace
grep -q '^PermitRootLogin' /etc/ssh/sshd_config || echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
grep -q '^PasswordAuthentication' /etc/ssh/sshd_config || echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
echo "==> Generating SSH host keys"
ssh-keygen -A
# ---------------------------------------------------------------------------
# 6. Root password
# ---------------------------------------------------------------------------
echo "==> Setting root password"
echo "root:alpine" | chpasswd
# ---------------------------------------------------------------------------
# 7. Nebula OpenRC service
# ---------------------------------------------------------------------------
echo "==> Creating /etc/init.d/nebula"
cat > /etc/init.d/nebula <<'EOF'
#!/sbin/openrc-run
description="Nebula overlay network"
command="/usr/local/bin/nebula"
command_args="-config /etc/nebula/config.yml"
command_background=true
pidfile="/run/nebula.pid"
depend() {
need net
after networking
}
start_pre() {
checkpath -f -m 0600 -o root:root /run/nebula.pid
}
EOF
chmod +x /etc/init.d/nebula
# ---------------------------------------------------------------------------
# 8. OpenRC service enablement
# ---------------------------------------------------------------------------
echo "==> Enabling services"
rc-update add sshd default
rc-update add networking default
rc-update add nebula default
# Also ensure basic boot services are present
rc-update add devfs sysinit || true
rc-update add dmesg sysinit || true
rc-update add mdev sysinit || true
rc-update add hwdrivers sysinit || true
# ---------------------------------------------------------------------------
# 9. Hostname
# ---------------------------------------------------------------------------
echo "==> Setting hostname to 'rescue'"
echo "rescue" > /etc/hostname
echo "==> chroot-setup.sh complete"