#!/bin/sh # apk add blkid parted dosfstools e2fsprogs wget tar set -eu : "${DISK:=/dev/sdc}" readonly SCRIPT="${0##*/}" readonly TMPDIR="$(mktemp -dt "${SCRIPT%.*}".XXXXXX)" readonly BOOTDEV="$DISK"1 readonly ROOTDEV="$DISK"2 readonly APK_KEY="alpine-devel@lists.alpinelinux.org-60ac2099.rsa.pub" readonly MIRROR="http://dl-cdn.alpinelinux.org/alpine" model='j293' kernver='5.16.0-r15' kernel="linux-asahi-$kernver.apk" cleanup() { set +e mountpoint -q "$TMPDIR"/boot/efi && umount "$TMPDIR"/boot/efi mountpoint -q "$TMPDIR" && umount "$TMPDIR" rm -rf "$TMPDIR" } trap cleanup EXIT INT if [ ! -f u-boot.macho ]; then #wget https://dev.alpinelinux.org/~mps/m1/m1n1.macho wget https://dev.alpinelinux.org/~mps/m1/u-boot.macho fi if [ ! -f $kernel ]; then wget https://dev.alpinelinux.org/~mps/m1/"$kernel" fi echo "Paritioning disk" parted -s "$DISK" mktable gpt > /dev/null parted -s "$DISK" unit s -- mkpart primary fat32 2048 1050623 > /dev/null parted -s "$DISK" -- set 1 esp on > /dev/null parted -s "$DISK" unit s -- mkpart primary ext4 1050624 7888862 > /dev/null echo "Creating dirs and mounting" mkfs.fat -F 32 -n ESP "$BOOTDEV" mkfs.ext4 -qL root "$ROOTDEV" mount -t ext4 "$ROOTDEV" "$TMPDIR" mkdir -p "$TMPDIR"/boot mkdir -p "$TMPDIR"/boot/efi "$TMPDIR"/etc/apk/keys mount -t vfat "$BOOTDEV" "$TMPDIR"/boot/efi echo "Setup apk keys and repositories" wget -qP "$TMPDIR"/etc/apk/keys https://alpinelinux.org/keys/"$APK_KEY" printf "$MIRROR/edge/%s\n" main community > "$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 \ sysfsutils ssl_client ca-certificates-bundle alpine-keys \ ethtool e2fsprogs libudev-zero libudev-zero-helper \ iwd linux-firmware wpa_supplicant efibootmgr ttf-dejavu \ nvme-cli agetty terminus-font openresolv tar xf linux-5.16.0-asahi-25.tar.gz -C $TMPDIR #apk --allow-untrusted --root "$TMPDIR" --arch aarch64 --no-script add $kernel apk --allow-untrusted --root "$TMPDIR" --arch aarch64 --no-script add grub-efi grub-mkfont echo "Setting up services and inittab" for rc in boot/bootmisc boot/hostname boot/modules boot/sysctl boot/urandom boot/networking \ sysinit/devfs sysinit/hwdrivers sysinit/mdev sysinit/modules \ shutdown/mount-ro shutdown/killprocs \ default/dbus default/iwd default/chronyd; do ln -s /etc/init.d/"${rc##*/}" "$TMPDIR"/etc/runlevels/"$rc" done cat > "$TMPDIR"/root/grub-setup.sh< /boot/grub/grub.cfg sed -i 's/^tty1.*/tty1::respawn:\/sbin\/agetty -L 115200 tty1 linux --login-pause --autologin root --noclear/' /etc/inittab exit EOF echo 'GRUB_DISABLE_LINUX_PARTUUID=false' >> "$TMPDIR"/etc/default/grub echo 'GRUB_CMDLINE_LINUX="rootwait console=tty1"' >> "$TMPDIR"/etc/default/grub echo 'GRUB_TIMEOUT=10' >> "$TMPDIR"/etc/default/grub echo 'GRUB_FONT="/boot/grub/fonts/dejavu.pf2"' >> "$TMPDIR"/etc/default/grub chmod 0744 "$TMPDIR"/root/grub-setup.sh echo "Settting grub boot loader" mount -t proc none $TMPDIR/proc mount -o bind /sys $TMPDIR/sys mount -o bind /dev $TMPDIR/dev echo "Run this two commands and after that exit" echo "grub-install --target=arm64-efi --efi-directory=/boot/efi --removable" echo "grub-mkconfig > /boot/grub/grub.cfg" chroot $TMPDIR /root/grub-setup.sh #chroot $TMPDIR /bin/ash -l umount $TMPDIR/dev umount $TMPDIR/sys umount $TMPDIR/proc echo "Finished, cleaning up"