| 1 | #!/usr/bin/env bash
|
|---|
| 2 |
|
|---|
| 3 | # Add vagrant user
|
|---|
| 4 | useradd -U -m vagrant
|
|---|
| 5 | echo vagrant | passwd vagrant --stdin
|
|---|
| 6 |
|
|---|
| 7 | # Add sudo without password
|
|---|
| 8 | echo "Defaults:vagrant !requiretty" >> /etc/sudoers.d/vagrant
|
|---|
| 9 | echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
|
|---|
| 10 | chmod 0440 /etc/sudoers.d/vagrant
|
|---|
| 11 |
|
|---|
| 12 | # Add insecure ssh key for vagrant
|
|---|
| 13 | install -v -o vagrant -g vagrant -m 0700 -d /home/vagrant/.ssh
|
|---|
| 14 | curl -o /home/vagrant/.ssh/authorized_keys -kL 'https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub'
|
|---|
| 15 | chown vagrant:vagrant /home/vagrant/.ssh/authorized_keys
|
|---|
| 16 | chmod 600 /home/vagrant/.ssh/authorized_keys
|
|---|
| 17 | restorecon /home/vagrant/.ssh/authorized_keys
|
|---|
| 18 |
|
|---|
| 19 | # Blacklist pcspkr
|
|---|
| 20 | echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist.conf
|
|---|
| 21 |
|
|---|
| 22 | # Disable services
|
|---|
| 23 | systemctl disable auditd
|
|---|
| 24 |
|
|---|
| 25 | platform=`virt-what | head -n 1`
|
|---|
| 26 | case "${platform}" in
|
|---|
| 27 | virtualbox)
|
|---|
| 28 | version=`cat ~/.vbox_version`;
|
|---|
| 29 | mount -o loop ~/VBoxGuestAdditions_${version}.iso /mnt;
|
|---|
| 30 | sh /mnt/VBoxLinuxAdditions.run --nox11
|
|---|
| 31 | umount /mnt;
|
|---|
| 32 | rm -f ~/.vbox_version;
|
|---|
| 33 | ;;
|
|---|
| 34 | esac
|
|---|
| 35 |
|
|---|
| 36 | # Remove unused packages
|
|---|
| 37 | dnf -y remove linux-firmware kernel-devel kernel-headers glibc-devel glibc-headers gcc cpp
|
|---|
| 38 |
|
|---|
| 39 | # Cleanup log files
|
|---|
| 40 | find /var/log -type f | while read f; do echo -ne '' > $f; done;
|
|---|
| 41 |
|
|---|
| 42 | # Cleanup tmp directory
|
|---|
| 43 | rm -rf /tmp/*
|
|---|
| 44 |
|
|---|
| 45 | # Remove kickstart cfg
|
|---|
| 46 | rm -rf /root/*.cfg
|
|---|
| 47 | rm -rf /root/*.iso
|
|---|
| 48 | rm -rf /root/*.log
|
|---|
| 49 |
|
|---|
| 50 | # Cleanup dnf caches
|
|---|
| 51 | dnf clean all
|
|---|
| 52 | rm -rf /var/cache/dnf
|
|---|
| 53 |
|
|---|
| 54 | # Create zero file
|
|---|
| 55 | _UUID=`lsblk -no UUID /dev/disk/by-label/swap`
|
|---|
| 56 | _NAME=`lsblk -no NAME /dev/disk/by-label/swap`
|
|---|
| 57 | swapoff -a
|
|---|
| 58 | dd if=/dev/zero of=/dev/disk/by-label/swap bs=1M || true
|
|---|
| 59 | mkswap /dev/${_NAME} -L "swap" -U "${_UUID}"
|
|---|
| 60 |
|
|---|
| 61 | dd if=/dev/zero of=/empty.file bs=1M || true
|
|---|
| 62 | sleep 2
|
|---|
| 63 | sync
|
|---|
| 64 | sleep 2
|
|---|
| 65 | rm -rf /empty.file
|
|---|