cockpit/bots/images/scripts/lib/zero-disk.setup

51 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# This file is part of Cockpit.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
# We don't want to delete the pbuilder caches since we need them during build.
# Mock with --offline and dnf is sometimes happy without caches, and with yum it
# never is, so we provide an option to also leave the mock caches in place.
#
# We also want to keep cracklib since otherwise password quality
# checks break on Debian.
if [ -f /root/.skip-zero-disk ]; then
echo "Skipping zero-disk.setup as /root/.skip-zero-disk exists"
exit 0
fi
keep="! -path /var/cache/pbuilder ! -path /var/cache/cracklib ! -path /var/cache/tomcat"
while [ $# -gt 0 ]; do
case $1 in
--keep-mock-cache)
keep="$keep ! -path /var/cache/mock"
;;
esac
shift
done
if [ -d "/var/cache" ]; then
find /var/cache/* -maxdepth 0 -depth -name "*" $keep -exec rm -rf {} \;
fi
rm -rf /var/tmp/*
rm -rf /var/log/journal/*
dd if=/dev/zero of=/root/junk || true
sync
rm -f /root/junk