#!/bin/sh

# Change to planet

# tradnet -> planet
change_planet () {
    if [ -r /tmp/SeTT_PX ]; then
	T_PX=`cat /tmp/SeTT_PX`
    elif [ -z "$T_PX" -a -n "$1" ]; then
	T_PX=$1
    else
	T_PX=/
    fi
    cd $T_PX

    (
	cd sbin
	rm -f netconfig; ln -s netconfig.planet netconfig
	rm -f enetconfig; ln -s enetconfig.planet enetconfig
    )
    (
	cd etc/rc.d
	rm -f rc.inet1; ln -s rc.inet1.planet rc.inet1
	rm -f rc.dhcp; ln -s rc.dhcp.planet rc.dhcp
	if [ -f rc.pcmcia.planet ]; then
	    ln -s rc.pcmcia.planet rc.pcmcia
	fi
    )
    (
	cd etc/murasaki
	if [ -f murasaki.conf.planet ]; then
	    rm -f murasaki.conf; ln -s murasaki.conf.planet murasaki.conf
	fi
    )
    (
	cd etc
	if [ -f resolv.conf ]; then
	    mv -f resolv.conf resolv.conf.tradnet
	fi
	touch resolv.conf
    )
}

# Installer must call me with -f !!
if [ "$1" = "-f" ]; then
    change_planet
    exit
fi

if [ `ls -l /sbin/netconfig | sed 's/.*-> *//'` = "netconfig.tradnet" ]; then
    if [ ! -x /usr/bin/perl ]; then

cat <<EOF > /tmp/tmpmsg

Planet Ѥˤ perl ɬܤǤperl 󥹥ȡ뤵
Ƥʤ褦Ǥޤperl 򥤥󥹥ȡ뤷Ƥ
 
EOF

	dialog --title "ERROR" --msgbox "`cat /tmp/tmpmsg`" 8 70
	rm -f /tmp/tmpmsg
	exit 1
    fi

cat <<EOF > /tmp/tmpmsg

ߡͥåȥġȤơ 'tradnet' Ȥ
ޤΡPCŬ 'Planet' ѹޤ?

ʤѹϡƥƵưɬפޤޤ
Planet Ѥ硢ѹϡͥåȥޤǽ餫
ľɬפޤ
 
EOF

    dialog --title "Change to Planet?" --yesno "`cat /tmp/tmpmsg`" 12 70
    if [ ! $? = 0 ]; then
	rm -f /tmp/tmpmsg
	exit
    fi
    rm -f /tmp/tmpmsg
    change_planet
fi

exec /sbin/netconfig.planet -noforce
