Created
January 25, 2023 22:38
-
-
Save Kreyren/20398aa7213bfc8de74d5dda242c491c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# apk add blkid parted dosfstools e2fsprogs wget tar | |
set -eu | |
: "${DISK:=/dev/sdb}" | |
#if [ $DISK = "/dev/sdX" ]; then | |
# echo "DISK is not set correctly" | |
# exit | |
#fi | |
readonly SCRIPT="${0##*/}" | |
#readonly TMPDIR="$(mktemp -dt "${SCRIPT%.*}".XXXXXX)" | |
readonly TMPDIR="/mmc" | |
readonly BOOTDEV="$DISK"1 | |
readonly ROOTDEV="$DISK"2 | |
readonly APK_KEY="[email protected]" | |
readonly MIRROR="http://dl-cdn.alpinelinux.org/alpine" | |
cleanup() { | |
set +e | |
mountpoint -q "$TMPDIR"/boot && umount "$TMPDIR"/boot | |
mountpoint -q "$TMPDIR" && umount "$TMPDIR" | |
#rm -rf "$TMPDIR" | |
} | |
trap cleanup EXIT INT | |
kernel='linux-sunxi-5.17.5-r0.apk' | |
if [ ! -f $kernel ]; then | |
wget https://dev.alpinelinux.org/~mps/sunxi/"$kernel" | |
fi | |
echo "Paritioning disk" | |
# fat32 512, ext4 8GB | |
parted -s "$DISK" mktable msdos > /dev/null | |
parted -s "$DISK" unit s -- mkpart primary ext4 8192 1056767 > /dev/null | |
parted -s "$DISK" unit s -- mkpart primary ext4 1056768 17833983 > /dev/null | |
echo "Creating dirs and mounting" | |
mkfs.ext4 -qL boot "$BOOTDEV" | |
mkfs.ext4 -qL root "$ROOTDEV" | |
#mkfs.f2fs -f -l root "$ROOTDEV" | |
#mount -t f2fs "$ROOTDEV" "$TMPDIR" | |
mount -t ext4 "$ROOTDEV" "$TMPDIR" | |
mkdir -p "$TMPDIR"/boot | |
mkdir -p "$TMPDIR"/etc/apk/keys | |
mount -t ext4 "$BOOTDEV" "$TMPDIR"/boot | |
echo "Setup apk keys and repositories" | |
MPS_KEY="[email protected]" | |
wget -qP "$TMPDIR"/etc/apk/keys https://alpinelinux.org/keys/"$APK_KEY" | |
wget -qP "$TMPDIR"/etc/apk/keys https://www.arvanta.net/mps/aports-local/"$MPS_KEY" | |
printf "$MIRROR/edge/%s\n" main community testing > "$TMPDIR"/etc/apk/repositories | |
printf "https://www.arvanta.net/mps/aports-local\n" >> "$TMPDIR"/etc/apk/repositories | |
echo "installing base packages" | |
apk --allow-untrusted --root "$TMPDIR" --arch aarch64 --initdb add \ | |
alpine-base alpine-baselayout alpine-conf kmod openrc \ | |
dbus util-linux blkid chrony u-boot-sunxi \ | |
sysfsutils ssl_client ca-certificates-bundle alpine-keys \ | |
ethtool e2fsprogs libudev-zero libudev-zero-helper \ | |
iwd agetty openresolv tar wget linux-sunxi \ | |
linux-firmware-rtlwifi iw wpa_supplicant | |
dd if="$TMPDIR"/usr/share/u-boot/a64-olinuxino-emmc/u-boot-sunxi-with-spl.bin of=$DISK bs=8k seek=1 | |
echo "Setting up services and inittab" | |
for rc in boot/bootmisc boot/hostname boot/modules boot/sysctl boot/urandom boot/networking \ | |
boot/syslog boot/klogd \ | |
sysinit/devfs sysinit/hwdrivers sysinit/mdev sysinit/modules \ | |
shutdown/mount-ro shutdown/killprocs \ | |
default/dbus default/chronyd default/iwd; do | |
ln -s /etc/init.d/"${rc##*/}" "$TMPDIR"/etc/runlevels/"$rc" | |
done | |
mkdir -p "$TMPDIR"/boot/extlinux | |
partuuid=`fdisk -l $DISK | grep 'Disk identifier:'| cut -d ' ' -f 3 | cut -d 'x' -f 2` | |
ROOTPART="$partuuid-02" | |
BOOTPART="$partuuid-01" | |
console='console=${console}' | |
echo "Creating extlinux.conf" | |
cat > "$TMPDIR"/boot/extlinux/extlinux.conf<<EOF | |
TIMEOUT 50 | |
PROMPT 1 | |
DEFAULT sunxi | |
MENU TITLE Alpine on Olinuxino MMC | |
LABEL sunxi | |
MENU LABEL sunxi | |
KERNEL /vmlinuz-sunxi | |
FDTDIR /dtbs-sunxi | |
APPEND modules=sd-mod,usb-storage,ext4,f2fs,sunxi-mmc root=PARTUUID=$ROOTPART rw rootwait $console | |
EOF | |
sed -i 's/^#ttyS0/ttyS0/' $TMPDIR/etc/inittab | |
sed -i 's/^ttyS0.*/ttyS0::respawn:\/sbin\/agetty -L 115200 ttyS0 linux --login-pause --autologin root --noclear/' $TMPDIR/etc/inittab | |
echo "Finished, cleaning up" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment