# as ROOT, prepare for building alpine packages
apk add sudo terminus-font
setfont /usr/share/consolefonts/ter-112n.psf.gz -C /dev/tty1
grep abuild /etc/group
echo '%abuild ALL=(ALL) ALL' > /etc/sudoers.d/abuild
echo 'PACKAGER="ed r4 <ed-r4@ocv.me>"' >> /etc/abuild.conf 
echo 'MAINTAINER="$PACKAGER"' >> /etc/abuild.conf 
sed -ri "s/(export JOBS=)[0-9]+/\1$(nproc)/" /etc/abuild.conf 
cat /sys/class/power_supply/BAT1/capacity

# as user, clone aports and build your kernel --
# you /could/ use the regular linux-edge but you probably want to make some adjustments
git clone https://gitlab.alpinelinux.org/alpine/aports
abuild-keygen -nai
cd aports/testing/linux-edge/
abuild -crK
# interrupt when build starts
(cd src/build-edge.x86_64/ && make nconfig)
cp -pv src/build-edge.x86_64/.config config-edge.x86_64
sed -ri "s/^[0-9a-f]{128}  config-edge.x86_64/$(sha512sum config-edge.x86_64)/" APKBUILD && rm -rf src pkg && abuild -crK

# as ROOT, install kernel and fix uefi bootloader config
apk add /home/ed/packages/testing/x86_64/linux-edge-*
sed -r 's@(LINUX|INITRD) (vmlinuz|initramfs)@\1 /\2@' </boot/extlinux.conf >/boot/EFI/boot/syslinux.cfg
poweroff

# as ROOT, connect to wifi
# if necessary, manually set ssid and psk in /etc/wpa_supplicant/wpa_supplicant.conf
# since 5.7 introduces the new wifi interface (TODO how do you iwlist now)
ip link set wlan0 up
wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf &
udhcpc -i wlan0 & 

# as user, build the libdrm and amdgpu packages
cd ~/aports/main/libdrm/ && abuild -crK
sudo apk add ~ed/packages/main/x86_64/libdrm-2.4.102-r0.apk
cd ~/aports/main/xf86-video-amdgpu/ && abuild -crK
sudo apk add /home/ed/packages/main/x86_64/xf86-video-amdgpu-19.1.0-r0.apk

# continue installing xfce like usual
