From df6271fc8483cbee1c997a8d758632f318894650 Mon Sep 17 00:00:00 2001 From: Jiovanni-bot Date: Mon, 29 May 2023 11:52:26 +0200 Subject: [PATCH] dumpyara: rebrand for personal usage [skip ci] * Setup a python bot with venv * Setup a github workflow Change-Id: I746c928ccd13e80b44175448a731ba4905328afc --- .github/workflows/dump.yml | 36 +++++++++++++++++ README.md | 17 ++++---- dumpyara.service | 34 ++++++++++++++++ dumpyara.sh | 8 ++-- main.py | 83 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/dump.yml create mode 100644 dumpyara.service create mode 100755 main.py diff --git a/.github/workflows/dump.yml b/.github/workflows/dump.yml new file mode 100644 index 0000000..3a829c0 --- /dev/null +++ b/.github/workflows/dump.yml @@ -0,0 +1,36 @@ +name: Dump + +on: + push: + branches: + - master + +env: + DUMP_URL: "" # Direct url to a recovery zip + +jobs: + dump: + runs-on: ubuntu-latest + + steps: + - name: Set up Git + uses: actions/checkout@v3 + + - name: Create .githubtoken file + run: echo "${{ secrets.GIT_TOKEN }}" > .githubtoken + + - name: Create .tgtoken file + run: echo "${{ secrets.TELEGRAM_TOKEN }}" > .tgtoken + + - name: Set up environment + run: bash setup.sh + + # protobuf-compiler is required for this + #- name: Install otadump + # uses: actions-rs/install@v0.1 + # with: + # crate: otadump + # version: latest + + - name: Run dumpyara + run: bash dumpyara.sh "$DUMP_URL" diff --git a/README.md b/README.md index 103899b..8c2187e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # dumpyara -**[Telegram channel (feed)](https://t.me/android_dumps)** -**[Telegram group for dump requests](https://t.me/dumprequests)** +[![Dump](https://github.com/Jiovanni-dump/dumpyara/actions/workflows/dump.yml/badge.svg)](https://github.com/Jiovanni-dump/dumpyara/actions/workflows/dump.yml) + +**[Telegram channel (feed)](https://t.me/jiovanni_dumps)** **Script requirements**: Linux or Mac - + ***For setting up requirements***: bash setup.sh @@ -15,10 +16,8 @@ bash dumpyara.sh " OR " yourGithubToken -You can also place your github oauth token in a file called `.githubtoken` and telegram bot token in a file called `.tgtoken` in the root of this repository, if you wish it is ignored by git. -Before you start, make sure that dumpyara scripts are mapped to your own org or account, otherwise you'll only dump, not push. - -**Supported image types**: -check [here](https://github.com/AndroidDumps/Firmware_extractor/blob/master/extractor.sh#L3) +You can also place your github oauth token in a file called `.githubtoken` and telegram bot token in a file called `.tgtoken` in the root of this repository, if you wish it is ignored by git. +Before you start, make sure that dumpyara scripts are mapped to your own org or account, otherwise you'll only dump, not push. -If you're a member of AndroidDumps org, use a token with following permissions: `admin:org, public_repo` +**Supported image types**: +check [here](https://github.com/AndroidDumps/Firmware_extractor/blob/master/extractor.sh#L3) diff --git a/dumpyara.service b/dumpyara.service new file mode 100644 index 0000000..be40622 --- /dev/null +++ b/dumpyara.service @@ -0,0 +1,34 @@ +[Unit] +Description=Dumpyara service +After=multi-user.target + +[Service] +# Base settings +Type=simple +Restart=always +RestartSec=10 + +# Execution parameters +User=itsvixano +WorkingDirectory=/home/itsvixano/bot/dumpyara +ExecStart=/bin/sh -c 'source .venv/bin/activate && python3 main.py' + +# Limit damage in case something goes awry +MemoryLimit=512M +CPUQuota=200% + +# Security +PrivateTmp=true +ProtectSystem=full +NoNewPrivileges=true +ProtectControlGroups=true +ProtectKernelModules=true +ProtectKernelTunables=true +PrivateDevices=true +RestrictAddressFamilies=AF_INET AF_INET6 +RestrictNamespaces=true +RestrictRealtime=true +SystemCallArchitectures=native + +[Install] +WantedBy=multi-user.target diff --git a/dumpyara.sh b/dumpyara.sh index fe5f32b..ba48059 100755 --- a/dumpyara.sh +++ b/dumpyara.sh @@ -52,7 +52,7 @@ else [[ -e "$URL" ]] || { echo "Invalid Input" && exit 1; } fi -ORG=AndroidDumps #your GitHub org name +ORG=Jiovanni-dump #your GitHub org name FILE=$(echo ${URL##*/} | inline-detox) EXTENSION=$(echo ${URL##*.} | inline-detox) UNZIP_DIR=${FILE/.$EXTENSION/} @@ -246,10 +246,10 @@ if [[ -n $GIT_OAUTH_TOKEN ]]; then curl --silent --fail "https://raw.githubusercontent.com/$ORG/$repo/$branch/all_files.txt" 2> /dev/null && echo "Firmware already dumped!" && exit 1 git init if [[ -z "$(git config --get user.email)" ]]; then - git config user.email AndroidDumps@github.com + git config user.email giovanniricca@duck.com fi if [[ -z "$(git config --get user.name)" ]]; then - git config user.name AndroidDumps + git config user.name Jiovanni-bot fi curl -s -X POST -H "Authorization: token ${GIT_OAUTH_TOKEN}" -d '{ "name": "'"$repo"'" }' "https://api.github.com/orgs/${ORG}/repos" #create new repo curl -s -X PUT -H "Authorization: token ${GIT_OAUTH_TOKEN}" -H "Accept: application/vnd.github.mercy-preview+json" -d '{ "names": ["'"$manufacturer"'","'"$platform"'","'"$top_codename"'"]}' "https://api.github.com/repos/${ORG}/${repo}/topics" @@ -324,7 +324,7 @@ fi # Telegram channel TG_TOKEN=$(< "$PROJECT_DIR"/.tgtoken) if [[ -n "$TG_TOKEN" ]]; then - CHAT_ID="@android_dumps" + CHAT_ID="@jiovanni_dumps" commit_head=$(git log --format=format:%H | head -n 1) commit_link="https://github.com/$ORG/$repo/commit/$commit_head" echo -e "Sending telegram notification" diff --git a/main.py b/main.py new file mode 100755 index 0000000..7d836e1 --- /dev/null +++ b/main.py @@ -0,0 +1,83 @@ +#!/usr/bin/python3 + +# pip install pyTelegramBotAPI + +import os +import subprocess +import telebot +import re + +allowed_user_ids = [ + 172222663, # GiovanniRN5 + 690187343, # lostark13 + 419006851, # dereference +] + +# Read the Telegram token from the file +token_file = ".tgtoken" +with open(token_file, "r") as file: + bot_token = file.read().strip() + +bot = telebot.TeleBot(bot_token) + + +def is_valid_url(url): + regex = re.compile( + r"^(https?:\/\/)?(www\.)?([^\s.]+\.\S{2,}|localhost[\:?\d]*)\S*$" + ) + return re.match(regex, url) + + +@bot.message_handler(commands=["alive"]) +def check_alive(message): + chat_id = message.chat.id + bot.send_message(chat_id, "I'm alive and ready to go!") + + +@bot.message_handler(commands=["dump"]) +def dump(message): + chat_id = message.chat.id + user_id = message.from_user.id + file_path = ".github/workflows/dump.yml" + + if user_id not in allowed_user_ids: + bot.send_message(chat_id, "You are not authorized to use this command.") + return + + # Extract the url from the message + dump_url = ( + message.text.split(" ", 1)[1].strip() + if len(message.text.split(" ", 1)) > 1 + else "" + ) + + if not is_valid_url(dump_url): + bot.send_message(chat_id, "Invalid URL provided.") + return + + try: + with open(file_path, "r") as file: + lines = file.readlines() + + with open(file_path, "w") as file: + for line in lines: + if line.startswith(" DUMP_URL:"): + line = f' DUMP_URL: "{dump_url}" # Direct url to a recovery zip\n' + file.write(line) + + # Commit and push the changes + subprocess.run(["git", "add", "."]) + subprocess.run(["git", "commit", "-m", dump_url, "--no-gpg-sign", "--allow-empty"]) + subprocess.run(["git", "push"]) + + bot.send_message(chat_id, "Dump started successfully!") + bot.send_message( + chat_id, + "Feel free to check the dump progress [here](https://github.com/Jiovanni-dump/dumpyara/actions)", + parse_mode="Markdown", + ) + except Exception as e: + bot.send_message(chat_id, f"An error occurred: {str(e)}") + +if __name__ == '__main__': + bot.polling()