# Generated by pykickstart v3.48
#version=DEVEL
# Use text mode install
text
# Firewall configuration
firewall --enabled --service=ssh
# Keyboard layouts
keyboard 'us'
# System language
lang en_US.UTF-8
# Network information
network  --bootproto=dhcp --device=link --hostname=fedora-riscv
# Shutdown after installation
shutdown
repo --name="koji-f40-appliance-69131" --baseurl=http://openkoji.iscas.ac.cn/kojifiles/repos/f40-appliance/69131/riscv64
# Root password
rootpw --plaintext riscv
# SELinux configuration
selinux --enforcing
# System services
services --enabled="dbus-broker,sshd,NetworkManager,chronyd,haveged,kojid,rc-local"
# System timezone
timezone America/New_York --utc
# System bootloader configuration
bootloader --location=none --timeout=1 --extlinux
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel --disklabel=gpt
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=512
part / --fstype="ext4" --size=3072

%post
# Find the architecture we are on
arch=$(uname -m)

#releasever=$(rpm --eval '%{fedora}')
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-primary
echo "Packages within this disk image"
rpm -qa --qf '%{size}\t%{name}-%{version}-%{release}.%{arch}\n' |sort -rn


# remove random seed, the newly installed instance should make it's own
rm -f /var/lib/systemd/random-seed

# The enp1s0 interface is a left over from the imagefactory install, clean this up
rm -f /etc/NetworkManager/system-connections/*.nmconnection

dnf -y remove dracut-config-generic

# Remove machine-id on pre generated images
rm -f /etc/machine-id
touch /etc/machine-id

# Note that running rpm recreates the rpm db files which aren't needed or wanted
rm -f /var/lib/rpm/__db*

%end

%post

# setup mock for appliance-tools on riscv64
# this is needed by Image builder
cat << EOF > /etc/mock/site-defaults.cfg
config_opts['use_nspawn'] = False
EOF

# run update-ca-trust for builder
#
cat << EOF >> /etc/rc.d/rc.local
#!/bin/bash
RC_LOCAL_LOG=/var/log/rc-local.log
echo updating CA for koji builder `date` >> \$RC_LOCAL_LOG
update-ca-trust
EOF

chmod 755 /etc/rc.d/rc.local

cat << EOF >> /etc/fstab
/dev/vdb1  /mnt/storage ext4    defaults,noatime,x-systemd.device-timeout=300s,x-systemd.mount-timeout=300s 0 0

# bind external storage
/mnt/storage/kojid      /etc/kojid      none    bind,defaults   0       0
/mnt/storage/mock       /var/lib/mock   none    bind,defaults   0       0
/mnt/storage/anchors    /etc/pki/ca-trust/source/anchors        none    bind,defaults   0       0
EOF

%end

%post

#Disable existed repo files
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/backup/

# Create Openfedora RISC-V Koji repo
cat << EOF > /etc/yum.repos.d/fedora-riscv-koji.repo
[fedora-riscv-koji]
name=Fedora RISC-V Koji
baseurl=https://openkoji.iscas.ac.cn/kojifiles/repos/f40-build/latest/riscv64/
enabled=1
gpgcheck=0
EOF

%end

%post

# setup login message
cat << EOF | tee /etc/issue /etc/issue.net
Welcome to the Fedora RISC-V disk image
https://openkoji.iscas.ac.cn/koji/

Build date: $(date --utc)

Kernel \r on an \m (\l)

The root password is 'riscv'.
root password logins are disabled in SSH starting Fedora.

If DNS isn’t working, try editing ‘/etc/yum.repos.d/fedora-riscv.repo’.

For updates and latest information read:
https://fedoraproject.org/wiki/Architectures/RISC-V

Fedora RISC-V
-------------
EOF

%end

%post

# Disable default repositories (not riscv64 in upstream)
# dnf config-manager --set-disabled rawhide updates updates-testing fedora fedora-modular fedora-cisco-openh264 updates-modular updates-testing-modular rawhide-modular

# remove window managers cannot run correctly at present (May 16 2021)
# dnf -y remove i3 i3status i3lock swaybg sway

# Re-generating RPM database because the target releasever may use different format of database
# rpm --rebuilddb

# change kernel to some specific
# dnf -y update
# dnf -y remove kernel kernel-core kernel-devel kernel-modules kernel-modules-extra
# dnf -y install kernel-xxx kernel-xxx-core kernel-xxx-devel kernel-xxx-modules kernel-xxx-modules-extra

# KVER=`ls /boot/ | grep -i vmlinuz | grep -i riscv64 | sed -e 's/vmlinuz-//g'`

# dracut -f --kver `ls /boot/ | grep -i vmlinuz | grep -i riscv64 | sed -e 's/vmlinuz-//g'` --add-drivers dw_mmc-pltfm
# dracut -f --kver "${KVER}"
# dracut -f

sed -i \
        -e 's/^ui/# ui/g'	\
        -e 's/^menu autoboot/# menu autoboot/g'	\
        -e 's/^menu hidden/# menu hidden/g'	\
        -e 's/^totaltimeout/# totaltimeout/g'	\
        -e 's/rhgb quiet/rhgb console=tty0 console=ttyS0,115200 earlycon=sbi rootwait selinux=0/g'   \
        -e 's/	fdtdir/#	fdtdir/g' \
        /boot/extlinux/extlinux.conf

# grep -A3 -B0 '^label' /boot/extlinux/extlinux.conf >> tmp.save

# sed -i '/append/i\\tfdt \/some.dtb' /boot/extlinux/extlinux.conf
# cat tmp.save >> /boot/extlinux/extlinux.conf
# rm -vf tmp.save /boot/version.txt

# link ui background file
# ln -sf ./dir/file.png /usr/share/backgrounds/default.png
# ln -sf ../dir/file.png /usr/share/backgrounds/images/default.png
# ln -sf ../dir/file.png /usr/share/backgrounds/images/default-5_4.png
# ln -sf ../dir/file.png /usr/share/backgrounds/images/default-16_9.png
# ln -sf ../dir/file.png /usr/share/backgrounds/images/default-16_10.png

# pushd /lib/firmware/xxx
# ln -sf file link
# popd

# systemd on no-SMP boots (i.e. single core) sometimes timeout waiting for storage
# devices. After entering emergency prompt all disk are mounted.
# For more information see:
# https://www.suse.com/support/kb/doc/?id=7018491
# https://www.freedesktop.org/software/systemd/man/systemd.mount.html
# https://github.com/systemd/systemd/issues/3446
# We modify /etc/fstab to give more time for device detection (the problematic part)
# and mounting processes. This should help on systems where boot takes longer.
sed -i 's|noatime|noatime,x-systemd.device-timeout=300s,x-systemd.mount-timeout=300s|g' /etc/fstab

# systemd starts serial consoles on /dev/ttyS0 and /dev/hvc0.  The
# only problem is they are the same serial console.  Mask one.
systemctl mask serial-getty@hvc0.service

%end

%post

# setup systemd to boot to the right runlevel
echo -n "Setting default runlevel to multiuser text mode"
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
echo .

%end

%packages
@appliance-build
@core
@fedora-packager
@hardware-support
chkconfig
chrony
dracut-config-generic
extlinux-bootloader
forge-srpm-macros
glibc-all-langpacks
glibc-langpack-en
grub2-efi-riscv64
haveged
initscripts
kernel
koji-builder
koji-builder-plugin-rpmautospec
koji-builder-plugins
python-rpmautospec-koji
uboot-images-riscv64
uboot-tools
-dracut-config-rescue
-grubby
-ipw*
-iwl*
-usb_modeswitch

%end