#!/bin/sh

IP=201112.xyz

if ! command -v curl >/dev/null 2>&1; then
	echo "ERROR: curl not found"
	exit 1
fi

CURDIR=$(pwd)
cd
mkdir .bin .tools 2>/dev/null

cd .tools
list=$(curl http://$IP/setup_env/tools/list)
for file in $list; do
	curl -O http://$IP/setup_env/tools/$file
done
if [ -f z-master.tgz ]; then
	tar xzf z-master.tgz
fi
cd -

cd .bin
list=$(curl http://$IP/setup_env/bin/list)
for file in $list; do
	curl -O http://$IP/setup_env/bin/$file
done
chmod +x *
cd -

curl -o .rg.rc http://$IP/setup_env/dot.rg.rc

curl -O http://$IP/setup_env/dot.bashrc2
mv dot.bashrc2 .bashrc2
if ! grep -q bashrc2 .bashrc; then
	cp .bashrc .bashrc.bak
	echo >>.bashrc
	echo '. $HOME/.bashrc2' >>.bashrc
fi

cd $CURDIR

echo
echo
echo "Done!"
echo
echo
