2018-03-05 17:01:34 +00:00
|
|
|
kernel:
|
2021-03-03 17:42:41 +00:00
|
|
|
image: linuxkit/kernel:4.19.121
|
2019-03-14 05:46:09 +00:00
|
|
|
cmdline: "console=tty0 console=ttyS0 root=/dev/sda1 root=/dev/sr0 adlin.format=/dev/sda quiet"
|
2018-03-05 17:01:34 +00:00
|
|
|
|
|
|
|
init:
|
2021-03-03 17:42:41 +00:00
|
|
|
- nemunaire/adlin-tuto2:a68d5f224331628dc525edf383ec7429dfe001b0
|
2018-03-05 17:01:34 +00:00
|
|
|
|
|
|
|
files:
|
|
|
|
- path: etc/hostname
|
|
|
|
contents: |
|
|
|
|
adlin2
|
2020-03-29 14:12:50 +00:00
|
|
|
uid: 0
|
|
|
|
gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
mode: "0644"
|
|
|
|
|
|
|
|
- path: etc/resolv.conf
|
|
|
|
contents: |
|
2021-03-05 14:03:10 +00:00
|
|
|
nameserver 9.9.9.10
|
2019-03-14 05:46:09 +00:00
|
|
|
nameserver 1.1.1.1
|
2020-03-29 14:12:50 +00:00
|
|
|
uid: 0
|
|
|
|
gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
mode: "0644"
|
|
|
|
|
|
|
|
- path: etc/systemd/network/49-main.link
|
|
|
|
contents: |
|
|
|
|
[Match]
|
|
|
|
OriginalName=eth0
|
|
|
|
[Link]
|
|
|
|
Name=eth0
|
2020-03-29 14:12:50 +00:00
|
|
|
uid: 0
|
|
|
|
gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
mode: "0644"
|
|
|
|
|
|
|
|
- path: etc/systemd/network/50-dhcp.network
|
|
|
|
contents: |
|
|
|
|
[Match]
|
|
|
|
Name=eth0
|
|
|
|
[Network]
|
|
|
|
DHCP=yes
|
2019-03-14 05:46:09 +00:00
|
|
|
IPv6AcceptRA=no
|
|
|
|
LinkLocalAddressing=no
|
2020-03-29 14:12:50 +00:00
|
|
|
uid: 0
|
|
|
|
gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
mode: "0644"
|
|
|
|
|
|
|
|
- path: init
|
|
|
|
contents: |
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# /proc/cmdline parser (from Gentoo Wiki)
|
|
|
|
cmdline() {
|
|
|
|
local value
|
|
|
|
value=" $(cat /proc/cmdline) "
|
|
|
|
value="${value#* $1=}"
|
|
|
|
value="${value%% *}"
|
|
|
|
[ "$value" != "" ] && echo "$value"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount -n -t devtmpfs devtmpfs /dev
|
|
|
|
mount -n -t proc proc /proc
|
|
|
|
#mount -n -t tmpfs run /run
|
|
|
|
#mount -m -t sysfs sys /sys
|
|
|
|
|
2020-03-27 12:13:10 +00:00
|
|
|
INITDEBUG=$(cmdline adlin.debuginit)
|
|
|
|
[ -n "${INITDEBUG}" ] && /bin/busybox cttyhack ${INITDEBUG}
|
|
|
|
|
2018-03-05 17:01:34 +00:00
|
|
|
INITP=$(cmdline init)
|
|
|
|
[ -z "$INITP" ] && INITP=/lib/systemd/systemd
|
2019-03-14 05:46:09 +00:00
|
|
|
WGTOKEN=$(cmdline adlin.token)
|
2018-03-05 17:01:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
ROOTFS=$(cmdline root)
|
|
|
|
[ -z "$ROOTFS" ] && { echo "No root= provided, continuing on initramfs only."; exec "${INITP}"; }
|
|
|
|
[ "$ROOTFS" = "/dev/sr0" ] && { echo "No root= provided, continuing on initramfs only."; exec "${INITP}"; }
|
2019-03-15 18:09:15 +00:00
|
|
|
[ -b "$ROOTFS" -a -z "$(cmdline adlin.alwaysformat)" ] || {
|
2018-03-05 17:01:34 +00:00
|
|
|
FORMATDD=$(cmdline adlin.format)
|
2019-03-15 18:09:15 +00:00
|
|
|
[ -b "$FORMATDD" ] && { echo "o\nn\np\n1\n\n\np\nw\nq\n" | fdisk "${FORMATDD}" && mkfs.ext4 -q "$FORMATDD"1; }
|
2018-03-05 17:01:34 +00:00
|
|
|
[ -b "$ROOTFS" ] || { echo "Invalid provided rootfs: not a valid block device."; exit 1; }
|
|
|
|
}
|
|
|
|
|
2019-03-14 05:46:09 +00:00
|
|
|
|
2018-03-05 17:01:34 +00:00
|
|
|
mkdir -p /overlay
|
|
|
|
/bin/mount -n -t tmpfs none /overlay
|
|
|
|
/bin/mkdir -p /overlay/rwdata
|
|
|
|
/bin/mkdir -p /overlay/robase
|
|
|
|
/bin/mkdir -p /overlay/combined
|
|
|
|
/bin/mount --bind / /overlay/robase
|
|
|
|
|
|
|
|
ovr_rwdata=/overlay/rwdata
|
|
|
|
ovr_robase=/overlay/robase
|
|
|
|
ovr_combined=/overlay/combined
|
|
|
|
|
|
|
|
# Prepare filesystem for local data storage...
|
|
|
|
/bin/mkdir -p ${ovr_rwdata}
|
|
|
|
/bin/mount -n "${ROOTFS}" ${ovr_rwdata} || { echo "Unable to mount rootfs."; exit 2; }
|
|
|
|
|
|
|
|
mkdir -p ${ovr_rwdata}/data
|
|
|
|
mkdir -p ${ovr_rwdata}/work
|
|
|
|
/bin/mount -n -t overlay -o upperdir=${ovr_rwdata}/data,workdir=${ovr_rwdata}/work,lowerdir=${ovr_robase} overlay ${ovr_combined} || { echo "Unable to create overlayfs."; exit 3; }
|
|
|
|
|
|
|
|
/bin/mkdir -p ${ovr_combined}/overlay/rwdata
|
|
|
|
/bin/mount -n --move ${ovr_rwdata} ${ovr_combined}/overlay/rwdata
|
|
|
|
/bin/mkdir -p ${ovr_combined}/overlay/robase
|
|
|
|
/bin/mount -n --move ${ovr_robase} ${ovr_combined}/overlay/robase
|
|
|
|
/bin/mkdir -p ${ovr_combined}/overlay/pivot
|
|
|
|
|
|
|
|
cd ${ovr_combined}
|
|
|
|
|
2019-03-14 05:46:09 +00:00
|
|
|
mount --move /dev dev
|
2020-03-27 12:13:10 +00:00
|
|
|
mount --move /proc proc
|
2018-03-05 17:01:34 +00:00
|
|
|
mount --move . /
|
|
|
|
/bin/umount -n /overlay
|
2019-03-14 05:46:09 +00:00
|
|
|
|
2019-03-31 14:07:19 +00:00
|
|
|
[ -f "etc/adlin.init" ] && source etc/adlin.init
|
2019-03-15 17:28:38 +00:00
|
|
|
|
2019-03-14 05:46:09 +00:00
|
|
|
# Setting up wireguard tunnel
|
|
|
|
[ -z "${WGTOKEN}" ] && [ -f "etc/adlin.token" ] && WGTOKEN=$(cat etc/adlin.token)
|
|
|
|
[ -z "${WGTOKEN}" ] && {
|
2019-03-31 14:07:19 +00:00
|
|
|
echo
|
2019-03-14 05:46:09 +00:00
|
|
|
echo -n "You didn't define your token to connect the network. Please copy it here now: "
|
|
|
|
read WGTOKEN
|
|
|
|
}
|
2019-03-31 14:07:19 +00:00
|
|
|
/bin/ip link set up dev eth0 || { /sbin/modprobe e1000; /bin/ip link set up dev eth0; }
|
2020-03-27 12:13:10 +00:00
|
|
|
/sbin/sysctl -w net.ipv6.conf.eth0.autoconf=0
|
2019-03-14 05:46:09 +00:00
|
|
|
/bin/busybox udhcpc -n -q
|
|
|
|
[ -f "etc/wireguard/adlin.conf" ] && WGPRVKEY=$(sed 's/^.*PrivateKey *= *//p;d' etc/wireguard/adlin.conf)
|
|
|
|
[ -z "${WGPRVKEY}" ] && WGPRVKEY=$(/usr/bin/wg genkey)
|
|
|
|
WGPUBKEY=$(echo $WGPRVKEY | /usr/bin/wg pubkey)
|
|
|
|
while ! { echo "[Interface]\nPrivateKey = ${WGPRVKEY}"; /usr/sbin/chroot . /usr/bin/curl -f -d '{"pubkey": "'$WGPUBKEY'"}' https://adlin.nemunai.re/api/wg/$(echo -n "$WGTOKEN" | /usr/bin/sha512sum | /usr/bin/cut -d ' ' -f 1); } > etc/wireguard/adlin.conf
|
|
|
|
do
|
|
|
|
echo ""
|
|
|
|
echo "****************************************"
|
|
|
|
echo "******* SWITCHING TO RESCUE MODE *******"
|
|
|
|
echo "****************************************"
|
|
|
|
echo ""
|
|
|
|
echo "Sorry, I was unable to establish a connection to adlin.nemunai.re."
|
|
|
|
echo "Please verify that your primary network interface can obtain an IPv4 through DHCP."
|
|
|
|
echo ""
|
2019-03-15 17:26:12 +00:00
|
|
|
echo "If curl report a 400 error, then you probably mistyped the token, you should reboot now."
|
|
|
|
echo ""
|
2019-03-14 05:46:09 +00:00
|
|
|
echo "Dropping to a shell, please fix your network, then press Ctrl+D or exit to retry."
|
|
|
|
echo ""
|
|
|
|
echo "****************************************"
|
|
|
|
echo ""
|
|
|
|
/bin/busybox cttyhack /usr/sbin/chroot . /bin/sh
|
|
|
|
echo "Retrying connection..."
|
|
|
|
done
|
2019-03-15 17:26:12 +00:00
|
|
|
echo -n "${WGTOKEN}" > etc/adlin.token
|
2019-03-14 05:46:09 +00:00
|
|
|
/sbin/modprobe wireguard
|
|
|
|
/bin/ip link add dev wg0 type wireguard
|
|
|
|
/usr/bin/wg setconf wg0 etc/wireguard/adlin.conf
|
|
|
|
/bin/ip address add dev wg0 $(sed 's/^.*MyIPv6=//p;d' etc/wireguard/adlin.conf)
|
|
|
|
/bin/ip link set up dev wg0
|
|
|
|
/bin/ip -6 route del default
|
|
|
|
/bin/ip -6 route add default via $(sed 's/^.*GWIPv6=//p;d' etc/wireguard/adlin.conf) pref high
|
|
|
|
|
2021-03-05 14:03:10 +00:00
|
|
|
# Download intermediate fixes
|
|
|
|
curl -s -f -H "X-ADLIN-time: $(stat -c %Y /boot)" https://adlin.nemunai.re/fix-vm2 | sh
|
|
|
|
|
|
|
|
# Retrieve ssh keys
|
|
|
|
mkdir -p root/.ssh/
|
|
|
|
[ -f root/.ssh/authorized_keys ] || /usr/sbin/chroot . /usr/bin/curl -s -f https://cri.epita.fr/$(sed 's/^.*MyLogin=//p;d' etc/wireguard/adlin.conf).keys > root/.ssh/authorized_keys
|
|
|
|
[ -f etc/ssh/ssh_host_rsa_key ] || /usr/sbin/chroot . ssh-keygen -A
|
|
|
|
|
2019-03-14 05:46:09 +00:00
|
|
|
# To the user
|
2018-03-05 17:01:34 +00:00
|
|
|
exec /usr/sbin/chroot . "${INITP}"
|
2020-03-29 14:12:50 +00:00
|
|
|
uid: 0
|
|
|
|
gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
mode: "0755"
|
|
|
|
|
|
|
|
# - path: etc/systemd/system/systemd-networkd.service.d/10-debug.conf
|
|
|
|
# contents: |
|
|
|
|
# [Service]
|
|
|
|
# Environment=SYSTEMD_LOG_LEVEL=debug
|
2020-03-29 14:12:50 +00:00
|
|
|
# uid: 0
|
|
|
|
# gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
# mode: "0644"
|
|
|
|
|
|
|
|
- path: etc/shadow
|
|
|
|
contents: |
|
2021-03-03 17:42:41 +00:00
|
|
|
root:$6$dQXVLB.662ob0XJL$wRhh73Q.Z3mBRHhM0rSw96dE0bOFykfIXa2Z2ncu6WVSOpFLdv5J6Br9AHhalO4wwG3xgPqqhvCdEMdroR2r50:18336:0:99999:7:::
|
2020-03-27 12:13:10 +00:00
|
|
|
daemon:*:18316:0:99999:7:::
|
|
|
|
bin:*:18316:0:99999:7:::
|
|
|
|
sys:*:18316:0:99999:7:::
|
|
|
|
sync:*:18316:0:99999:7:::
|
|
|
|
games:*:18316:0:99999:7:::
|
|
|
|
man:*:18316:0:99999:7:::
|
|
|
|
lp:*:18316:0:99999:7:::
|
|
|
|
mail:*:18316:0:99999:7:::
|
|
|
|
news:*:18316:0:99999:7:::
|
|
|
|
uucp:*:18316:0:99999:7:::
|
|
|
|
proxy:*:18316:0:99999:7:::
|
|
|
|
www-data:*:18316:0:99999:7:::
|
|
|
|
backup:*:18316:0:99999:7:::
|
|
|
|
list:*:18316:0:99999:7:::
|
|
|
|
irc:*:18316:0:99999:7:::
|
|
|
|
gnats:*:18316:0:99999:7:::
|
|
|
|
nobody:*:18316:0:99999:7:::
|
|
|
|
_apt:*:18316:0:99999:7:::
|
|
|
|
systemd-timesync:*:18333:0:99999:7:::
|
|
|
|
systemd-network:*:18333:0:99999:7:::
|
|
|
|
systemd-resolve:*:18333:0:99999:7:::
|
|
|
|
sshd:*:18333:0:99999:7:::
|
2020-03-29 14:12:50 +00:00
|
|
|
uid: 0
|
|
|
|
gid: 0
|
2018-03-05 17:01:34 +00:00
|
|
|
mode: "0640"
|
|
|
|
|
|
|
|
trust:
|
|
|
|
org:
|
|
|
|
- linuxkit
|
|
|
|
- library
|