#!/bin/sh

set -e

echo "Removing unwanted files"

# Get POTFILES_DOT_IN
. /usr/share/tails/build/variables

find /usr/share/doc -type f -name changelog.gz -delete
find /usr/share/doc -type f -name changelog.Debian.gz -delete
find /usr/share/doc -type f -name NEWS.Debian.gz -delete

# Remove .in files managed by intltool
# shellcheck disable=SC2086
rm $POTFILES_DOT_IN

# These files are not needed after the Tor Browser has been installed
# (by the 10-tbb hook)
rm /usr/share/tails/tbb-*.txt

# Remove the snakeoil SSL key pair generated by ssl-cert
find /etc/ssl/certs /etc/ssl/private |
    while read -r f; do
        if [ "$(readlink -f "$f")" = "/etc/ssl/certs/ssl-cert-snakeoil.pem" ] ||
            [ "$(readlink -f "$f")" = "/etc/ssl/private/ssl-cert-snakeoil.key" ]; then
            rm "${f}"
        fi
    done
update-ca-certificates

# Remove the kernel .map files which are only useful for kernel
# debugging (and slightly make things easier for malware, perhaps) and
# otherwise just occupy disk space.
rm -f /boot/*.map /boot/*.map-*

# Files needed at build time for preparing the Unsafe Browser
rm /usr/local/bin/jsonlz4
rm /usr/share/tails/chroot-browsers/unsafe-browser/addonStartup.json

# Other files used at build time only
rm -r /usr/src

# Documentation that's large and not that useful in Tails
rm -r /usr/share/inkscape/examples

# Don't include hunspell dictionaries in the bdic format
#
# These dictionaries are shipped *in addition to* the same
# dictionaries in the .dic + .aff format and grow the image
# size significantly.
#
# Only Chrome & friends, as well as apps that use Qt WebEngine, use
# the bdic format, so no app we ship loses spellchecking
# by excluding those.
rm -f /usr/share/hunspell-bdic/*.bdic
