diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d033330 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ + +SHELL = /bin/bash +TOOLS="./tools" + +.PHONY: help run kill status monitor errors + +help: + @ echo "" + @ echo "Usage:" + @ echo " run: Launch the Bot" + @ echo " kill: Stop the Bot" + @ echo " status: Check if Bot is running" + @ echo " monitor: Check users captcha process" + @ echo " error: Check for errors in the Bot" + @ echo "" + +run: + @ $(TOOLS)/run + +kill: + @ $(TOOLS)/kill + +status: + @ $(TOOLS)/status + +monitor: + @ $(TOOLS)/monitor + +errors: + @ $(TOOLS)/check_errors diff --git a/docker/Dockerfile b/docker/Dockerfile index 3f9247c..c9aa275 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -75,5 +75,5 @@ RUN chown -R "${BOT_USER}:${BOT_GROUP}" ${BOT_HOME_DIR} && \ # Set up to run as an unprivileged user USER ${BOT_USER} -WORKDIR ${APP_DIR}/src -CMD ["./entrypoint.sh"] +WORKDIR ${APP_DIR} +CMD ["./tools/entrypoint.sh"] diff --git a/src/check_errors b/src/check_errors deleted file mode 100644 index 197c12f..0000000 --- a/src/check_errors +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -cat -n output.log | grep -e "Traceback" -A 15 -B 5 - -exit 0 diff --git a/src/monitor b/src/monitor deleted file mode 100644 index 37a32db..0000000 --- a/src/monitor +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -# Actual script directory path -DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -tail -n1000 -f $DIR/output.log | grep -e "New join detected:" -e "Captcha not solved, kicking" -e "Captcha solved by" - -exit 0 diff --git a/src/run b/src/run deleted file mode 100644 index 7f2b976..0000000 --- a/src/run +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -# Actual script directory path -DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" - -# Process ID -PID=`ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}'` - -if [ ! -z "$PID" ]; then - echo "Already running." - exit 1 -fi - -rm -rf $DIR/data/captchas/* -nohup python3 -u $DIR/join_captcha_bot.py >> $DIR/output.log 2>&1 & -echo "Starting Script..." -sleep 1 -$DIR/status - -exit 0 diff --git a/src/entrypoint.sh b/tools/check_errors similarity index 57% rename from src/entrypoint.sh rename to tools/check_errors index f238eac..627052e 100644 --- a/src/entrypoint.sh +++ b/tools/check_errors @@ -3,6 +3,7 @@ # Actual script directory path DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -rm -f $DIR/data/captchas/* +# Check and shows errors +cat -n $DIR/../output.log | grep -e "Traceback" -A 15 -B 5 -exec python3 -u $DIR/join_captcha_bot.py +exit 0 diff --git a/tools/entrypoint.sh b/tools/entrypoint.sh new file mode 100644 index 0000000..5b2f5a8 --- /dev/null +++ b/tools/entrypoint.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Actual script directory path +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +# Clean old/previous residual captcha images +rm -f $DIR/../src/data/captchas/* + +# Launch the Bot +exec python3 -u $DIR/../src/join_captcha_bot.py diff --git a/src/forcekill b/tools/forcekill similarity index 67% rename from src/forcekill rename to tools/forcekill index 7d3d9b3..0d54cfe 100644 --- a/src/forcekill +++ b/tools/forcekill @@ -4,18 +4,22 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" # Process ID -PID=`ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}'` +PID=$(ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}') +# Check if process is running if [ -z "$PID" ]; then echo "Script is not running." exit 1 fi +# Kill the process kill -9 $PID echo "Killing script, please wait..." while $(kill -0 $PID 2>/dev/null); do sleep 1 done + +# Show process status after kill $DIR/status exit 0 diff --git a/src/kill b/tools/kill similarity index 67% rename from src/kill rename to tools/kill index ed16a79..77a0627 100644 --- a/src/kill +++ b/tools/kill @@ -4,18 +4,22 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" # Process ID -PID=`ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}'` +PID=$(ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}') +# Check if process is running if [ -z "$PID" ]; then echo "Script is not running." exit 1 fi +# Kill the process echo "Killing script, please wait..." kill $PID while $(kill -0 $PID 2>/dev/null); do sleep 1 done + +# Show process status after kill $DIR/status exit 0 diff --git a/tools/monitor b/tools/monitor new file mode 100644 index 0000000..a96a691 --- /dev/null +++ b/tools/monitor @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# Actual script directory path +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +# Continuous check and show users joins and captcha process +tail -n1000 -f $DIR/../output.log | grep -e "New join detected:" -e "Captcha not solved, kicking" -e "Captcha solved by" + +exit 0 diff --git a/tools/run b/tools/run new file mode 100644 index 0000000..5d14398 --- /dev/null +++ b/tools/run @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Actual script directory path +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +# Process ID +PID=$(ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}') + +# Check if process is running +if [ ! -z "$PID" ]; then + echo "Already running." + exit 1 +fi + +# Clean old/previous residual captcha images +rm -rf $DIR/../src/data/captchas/* + +# Launch the Bot +echo "Starting Script..." +nohup python3 -u $DIR/../src/join_captcha_bot.py >> $DIR/../output.log 2>&1 & +sleep 1 +$DIR/status + +exit 0 diff --git a/src/status b/tools/status similarity index 52% rename from src/status rename to tools/status index 138f92f..d5bfc0e 100644 --- a/src/status +++ b/tools/status @@ -1,7 +1,7 @@ #!/usr/bin/env bash -PID=`ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}'` - +# Check if process is running +PID=$(ps -aux | grep -e "[j]oin_captcha_bot.py" | awk 'FNR == 1 {print $2}') if [ -z "$PID" ]; then echo "Not running." else diff --git a/src/language/update_languages b/tools/update_languages similarity index 94% rename from src/language/update_languages rename to tools/update_languages index 76afea8..0a6b9d2 100644 --- a/src/language/update_languages +++ b/tools/update_languages @@ -3,9 +3,11 @@ # Actual script directory path DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -cd $DIR -rm -f $DIR/*.json +# Go to language text files directory and remove them +cd $DIR/../src/language +rm -f ./*.json +# Download latests language text files from Github wget https://raw.githubusercontent.com/J-Rios/TLG_JoinCaptchaBot/master/src/language/ar.json wget https://raw.githubusercontent.com/J-Rios/TLG_JoinCaptchaBot/master/src/language/be.json wget https://raw.githubusercontent.com/J-Rios/TLG_JoinCaptchaBot/master/src/language/ca.json