# Generated by pykickstart v3.47
#version=DEVEL
# Use text mode install
text
# Firewall configuration
firewall --enabled --service=mdns
# Keyboard layouts
keyboard 'us'
# System language
lang en_US.UTF-8
# Network information
network  --bootproto=dhcp --device=link --activate
# Shutdown after installation
shutdown
repo --name="koji-f39-build-47510" --baseurl=http://openkoji.iscas.ac.cn/kojifiles/repos/f39-build/47510/riscv64
# Root password
rootpw --plaintext riscv
# SELinux configuration
selinux --enforcing
# System services
services --disabled="lm_sensors,libvirtd,gdm" --enabled="sshd,dbus-broker,NetworkManager,chronyd,haveged,lightdm"
# System timezone
timezone US/Eastern
# System bootloader configuration
bootloader --location=mbr --timeout=1
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel --disklabel=gpt
# Disk partitioning information
part /boot/efi --fstype="vfat" --size=128 --label=EFI
part /boot --fstype="ext4" --size=1024 --label=boot
part / --fstype="ext4" --size=12288 --label=rootfs

%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

#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/repos/f38-build-side-42-init-devel/31010/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

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

%end

%post

# Explicitly set graphical.target as default as this is how initial-setup detects which version to run
echo -n "Setting default runlevel to graphical mode[5]"
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/graphical.target /etc/systemd/system/default.target
echo .

%end

%post

# remove unnecessary entry in /etc/fstab
#sed -i '/swap/d' /etc/fstab
#sed -i '/efi/d' /etc/fstab

%end

%post

pushd /tmp

#making a temp resolv.conf file
rm -f /etc/resolv.conf
echo 'nameserver 114.114.114.114' >> /etc/resolv.conf

/usr/bin/wget -P image-bin-patch "http://openkoji.iscas.ac.cn/pub/dl/riscv/Sophgo/SG2042_EVB/kernel-cross/image-bin-patch.tar"

#recover to the original resolv.conf
rm -f /etc/resolv.conf
ln -s ../run/systemd/resolve/stub-resolv.conf  /etc/resolv.conf

pushd image-bin-patch
/usr/bin/tar  xpf image-bin-patch.tar
rm -f image-bin-patch.tar
cp -rvf * /
popd

rm -rf image-bin-patch

popd

sed -i -e "s/@@ROOTUUID@@/${ROOT_UUID}/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@DISTRO@@/Fedora/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@DISTRO_RELAESE@@/fc39/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@KERNEL_RELAESE@@/6.1.55/g"   \
    /boot/extlinux/extlinux.conf

dracut -f --regenerate-all

%end

%post

#/usr/sbin/sfdisk -l /dev/loop0

#echo 'Deleting the first partition of Image...'
#/usr/sbin/sfdisk --delete /dev/loop0 1
#/usr/sbin/sfdisk -l /dev/loop0

#echo 'Reorder the partitions of Image...'
#/usr/sbin/sfdisk -r /dev/loop0
#/usr/sbin/sfdisk -l /dev/loop0

pushd /tmp

#making a temp resolv.conf file
rm -f /etc/resolv.conf
echo 'nameserver 114.114.114.114' >> /etc/resolv.conf

/usr/bin/wget -P boot "http://openkoji.iscas.ac.cn/pub/dl/riscv/Sophgo/SG2042_EVB/FW/EFI.tar"

#recover to the original resolv.conf
rm -f /etc/resolv.conf
ln -s ../run/systemd/resolve/stub-resolv.conf  /etc/resolv.conf

pushd boot
/usr/bin/tar  xpf EFI.tar
rm -f EFI.tar
cp -rvf * /boot/efi/
popd

rm -rf boot

popd

ROOT_UUID=`grep ' / ' /etc/fstab | awk '{printf $1}' | sed -e 's/^UUID=//g'`

sed -i -e "s/@@ROOTUUID@@/${ROOT_UUID}/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@DISTRO@@/Fedora/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@DISTRO_RELAESE@@/fc38/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@KERNEL_RELAESE@@/6.1.55/g"   \
    /boot/extlinux/extlinux.conf

sed -i -e "s/@@STORAGE@@/Installer Image/g"   \
    /boot/extlinux/extlinux.conf
%end

%packages
@admin-tools
@base-x
@buildsys-build
@c-development
@core
@development-tools
@fedora-packager
@hardware-support
@input-methods
@lxde-apps
@lxde-desktop
@lxde-media
@lxde-office
@lxqt-apps
@lxqt-desktop
@lxqt-l10n
@lxqt-media
@rpm-development-tools
@standard
@xfce-apps
@xfce-desktop
@xfce-extra-plugins
@xfce-media
@xfce-office
NetworkManager-bluetooth
PackageKit*
ack
appliance-tools
aria2
autoconf-archive
avahi
axel
binwalk
bloaty
bpftool
chkconfig
chrony
ckermit
cmake
colordiff
cowsay
dracut-config-generic
dtc
elinks
enki
entr
evemu
execstack
f2fs-tools
fedora-release-xfce
gcc-gdb-plugin
gcc-gfortran
gcc-plugin-devel
glibc-all-langpacks
glibc-langpack-en
glibc-static
gnome-keyring
grub2-efi-riscv64
grub2-efi-riscv64-modules
gstreamer1-plugin-mpg123
haveged
hdparm
hexedit
htop
i2c-tools
i2c-tools-perl
incron
initscripts
inxi
iproute-tc
iptables-services
isomd5sum
jfsutils
kernel
kernel-tools
koji-builder
koji-builder-plugin-rpmautospec
koji-builder-plugins
lftp
libatomic-static
libgfortran
libgfortran-static
libgpiod
libgpiod-c++
libgpiod-devel
libgpiod-utils
libi2c
libi2c-devel
libstdc++-static
livecd-tools
lximage-qt-l10n
mailx
mandoc
mc
metacity
moreutils
mtd-utils
mutt
nbd
nbdkit
ncdu
neofetch
ninja-build
nnn
notification-daemon
nvme-cli
obconf-qt-l10n
openrdate
openssl-devel
pavucontrol-qt-l10n
pax-utils
pcmanfm
perl-devel
perl-generators
pesign
prettyping
pv
pycdio
pykickstart
python-imgcreate-sysdeps
python3-asn1crypto
python3-bluez
python3-crypto
python3-entrypoints
python3-evdev
python3-i2c-tools
python3-imgcreate
python3-iso8601
python3-isomd5sum
python3-jmespath
python3-ordered-set
python3-pyelftools
python3-pyserial
python3-sh
python3-wheel
qemu-guest-agent
qemu-img
selinux-policy
setools-console
setroubleshoot-server
spi-tools
storaged
stress-ng
tar
tcsh
texinfo
the_silver_searcher
tig
tldr
tmux
trousers
uboot-tools
udftools
wget
wqy-bitmap-fonts
wqy-microhei-fonts
wqy-unibit-fonts
wqy-zenhei-fonts
zsh
-acpid
-dracut-config-rescue
-foomatic
-fprintd-pam
-generic-release*
-gimp-help
-iok
-ipw*
-iwl*
-libguestfs-tools-c
-polkit-gnome
-polkit-kde
-pt-sans-fonts
-system-config-network
-usb_modeswitch

%end