-
Notifications
You must be signed in to change notification settings - Fork 4
/
cleanup.sh
executable file
·63 lines (47 loc) · 1.28 KB
/
cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
set -e
apt clean
rm -rf /var/lib/apt/lists/*
# Do this at runlevel 3 (init 3)
systemctl stop rsyslog
systemctl stop open-vm-tools
systemctl stop systemd-journald
# Clear out login records
truncate -s0 /var/log/wtmp
truncate -s0 /var/log/lastlog
# Clear out temporary files
rm -rf /tmp/*
rm -rf /var/tmp/*
# Clean up home directories
rm ~ioi/.bash_history || true
rm ~ansible/.bash_history || true
rm ~root/.bash_history || true
# Empty system and kernel logs
cat /dev/null > /var/log/kern.log
cat /dev/null > /var/log/dmesg
cat /dev/null > /var/log/syslog
cat /dev/null > /var/log/auth.log
cat /dev/null > /var/log/cloud-init.log
# Remove various logs
rm /var/log/vmware*log || true
rm /var/log/Xorg*log || true
rm /var/log/unattended-upgrades/* || true
rm /var/log/apt/term.log || true
rm -rf /var/log/journal/* || true
rm -rf /var/log/installer || true
# Clear cloud-init, forces regeneration of SSH host keys among other things next boot up
cloud-init clean --logs
# Recreate swap file
swapoff -a
rm /swap.img
dd if=/dev/zero of=/swap.img bs=1048576 count=3908
mkswap /swap.img
chmod 600 /swap.img
# Clean out local config file
if [ -f "config.local.sh" ]; then
rm config.local.sh
fi
PARTKEY=$(/opt/ioi/sbin/genkey.sh)
echo $PARTKEY
echo REMEMBER TO REMOVE SETUP DIRECTORY
# vim: ts=4