User Tools

Site Tools

This is the script that cleans up the student's home directory and frees up space in the VM before creating a golden image.

Do not run this on a VM you are already using, as this will wipe out a number of files in the student home directory.

echo "Removing unused packages..."
apt auto-remove -y
echo "Cleaning logs..."
# Stop logging service
service rsyslog stop
# Clear logs
logrotate -f /etc/logrotate.conf
rm /var/log/*.gz /var/log/*.1
echo "Cleaning /tmp and /var/tmp..."
rm -rf /tmp/*
rm -rf /var/tmp/*
echo "Removing SSH keys..."
rm -rf ~student/.ssh/*
rm -rf ~root/.ssh/*
echo "Removing configuration files and histories..."
rm -rf ~root/.bash_history
rm -rf ~student/.bash_history
rm -rf ~student/.mozilla/firefox
rm -rf ~student/.ipython
rm -rf ~student/.chisubmit
rm -rf ~student/.vim
rm -rf ~student/.emacs.d
rm -rf ~student/.gitconfig
rm -rf ~student/.local/share/recently-used.xbel
rm -rf ~student/.config/sublime-text-3
echo "Removing old snaps..."
# From
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
echo "Clearing caches..."
apt clean
rm -rf ~student/.cache
rm -rf /root/.cache
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/snapd/cache/*
echo "Adding SSH host key for"
ssh-keyscan -H > ~student/.ssh/known_hosts
ssh-keyscan -H $(dig +short >> ~student/.ssh/known_hosts
chown -R student.student ~student/.ssh
/var/lib/dokuwiki/data/pages/vm/ · Last modified: 2022/01/07 15:54 by borja