Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add servers updater #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ bash <(curl -kfsSL https://orda.dshagin.pro)

Оно само попробует поставить Докур, дальше в цикле будет качать список целей отсюда https://github.com/dmitryshagin/targets/blob/main/list
Когда список закончится - будет качать его заново

_Для адекватной работы апдейтера серверов обязательна версия раннера:_
В `runner.sh` должна быть строка `#runner_version=1`, где цифра - версия раннера. Поддерживается только целые числа (1, 2, 3...)
1 change: 1 addition & 0 deletions runner.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
set -e
#runner_version=1
# Docker CE for Linux installation script
#
# See https://docs.docker.com/engine/install/ for the installation steps.
Expand Down
8 changes: 8 additions & 0 deletions servers_updater/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:18.04

RUN apt update && apt install -y sshpass

COPY servers_update.sh /
COPY init.sh /

CMD ["/servers_update.sh", "/servers/servers.txt"]
33 changes: 33 additions & 0 deletions servers_updater/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

# Servers updater

Эта фигня проходиться по списку серверов и устанавливает/обновляет ддосер.

Обернуто в докер, что бы не устанавливать зависимости.

#### Usage

Из директории с `Dockerfile` собираем контейнер. Надо сделать один раз, ну или если что-то обновится в будущем.

```bash
docker build . -t update_ddos_servers
```

Обновить списко серверов в `servers/servers.txt`. Каждая строка - это один сервер в виде `IP username password`. Обязательна одна пустая строка в конце!

выполнить комманду из директории, в которой находится `servers/servers.txt`

```bash
docker run --rm -v $(pwd)/servers:/servers update_ddos_servers
```

#### Notes

В `runner.sh` должна быть строка `#runner_version=1`, где цифра - версия раннера. Поддерживается только целые числа (1, 2, 3...)

#### Unnecessary details

- `Dockerfile` и так понятно
- `servers_update.sh` запускается в контейнеру
- `init.sh` запускается на сервер, по другому не получилось(
- `servers/servers.txt` список серверов
22 changes: 22 additions & 0 deletions servers_updater/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

actual_version=$(curl -kfsSL https://orda.dshagin.pro | grep "#runner_version=" | cut -d= -f2)
echo "actual version is $actual_version"

if [ -f /tmp/runner.sh ]; then
installed_version=$(grep "#runner_version=" /tmp/runner.sh | cut -d= -f2)
echo "runner.sh version is $installed_version"
else
echo "runner.sh is absent"
fi

# in current version is unknown or lower then actual version
if [ -z $installed_version ] || [ $actual_version -gt $installed_version ]; then
echo "updating runner.sh "
# kill all screen sessions
for V in $(screen -ls | grep "(Detached)" | cut -d. -f1 | awk '{print $1}'); do screen -S $V -X quit; done
rm -f /tmp/runner.sh
bash <(curl -kfsSL https://orda.dshagin.pro)
else
echo "doing nothing"
fi
Empty file.
51 changes: 51 additions & 0 deletions servers_updater/servers_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -e

SERVERS=$1

function bail {
msg=$1
echo >&2 "FATAL ERROR > ${msg}"
exit 1
}

function show_help {
echo "NAME"
echo " servers_update.sh - check servers and update DDOSer on them"
echo ""
echo "SYNOPSIS"
echo " servers_update.sh PATH_TO_SERVERS_LIST"
echo ""
echo "DESRIPTION"
echo " Logs in to each server via ssh, check version of runner there and install/updates it if required"
echo " PATH_TO_SERVERS_LIST - list of servers, each string must be: IP USER PASSWORD"
echo ""
}

echo "Hello from servers updater"

if [ -z "$SERVERS" ]; then
show_help
bail "Servers list is required!"
fi

if [ ! -f "$SERVERS" ]; then
show_help
bail "${SERVERS} >> File with servers does not exist"
fi

n=1
while read line; do
# reading each line
ip=$(echo $line | cut -d " " -f 1)
user=$(echo $line | cut -d " " -f 2)
password=$(echo $line | cut -d " " -f 3)
echo "SERVER ${n}: ${ip}"

# scp init.sh to server
sshpass -p $password scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no init.sh $user@$ip:/init.sh
# run init.sh on server
sshpass -p $password ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $user@$ip "chmod +x /init.sh && /init.sh"

n=$((n+1))
done < $SERVERS