base_role/overlay/Linux/usr/local/sbin/box_clean_empty.bash
embed@git.macaw.me b50fd16591 first
2024-01-06 01:38:28 +00:00

63 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# -*- mode: sh; tab-width: 8; coding: utf-8-unix -*-
# in box, unix generic, builder generic
ROLE=hostvms
PREFIX=/var/local
prog=$( basename $0 .bash )
. /usr/local/bin/usr_local_tput.bash
if [ -d /etc/portage ] ; then
# maybe we should delete ALL the package.use and package.mask?
# we did most of them as workarounds or to set the distfiles.zip
rm -f "/etc/portage/package.use/grub.sh"
fi
### CLEANUP TO SHRINK THE BOX ###
# a fresh install probably shouldn't nag about news
# chroot "" /usr/bin/eselect news read all > /dev/null 2>&1
INFO "delete in /tmp and /var/tmp"
rm -rf /tmp/*
rm -rf /var/tmp/*
# there's some leftover junk by gem installation in the root folder
# don't know where this is from (/root/.gem/specs/rubygems.org%80/...), but it should go...
# we use a global ruby by default
# ...probably hard coded path by mistake, report to upstream? Which upstream?!?
[ -d /root/.gem ] && rm -rf /root/.gem
INFO "cleaning kernel"
ls -l /usr/src 2>/dev/null && \
for elt in /usr/src/linux-*/ ; do
[ -f .config ] || continue
INFO "kernel make clean in $elt"
[ -d "$elt" ] || continue
( cd "$elt" && make clean )
done
[ -f /root/bin/packer_clean_distfiles.bash ] && sh /root/bin/packer_clean_distfiles.bash
INFO "fill all free hdd space with zeros"
if df | grep /boot$ ; then
dd if=/dev/zero of="/boot/EMPTY" bs=1M 2>/dev/null
rm "/boot/EMPTY"
sync
fi
dd if=/dev/zero of="/EMPTY" bs=1M 2>/dev/null
rm "/EMPTY"
sync
INFO "fill all swap space with zeros and recreate swap"
cat /proc/swaps |grep ^/ | cut -f 1 -d ' '| while read dev ; do
swapoff $dev || continue
shred -n 0 -z $dev
# FixMe: label?
mkswap $dev
sync
done
exit 0