#!/bin/sh

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

# start
#
echo "Pre-installing for Main Program..."

# pre-install
#
rm -fr /etc/rc.d/rc*.d/*ntp
rm -fr /etc/rc.d/rc*.d/*fontine
rm -fr /lib/modules/2.4.20_n20-mpu300/v4l2
rm -fr /tmp/*.log
if [ ! -e /proc/bus/usb/devices ]; then
    echo "none /proc/bus/usb usbdevfs defaults 0 0" >> /etc/fstab
fi
if [ ! -e /var/lib/logrotate ]; then
    mkdir -m=u=rwx,go=rx /var/lib/logrotate
fi
if [ ! -e /var/log/helix ]; then
    mkdir -m=u=rwx,go=rx /var/log/helix
fi
touch /var/log/encoder.err
touch /var/log/encoder.info
touch /var/log/helix/error.log
touch /var/log/helix/cache.log
touch /var/log/helix/access.log
touch /var/log/helix/rss.log
touch /var/log/helix/rss.log.0
rm -fr /var/log/*.[1-9]
rm -fr /etc/logrotate.d/apache
rm -fr /etc/logrotate.d/samba
rm -fr /etc/logrotate.d/squid
rm -fr /etc/logrotate.d/wu-ftpd
rm -fr /etc/logrotate.d/zebra
if [ ! -e /anycast/fontine ]; then
    mkdir -p -m=u=rwx,go=rx /anycast/fontine/ttf
fi
if [ ! -e /usr/local/fontine ]; then
    mkdir -p -m=u=rwx,go=rx /usr/local/fontine
fi
if [ ! -e /usr/local/fontine/var ]; then
    ln -s /anycast/fontine /usr/local/fontine/var
fi
rm -fr /usr/local/fontine/var/ttf/HGRHG5.TTF
rm -fr /usr/local/fontine/var/ttf/HGRHR4.TTF
rm -fr /usr/local/fontine/var/ttf/HGRHR8.TTF
if [ -e /usr/local/fontine/ttf ]; then
    rm -fr /usr/local/fontine/ttf/HGRHG5.TTF
    rm -fr /usr/local/fontine/ttf/HGRHR4.TTF
    rm -fr /usr/local/fontine/ttf/HGRHR8.TTF
fi
if [ -e /usr/local/anycast/var/LAST/lastdata1.dat ]; then
    sed -e '/<6:537355520:0>.*/d' \
        -e 's/<3:537153536:0>/<3:537186304:0>/' \
        -e 's/<3:537153792:0>/<3:537186816:0>/' \
        -e 's/<3:537154048:0>/<3:537187328:0>/' \
        -e 's/<3:537154304:0>/<3:537187840:0>/' \
        -e 's/<3:537154560:0>/<3:537188352:0>/' \
        -e 's/<4:538320896:0:0>/<6:538320896:0>/' \
        /usr/local/anycast/var/LAST/lastdata1.dat > /tmp/lastdata1.tmp
    mv -f /tmp/lastdata1.tmp /usr/local/anycast/var/LAST/lastdata1.dat
fi
if [ -e /usr/local/anycast/var/LAST/lastdata1.bak ]; then
    sed -e '/<6:537355520:0>.*/d' \
        -e 's/<3:537153536:0>/<3:537186304:0>/' \
        -e 's/<3:537153792:0>/<3:537186816:0>/' \
        -e 's/<3:537154048:0>/<3:537187328:0>/' \
        -e 's/<3:537154304:0>/<3:537187840:0>/' \
        -e 's/<3:537154560:0>/<3:537188352:0>/' \
        -e 's/<4:538320896:0:0>/<6:538320896:0>/' \
        /usr/local/anycast/var/LAST/lastdata1.bak > /tmp/lastdata1.tmp
    mv -f /tmp/lastdata1.tmp /usr/local/anycast/var/LAST/lastdata1.bak
fi
rm -f /usr/local/fontine/etc/lang.conf
rm -f /usr/local/fontine/etc/lang.conf.*
rm -f /usr/local/fontine/etc/version.*
rm -fr /usr/local/anycast/pixmaps/ja_JP.eucJP
rm -fr /usr/local/anycast/locale/ja_JP.eucJP
rm -fr /usr/local/anycast/fontine/fontine/bmp/ja_JP.eucJP
rm -fr /usr/local/fontine/bmp/ja_JP.eucJP
if [ ! -h /usr/local/anycast/var/CG/SD_Safe_Area.tga.yuv ]; then
    rm -f /usr/local/anycast/var/CG/SD_Safe_Area.tga.yuv
fi
if [ ! -h /usr/local/anycast/var/CG_ATTR/SD_Safe_Area.tga.attr ]; then
    rm -f /usr/local/anycast/var/CG_ATTR/SD_Safe_Area.tga.attr
fi
if [ ! -h /usr/local/anycast/var/CG_THUM/SD_Safe_Area.tga.uyvy ]; then
    rm -f /usr/local/anycast/var/CG_THUM/SD_Safe_Area.tga.uyvy
fi

# end
#
echo "done."
