# Installation source for AlmaLinux 8.8
url --url https://mirror.fysik.dtu.dk/linux/almalinux/8.8/BaseOS/x86_64/os/

# System bootloader configuration:
# https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#bootloader
# To generate an encrypted password use the grub2-mkpasswd-pbkdf2 command
bootloader --iscrypted --password=grub.pbkdf2.sha512.10000.5520C6C9832F3AC3D149AC0B24BE69E2D4FB0DBEEDBD29CA1D30A044DE2645C4C7A291E585D4DC43F8A4D82479F8B95CA4BA4381F8550510B75E8E0BB2938990.C688B6F0EF935701FF9BD1A8EC7FE5BD2333799C98F28420C5CC8F1A2A233DE22C83705BB614EA17F3FDFDF4AC2161CEA3384E56EB38A2E39102F5334C47405E

# System authorization information: rootpw command
# To generate an SHA512 encrypted password="password", use:
# python -c 'import crypt,base64,os; print(crypt.crypt("password", "$6$" + base64.b64encode(os.urandom(6))))'
# Read "man 3 crypt" about password hashes.
rootpw --iscrypted <some SHA512 hash>

# Use graphical install (so X is configured)
graphical
#text

# Compute nodes with Slurm MUST have the firewall disabled
firewall --disabled

# Run the Setup Agent on first boot
firstboot --disable
# Accept license
eula --agreed
# Keyboard layouts
# keyboard --vckeymap=dk --xlayouts='dk'
# System language
lang en_US.UTF-8
# Installation logging level
logging --level=info
# Network information: 
# network --bootproto=dhcp --onboot yes --noipv6
network --bootproto=dhcp --onboot yes
# Reboot after installation 
reboot

# SELinux configuration
selinux --permissive
# System timezone
# timezone --utc Europe/Copenhagen

# The file /tmp/part-include is created below in the %pre section
%include /tmp/part-include

%packages
%end

# Start of the %pre section with logging into /root/ks-pre.log
%pre --log=/root/ks-pre.log
# pre section
# https://access.redhat.com/discussions/3144131
#----- partitioning logic below--------------
# pick the first drive that is not removable and is over MINSIZE
DIR="/sys/block"
# minimum size of hard drive needed specified in GIGABYTES
MINSIZE=100
MAXSIZE=1200
ROOTDRIVE=""
# /sys/block/*/size is in 512 byte chunks
# The loop first checks NVME then SATA/SAS drives:
for d in $DIR/nvme* $DIR/sd*
do
  DEV=`basename "$d"`
  if [ -d $DIR/$DEV ]; then
      GB=$((`cat $DIR/$DEV/size`/2**21))
      echo "Disk device $DEV has size $GB GB"
      if [ $GB -gt $MINSIZE -a $GB -lt $MAXSIZE -a -z "$ROOTDRIVE" ]
      then
        ROOTDRIVE=$DEV
        echo "Select ROOTDRIVE=$ROOTDRIVE"
      fi
  fi
done

if [ -z "$ROOTDRIVE" ]
then
	echo "ERROR: ROOTDRIVE is undefined"
else
	echo "ROOTDRIVE=$ROOTDRIVE"
	cat << EOF > /tmp/part-include
zerombr
clearpart --drives=$ROOTDRIVE --all --initlabel
ignoredisk --only-use=$ROOTDRIVE
reqpart --add-boot
part swap --size 32768 --asprimary
part pv.01 --fstype xfs --size=1 --grow --asprimary
volgroup VolGroup00 pv.01
logvol / --fstype xfs --name=lv_root --vgname=VolGroup00 --size=32768
EOF
fi
%end

# Start of the %post section with logging into /root/ks-post.log
%post --log=/root/ks-post.log
# Python3 is required for Ansible client hosts
dnf -y install python36 net-tools nfs-utils tar
%end
