From 5ce175ad2b3a86f21d7a4bd37b9a17813b992184 Mon Sep 17 00:00:00 2001 From: Simon Shi Date: Wed, 10 Aug 2016 00:28:33 +0800 Subject: [PATCH] Powerful setup.sh (#3263) * Rewrite run.sh Very powerful run.sh with lots of function. 1.install(make .so) 2.update 3.config generator 4.config backup 5.run loop make it never down It should run like run.sh *.json or other opinion. See -help. * Update run.sh * Update run.sh OK problem solved * Delete setup.py * Rename run.sh to setup.sh * Create run.sh * Update setup.sh * Update install.sh * Update setup.sh * Update run.sh * Update setup.sh Some small fix. --- install.sh | 79 ++++++++++++++++++++++++------- run.sh | 33 ++++++------- setup.py | 13 ------ setup.sh | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+), 50 deletions(-) mode change 100755 => 100644 run.sh delete mode 100644 setup.py create mode 100755 setup.sh diff --git a/install.sh b/install.sh index c11992bb0c..32cc1e1124 100755 --- a/install.sh +++ b/install.sh @@ -1,19 +1,62 @@ #!/usr/bin/env bash - -# Setup Python virtualenv -echo "Setting up Python virtualenv..." -eval "virtualenv ." -eval "source bin/activate" -echo "Python virtualenv setup successfully." - -# Install pip requirements -echo "Installing pip requirements..." -eval "pip install -r requirements.txt" -echo "Installed pip requirements." -echo "Installing and updating git submodules..." - -# Install git submodules -eval "cd ./web && git submodule init && cd .." -eval "git submodule update" -echo "Done." -echo "Please create and setup configs/config.json. Then, run 'python pokecli.py --config ./configs/config.json' or './run.sh' on Mac/Linux" \ No newline at end of file +pokebotpath=$(pwd) +cd $pokebotpath +if [ -f /etc/debian_version ] +then +echo "You are on Debian/Ubuntu" +sudo apt-get update +sudo apt-get -y install python python-pip python-dev build-essential git python-protobuf virtualenv +elif [ -f /etc/redhat-release ] +then +echo "You are on CentOS/RedHat" +sudo yum -y install epel-release +sudo yum -y install python-pip +elif [ "$(uname -s)" == "Darwin" ] +then +echo "You are on Mac os" +sudo brew update +sudo brew install --devel protobuf +else +echo "Nothing happend." +fi +pip install virtualenv +cd $pokebotpath +git pull +git submodule init +git submodule foreach git pull origin master +virtualenv . +source bin/activate +pip install -r requirements.txt +echo "Start to make encrypt.so" +wget http://pgoapi.com/pgoencrypt.tar.gz +tar -xf pgoencrypt.tar.gz +cd pgoencrypt/src/ +make +mv libencrypt.so $pokebotpath/encrypt.so +cd ../.. +rm -rf pgoencrypt.tar.gz +rm -rf pgoencrypt +echo "Install complete." +cd $pokebotpath +read -p "1.google 2.ptc +" auth +read -p "Input username +" username +read -p "Input password +" -s password +read -p " +Input location +" location +read -p "Input gmapkey +" gmapkey +cp configs/config.json.example configs/config.json +if [ "$auth" = "2" ] +then +sed -i "s/google/ptc/g" configs/config.json +fi +sed -i "s/YOUR_USERNAME/$username/g" configs/config.json +sed -i "s/YOUR_PASSWORD/$password/g" configs/config.json +sed -i "s/SOME_LOCATION/$location/g" configs/config.json +sed -i "s/GOOGLE_MAPS_API_KEY/$gmapkey/g" configs/config.json +echo "Edit configs/config.json to modify any other config. Use run.sh to run." +exit 0 diff --git a/run.sh b/run.sh old mode 100755 new mode 100644 index d7ef7079b7..0812dfac8c --- a/run.sh +++ b/run.sh @@ -1,26 +1,21 @@ #!/usr/bin/env bash - -# Starts PokemonGo-Bot -config="" - +pokebotpath=$(pwd) +filename="" if [ ! -z $1 ]; then - config=$1 +filename=$1 else - config="./configs/config.json" - if [ ! -f ${config} ]; then - echo -e "There's no ./configs/config.json file" - echo -e "Please create one or use another config file" - echo -e "./run.sh [path/to/config/file]" - exit 1 - fi +filename="./configs/config.json" +if [ ! -f "$filename" ] +then +echo "There's no "$filename" file. use setup.sh -config to creat one." +fi fi -while [ true ] +while true do -echo "###############################################" -echo "##Exit two times with [Ctl+C] to end the loop##" -echo "###############################################" -sleep 1 -python pokecli.py --config ${config} -sleep "10" +cd $pokebotpath +python pokecli.py -cf $filename +read -p "Press any button or wait 20 seconds." -r -s -n1 -t 20 +echo `date`"Pokebot"$*" Stopped." done +exit 0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 6ccf893c0d..0000000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -from pip.req import parse_requirements - -install_reqs = parse_requirements("requirements.txt", session=False) - -reqs = [str(ir.req) for ir in install_reqs] - -setup(name='pgoapi', - version='1.0', - url='https://github.com/tejado/pgoapi', - packages=['pgoapi'], - install_requires=reqs) diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000000..bcff0feefb --- /dev/null +++ b/setup.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env bash +pokebotpath=$(pwd) +backuppath=$(pwd)"/backup" + +function Pokebotupdate () { +cd $pokebotpath +git pull +git submodule init +git submodule foreach git pull origin master +virtualenv . +source bin/activate +pip install -r requirements.txt +} + +function Pokebotencrypt () { +echo "Start to make encrypt.so" +wget http://pgoapi.com/pgoencrypt.tar.gz +tar -xf pgoencrypt.tar.gz +cd pgoencrypt/src/ +make +mv libencrypt.so $pokebotpath/encrypt.so +cd ../.. +rm -rf pgoencrypt.tar.gz +rm -rf pgoencrypt +} + +function Pokebotconfig () { +cd $pokebotpath +read -p "1.google 2.ptc +" auth +read -p "Input username +" username +read -p "Input password +" -s password +read -p " +Input location +" location +read -p "Input gmapkey +" gmapkey +cp configs/config.json.example configs/config.json +if [ "$auth" = "2" ] +then +sed -i "s/google/ptc/g" configs/config.json +fi +sed -i "s/YOUR_USERNAME/$username/g" configs/config.json +sed -i "s/YOUR_PASSWORD/$password/g" configs/config.json +sed -i "s/SOME_LOCATION/$location/g" configs/config.json +sed -i "s/GOOGLE_MAPS_API_KEY/$gmapkey/g" configs/config.json +echo "Edit configs/config.json to modify any other config." +} + +function Pokebotinstall () { +cd $pokebotpath +if [ -f /etc/debian_version ] +then +echo "You are on Debian/Ubuntu" +sudo apt-get update +sudo apt-get -y install python python-pip python-dev build-essential git python-protobuf virtualenv +elif [ -f /etc/redhat-release ] +then +echo "You are on CentOS/RedHat" +sudo yum -y install epel-release +sudo yum -y install python-pip +elif [ "$(uname -s)" == "Darwin" ] +then +echo "You are on Mac os" +sudo brew update +sudo brew install --devel protobuf +else +echo "Nothing happend." +fi +sudo pip install virtualenv +Pokebotupdate +Pokebotencrypt +echo "Install complete." +Pokebotconfig +} + +function Pokebotreset () { +cd $pokebotpath +git fetch --all +git reset --hard origin/dev +Pokebotupdate +} + +function Pokebothelp () { +echo "usage:" +echo " -i,--install. Install PokemonGo-Bot." +echo " -b,--backup. Backup config files." +echo " -c,--config. Easy config generator." +echo " -e,--encrypt. Make encrypt.so." +echo " -r,--reset. Force sync dev branch." +echo " -u,--update. Command git pull to update." +} + +case $* in +--install|-i) +Pokebotinstall +;; +--encrypt|-e) +Pokebotencrypt +;; +--reset|-r) +Pokebotreset +;; +--update|-u) +Pokebotupdate +;; +--backup|-b) +mkdir $backuppath +cp -f $pokebotpath/configs/config*.json $backuppath/ +cp -f $pokebotpath/web/config/userdata.js $backuppath/ +echo "Backup complete" +;; +--config|-c) +Pokebotconfig +;; +--help|-h) +Pokebothelp +;; +*.json) +filename=$* +cd $pokebotpath +if [ ! -f ./configs/"$filename" ] +then +echo "There's no ./configs/"$filename" file. It's better to use run.sh not this one." +else +Pokebotrun +fi +;; +*) +Pokebothelp +;; +esac +exit 0