Skip to content

Instantly share code, notes, and snippets.

@TFaga
Created February 4, 2018 10:34
Show Gist options
  • Save TFaga/50e4624028e358fd6a8363370130ed8f to your computer and use it in GitHub Desktop.
Save TFaga/50e4624028e358fd6a8363370130ed8f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Add usernames to add to /etc/sudoers for passwordless sudo and disable password
users=("ansible")
for user in "${users[@]}"
do
cat /etc/sudoers | grep ^$user
RC=$?
if [ $RC != 0 ]; then
bash -c "echo \"$user ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers"
fi
passwd -d $user
passwd -l $user
done
#update apt-cache
apt-get update
#install packages
apt-get install -y ovirt-guest-agent cloud-init python
#set correct permission for ovirt-guest-agent
chown -R ovirtagent:ovirtagent /var/log/ovirt-guest-agent
#enable ovirg-guest-agent
systemctl enable ovirt-guest-agent
#Stop services for cleanup
service rsyslog stop
#clear audit logs
if [ -f /var/log/audit/audit.log ]; then
cat /dev/null > /var/log/audit/audit.log
fi
if [ -f /var/log/wtmp ]; then
cat /dev/null > /var/log/wtmp
fi
if [ -f /var/log/lastlog ]; then
cat /dev/null > /var/log/lastlog
fi
#cleanup persistent udev rules
if [ -f /etc/udev/rules.d/70-persistent-net.rules ]; then
rm /etc/udev/rules.d/70-persistent-net.rules
fi
#cleanup /tmp directories
rm -rf /tmp/*
rm -rf /var/tmp/*
#cleanup current ssh keys
rm -f /etc/ssh/ssh_host_*
## TODO set user ssh key
#add check for ssh keys on reboot...regenerate if neccessary
sed -i -e 's|exit 0||' /etc/rc.local
sed -i -e 's|.*test -f /etc/ssh/ssh_host_dsa_key.*||' /etc/rc.local
bash -c 'echo "test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server" >> /etc/rc.local'
bash -c 'echo "exit 0" >> /etc/rc.local'
#reset hostname
cat /dev/null > /etc/hostname
#cleanup apt
apt-get clean
#cleanup shell history
history -w
history -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment