#!/bin/sh

# Copyright (c) 2018, The ULBSD Project
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id: ulbsd-prepare 56 2021-02-12 21:02:53Z sv $

/bin/rm -Rv /.rnd
/bin/rm -Rv /.snap/*
/bin/rm -Rv /entropy
/bin/rm -Rv /restoresymtable
/bin/rm -Rv /boot/kernel.old*
/bin/rm -Rv /etc/hostid
/bin/rm -Rv /etc/resolv.conf*
/bin/rm -Rv /tmp/*
/bin/rm -Rv /tmp/.*
/bin/rm -Rv /usr/obj/*
/bin/rm -Rv /usr/ports/*
/bin/rm -Rv /usr/ports/.*
/bin/rm -Rv /var/backups/*
/bin/rm -Rv /var/db/dhclient.leases*
/bin/rm -Rv /var/db/freebsd-update/*
/bin/rm -Rv /var/db/mixer*
/bin/rm -Rv /var/db/portsnap/*
/bin/rm -Rv /var/db/sudo/lectured/*
/bin/rm -Rv /var/log/*.bz2
/bin/rm -Rv /var/log/sendmail.st.*
/bin/rm -Rv /var/log/Xorg.0.log.old
/bin/rm -Rv /var/mail/*
/bin/rm -Rv /var/run/*.pid
/bin/rm -Rv /var/run/*.pipe
/bin/rm -Rv /var/run/dmesg*
/bin/rm -Rv /var/run/dbus/*
/bin/rm -Rv /var/run/openct/status
/bin/rm -Rv /var/run/resolvconf/*
/bin/rm -Rv /var/run/sudo/ts/*
/bin/rm -Rv /var/run/syslogd.sockets
/bin/rm -Rv /var/run/utx.active
/bin/rm -Rv /var/tmp/*
/bin/rm -Rv /var/tmp/.*
/bin/rm -Rv /usr/local/share/ulbsd/license.key

/usr/bin/find /var/log/ -name "*" -type f -exec /usr/bin/truncate -s 0 {} \;
/usr/bin/sed -i '' -e '/ifconfig_/Id; /defaultrouter/Id' /etc/rc.conf

cd /root/; /bin/rm -Rv `/bin/ls -A | /usr/bin/grep -v '\.cshrc\|\.face\.icon\|\.k5login\|\.login\|\.profile\|\.startwm\.sh\|\.vnc\|\.xinitrc\|\.xprofile'`

/usr/bin/sed -i '' -e '/Variant=/Id' /usr/local/share/ulbsd/compile/cfgs/usr/local/etc/xdg/kcm-about-distrorc
/bin/echo "Variant=`/bin/date +'%Y.%m.%d'`" >> /usr/local/share/ulbsd/compile/cfgs/usr/local/etc/xdg/kcm-about-distrorc

# /sbin/mount_msdosfs /dev/da0s1 /mnt
# /sbin/dump -0Lf - / | /usr/local/bin/7z a -si -mx=9 /mnt/dump_root.img.7z >/dev/null
# cd / ; /sbin/umount /mnt
