#!/bin/bash

PYTHON_VERSION="2.7.15"
PIP_URL="https://bootstrap.pypa.io"
PYTHON_URL="https://www.python.org/ftp/python"

obfs_proxy_port=44443

if [ -f /etc/init.d/obfsproxy ]; then
    	echo "obfsproxy already present, we exit the script now!"
		exit 1
fi

IPLIST=`ip addr show | egrep -v '\blo|inet6' | egrep ':[0-9]+$' | awk '{print $2}' | sed -e 's/\/.*//g' | sort -r`

/bin/cp -Rp /etc/nginx /etc/nginx_backup

yum update -x freeradius* -x kernel* -x perl* -x strongswan* -x openvpn* --skip-broken
yum groupinstall -y "development tools" --skip-broken
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel --skip-broken -y

wget $PYTHON_URL/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.xz
tar -xf Python-$PYTHON_VERSION.tar.xz
cd Python-$PYTHON_VERSION
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" ; make && make altinstall

strip /usr/local/lib/libpython2.7.so.1.0
wget $PIP_URL/get-pip.py
python2.7 get-pip.py
pip2.7 install --upgrade pip
pip2.7 install obfsproxy

python --version

mkdir /var/run/obfsproxy
/bin/cp -Rp /root/nvpn-ss5/obfsproxy/obfsproxy /etc/init.d/
chkconfig --add obfsproxy
chkconfig --list obfsproxy
chkconfig obfsproxy on

echo "obfsproxy       44443/tcp               # obfsproxy" >> /etc/services
service obfsproxy start
service obfsproxy status

echo "alias tl='tail -f /var/log/messages /var/log/obfsproxy*.log'
alias fl='>/var/log/messages'
alias nl='netstat -tulpn'" >> ~/.bashrc

. ~/.bashrc

rm -rf Python-$PYTHON_VERSION Python-$PYTHON_VERSION.tar.xz
service nrpe restart