Skip to content

Commit

Permalink
dumpyara: rebrand for personal usage [skip ci]
Browse files Browse the repository at this point in the history
* Setup a python bot with venv
* Setup a github workflow

Change-Id: I746c928ccd13e80b44175448a731ba4905328afc
  • Loading branch information
Jiovanni-bot committed Jun 16, 2023
1 parent 3754745 commit df6271f
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dump.yml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,10 +16,8 @@

bash dumpyara.sh "<OTAlink> OR <OTA file path>" 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)
34 changes: 34 additions & 0 deletions dumpyara.service
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions dumpyara.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
83 changes: 83 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit df6271f

Please sign in to comment.