#!/bin/bash

#DESC Creates a systemd service that will run after first reboot only. (After network starts.)
#sed -i '/post_install.sh/d' /etc/crontab
# create post install script
cat > /usr/bin/post_install.sh <<EOF
#!/bin/bash

/usr/bin/updateos conf_firewall
/usr/bin/updateos register_insights
aide -i
cp -f /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
rm -f /etc/yum.repos.d/*
/usr/bin/updateos rh8repo_install
yum -y reinstall perl
/usr/bin/updateos install_ostools-1.16
/usr/bin/updateos install_tcc
update-crypto-policies --set LEGACY
systemctl disable post_install
systemctl disable NetworkManager
systemctl stop NetworkManager
rm -f /etc/systemd/system/post_install.service
rm -f /etc/hosts.allow
rm -f /etc/hosts.deny
/usr/bin/updateos email_results
reboot
EOF

# add post install service file to run after network starts.
cat > /etc/systemd/system/post_install.service <<EOF
[Unit]
Description=Post install script for staging.
After=network-online.target

[Service]
Type=idle
ExecStart=/usr/bin/post_install.sh

[Install]
WantedBy=network-online.target
EOF

chmod +x /usr/bin/post_install.sh
systemctl enable post_install
