#!/bin/bash
# Run from inside 003-lxde
pver=porteus-v1.0

# Remove backup files
find . -name "*~"|xargs rm

# Remove reduntant files
rm -r usr/info
rm -r usr/doc
rm usr/man/man2/*
rm usr/man/man3/*
rm usr/man/man4/*
rm usr/man/man6/*
rm usr/man/man9/*
rm -r usr/share/gtk-doc
#rm usr/share/lxde/wallpapers/*
rm -r var/log/remove*
rm -r var/log/setup

# showexec workaround
sed -i -e 's|showexec|\x00\x00\x00\x00\x00\x00\x00\x00|g' usr/libexec/udisks-daemon

# Set permissions
chown -R 1000:1000 home/guest
chown -R root:root root

echo "Changing permissions..."
find ./ -type d | xargs chmod -v 755 >/dev/null 2>&1
echo "Extracting All manpages..."
find . | grep .gz | xargs gunzip >/dev/null 2>&1
echo "stripping Unneeded Symbols..."
find . | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded >/dev/null 2>&1

echo "moving a.out, include and locale"
pack=`find . -name "*.a"`
target=/mnt/sda7/porteus32/$pver/export/a.out
[ ! -d $target ] && mkdir $target
for a in $pack; do
    cp -d --parents $a $target
    rm $a
done

headers=/mnt/sda7/porteus32/$pver/export/devel
cp -r usr/include $headers && rm -r usr/include/*
locales=/mnt/sda7/porteus32/$pver/export/togo
cp -r usr/share/locale $locales && rm -r usr/share/locale/*
for x in `ls usr/man | grep -v man`; do
    cp -r usr/man/$x /mnt/sda7/porteus32/$pver/export/togo/man
    rm -r usr/man/$x
done

echo "003 has been processed! All done."
echo
exit
