#!/bin/sh
#Made by Marcelo A.
#All Credits reserved to Marcelo A. nickname (Zap-W) , Copyrighted.

# Must be root
if test "$UID" != 0 ; then
 echo -e "This script must be run as root.\nType in root password, please."
 exec su -c "DISPLAY=$DISPLAY $0"
 exit 1
fi
   
# Must have pppd
if [ ! -x "`which pppd`" ] ; then
    echo "Oops, I can't execute the program pppd.  You"
    echo "must install the PPP software suite, version 2.3.10 or later."
    exit 1
 fi
# If pptp isn't found ,abort installation
if ! [ -x "`which pptp`" -o -x /usr/sbin/pptp-linux -o -x ./pptp-linux ] ; then
    echo "Can't execute the program pptp. You should" 
    echo "install the pptp linux client that comes with your distribution"
    echo ""
    echo "NOTE! ,Mandrake users should install the package pptp-adsl *NOT* pptp-linux!"
    echo ""
    echo "If all fails and your distro dosen't come with a pre-compiled pptp" 
    echo "client, you could try the one in ./scripts , just copy it"
    echo "to the parent directory .. or /usr/sbin"
  
  exit 1
fi

if ! pptp 2>&1 |grep "nolaunchpppd" 2>&1 > /dev/null ; then
 LINUXPPTP="./scripts/pptp-linux"
   echo "Your pptp client is old, consider upgrading ppp and pptp to the latest version..."
   echo "Using  pptp-linux binary insted..."
fi
 
cd `dirname $0`


mkdir -p /usr/sbin

#This checks if /usr/sbin is writable 
# Case it isn't it will place sth-s* files in current directoy 
# Solves the issue with live-cds like knoppix where /usr/sbin is readonly.
 for i in ./scripts/sth-s* ./scripts/pptp-linux ; do
  if ( : > /usr/sbin/1234a ) ; then
install -c -m 755 $i $LINUXPPTP /usr/sbin
rm -f /usr/sbin/1234a
  else
install -c -m 755 $i $LINUXPPTP ./
  fi     
done 

mkdir -p /etc/ppp

for i in sth.conf ; do 
        if [ ! -f /etc/ppp/$i ] ; then 
                install -c -m 644 ./config/$i /etc/ppp 
        else 
                echo "NOT overwriting existing /etc/ppp/$i" 
                install -c -m 644 ./config/$i /etc/ppp/$i-1.0 
        fi 
done
									
if [ -f /etc/redhat-release ] ; then 
        echo "Looks like a Red Hat system; installing /etc/rc.d/init.d/sth" 
        mkdir -p /etc/rc.d/init.d 
        install -c -m 755 ./scripts/sth-init /etc/rc.d/init.d/sth 
fi
if [ -f /etc/turbolinux-release ] ; then 
        echo "Looks like a TurboLinux system; installing /etc/rc.d/init.d/sth" 
        mkdir -p /etc/rc.d/init.d 
        install -c -m 755 ./scripts/sth-init-turbolinux /etc/rc.d/init.d/sth 
fi
if [ -f /etc/SuSE-release ] ; then 
        echo "Looks like a SuSE Linux system; installing /etc/rc.d/init.d/sth" 
        mkdir -p /etc/rc.d/init.d 
        install -c -m 755 ./scripts/sth-init-suse /etc/rc.d/init.d/sth 
fi
echo ""
exec sh ./scripts/sth-setup
