#!/bin/bash

script_path=$(readlink -f ${0%/*})
work_dir=${script_path}/work/x86_64/airootfs

chrooter(){
   arch-chroot ${work_dir} /bin/bash -c "${1}"
}

echo "==== create settings.sh ===="

cat <<EOF >${work_dir}/settings.sh
reflector -a 12 -l 70 -f 30 -p https -p http --sort rate --save /etc/pacman.d/mirrorlist

## blackarch strap
curl -OL https://blackarch.org/strap.sh
sed -i "s|pgp.mit.edu|keys.gnupg.net|g" strap.sh
chmod +x strap.sh
./strap.sh
rm strap.sh

# pacman-key --init
# pacman-key --keyserver keys.gnupg.net --recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3
# pacman-key --lsign-key 4345771566D76038C7FEB43863EC0ADBEA87E4E3
# pacman-key --keyserver keys.gnupg.net --recv-keys F9A6E68A711354D84A9B91637533BAFE69A25079
# pacman-key --lsign-key F9A6E68A711354D84A9B91637533BAFE69A25079

## pacman-key --keyserver keys.gnupg.net --recv-keys 98F76D97B786E6A3
# pacman-key --add /usr/share/pacman/keyrings/ctlos.gpg
# pacman-key --recv-keys 50417293016B25BED7249D8398F76D97B786E6A3
# pacman-key --lsign-key 50417293016B25BED7249D8398F76D97B786E6A3
# pacman-key --populate
# pacman-key --refresh-keys
# pacman -Syy

sed -i '/User/s/^#\+//' /etc/sddm.conf

Lsb_release() {
    sed -i /etc/lsb-release \
        -e 's,DISTRIB_ID=.*,DISTRIB_ID=Ctlos,' \
        -e 's,DISTRIB_RELEASE=.*,DISTRIB_RELEASE=Rolling,' \
        -e 's,DISTRIB_CODENAME=.*,DISTRIB_CODENAME=Anon,' \
        -e 's,DISTRIB_DESCRIPTION=.*,DISTRIB_DESCRIPTION=\"Ctlos Linux\",'

}

Os_release() {
    sed -i /usr/lib/os-release \
        -e 's,NAME=.*,NAME=\"Ctlos Linux\",' \
        -e 's,PRETTY_NAME=.*,PRETTY_NAME=\"Ctlos Linux\",' \
        -e 's,ID=.*,ID=ctlos,' \
        -e 's,ID_LIKE=.*,ID_LIKE=arch,' \
        -e 's,BUILD_ID=.*,BUILD_ID=rolling,' \
        -e 's,HOME_URL=.*,HOME_URL=\"https://ctlos.github.io\",' \
        -e 's,DOCUMENTATION_URL=.*,DOCUMENTATION_URL=\"https://ctlos.github.io/wiki\",' \
        -e 's,SUPPORT_URL=.*,SUPPORT_URL=\"https://forum.ctlos.ru\",' \
        -e 's,BUG_REPORT_URL=.*,BUG_REPORT_URL=\"https://github.com/ctlos/ctlosiso/issues\",' \
        -e 's,LOGO=.*,LOGO=ctlos,'
}

Issues() {
    sed -i 's|Arch|Ctlos|g' /etc/issue /usr/share/factory/etc/issue
}
Lsb_release
Os_release
Issues


# sed -i 's?GRUB_DISTRIBUTOR=.*?GRUB_DISTRIBUTOR=\"Ctlos\"?' /etc/default/grub
# sed -i 's?\#GRUB_THEME=.*?GRUB_THEME=\/boot\/grub\/themes\/crimson\/theme.txt?g' /etc/default/grub
# echo 'GRUB_DISABLE_SUBMENU=y' >> /etc/default/grub
# wget https://github.com/ctlos/ctlos-sh/raw/master/cleaner.sh
# chmod +x cleaner.sh
# mv cleaner.sh /usr/bin/
EOF

chmod +x ${work_dir}/settings.sh
chrooter /settings.sh
rm ${work_dir}/settings.sh

echo "==== Done settings.sh ===="
