Last active
March 3, 2023 20:22
-
-
Save apharp/d07f64f8df03b22ed2d4f8332aa49f6a to your computer and use it in GitHub Desktop.
Scripts to cleanup a Debian template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -L https://cleanup.aph.im | sh -s | |
history -c | |
history -w | |
sudo poweroff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# run after creating a clone | |
this_file=${0##*/} | |
id | |
if [ `id -u` -ne 0 ]; then | |
echo Need sudo | |
exit 1 | |
fi | |
# Change the VM name | |
echo -n "Set the name of this VM: " | |
read vm_name_input | |
new_vm_name=$(echo $vm_name_input | tr '[:upper:]' '[:lower:]' | tr -d [:space:]) | |
current_vm_name=$(cat /etc/hostname) | |
hostnamectl set-hostname $new_vm_name | |
hostname $new_vm_name | |
sudo sed -i "s/$current_vm_name/$new_vm_name/g" /etc/hosts | |
sudo sed -i "s/$current_vm_name/$new_vm_name/g" /etc/hostname | |
# set time zone | |
timedatectl set-timezone America/Chicago | |
#update apt-cache | |
apt update | |
# update OS | |
apt -y full-upgrade | |
# regenerate ssh host keys | |
test -f /etc/ssh/ssh_host_rsa_key || dpkg-reconfigure openssh-server | |
dbus-uuidgen --ensure=/etc/machine-id | |
dbus-uuidgen --ensure | |
rm $this_file | |
echo "\nPlease reboot this VM now.\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# prep ubuntu for cloning | |
this_file=${0##*/} | |
this_user=$SUDO_USER | |
id | |
if [ `id -u` -ne 0 ]; then | |
echo Need sudo | |
exit 1 | |
fi | |
cd ~ | |
wget https://gist.githubusercontent.com/apharp/d07f64f8df03b22ed2d4f8332aa49f6a/raw/first_run.sh | |
chmod +x first_run.sh | |
#update apt-cache | |
apt update | |
#install packages | |
#apt install -y qemu-guest-agent chrony | |
#flush the logs | |
logrotate -f /etc/logrotate.conf | |
#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 | |
if [ -f /etc/machine-id ]; then | |
cat /dev/null > /etc/machine-id | |
fi | |
if [ -f /var/lib/dbus/machine-id ]; then | |
cat /dev/null > /var/lib/dbus/machine-id | |
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_* | |
#cleanup apt | |
apt clean | |
apt autoremove | |
#rm ~/$this_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment