commit 250fe07bf0d1b00ecbd50ae334ab5de4e2715966 Author: Maxim Slipenko Date: Tue Jan 16 17:32:13 2024 +0300 init diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..207e87f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM registry.altlinux.org/alt/python:p10 + +RUN apt-get update && apt-get install -y \ + eepm \ + wget +# && rm -rf /var/lib/apt/lists/* + +COPY ./autorepacked ./autorepacked + +ENV PYTHONPATH "${PYTHONPATH}:." + +CMD ["python3", "-u", "./autorepacked/main.py"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b27d613 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +Usage: +``` +docker build -t maks1ms/altlinux-autorepacked:p10 . +docker run -e REPO_PATH=/repo -v /www/ALTLinux/autorepacked/p10/branch:/repo maks1ms/altlinux-autorepacked:p10 +``` \ No newline at end of file diff --git a/autorepacked/base_provider.py b/autorepacked/base_provider.py new file mode 100644 index 0000000..c0a09a4 --- /dev/null +++ b/autorepacked/base_provider.py @@ -0,0 +1,91 @@ +import os +import shutil +import subprocess +import tempfile +import re + + +def _get_file(directory): + files_and_dirs = os.listdir(directory) + files = [f for f in files_and_dirs if os.path.isfile(os.path.join(directory, f))] + return os.path.join(directory, files[0]) if files else None + +class BaseProvider: + def __init__(self, config): + self.config = config + + DOWNLOAD_URL = '' + _name = '' + + def get_name(self): + return self._name + + def get_version(self): + url = subprocess.run([ + 'epm', + '--silent', + 'tool', + 'eget', + '--get-real-url', + self.get_download_url(), + ], stdout=subprocess.PIPE).stdout.decode('utf-8') + + pattern = r'\d+\.\d+\.\d+' + match = re.search(pattern, url) + if match: + return match.group() + else: + return "not found" + + def get_download_url(self): + return self.DOWNLOAD_URL + + def download(self): + download_directory = tempfile.mkdtemp() + repacked_directory = tempfile.mkdtemp() + + subprocess.run( + args=[ + 'epm', + '--silent', + 'tool', + 'eget', + '-q', + self.get_download_url(), + ], + stdout=subprocess.PIPE, + cwd=download_directory, + ).stdout.decode('utf-8') + + file = _get_file(download_directory) + + subprocess.run( + args=[ + 'epm', + '--silent', + '-y', + 'repack', + file, + ], + stdout=subprocess.PIPE, + cwd=repacked_directory, + ).stdout.decode('utf-8') + + shutil.rmtree(download_directory) + + file = _get_file(repacked_directory) + + subprocess.run( + args=[ + 'epm', + '--silent', + 'repo', + 'pkgadd', + self.config.get('repo_path'), + file, + ], + stdout=subprocess.PIPE, + cwd=repacked_directory, + ).stdout.decode('utf-8') + + shutil.rmtree(repacked_directory) \ No newline at end of file diff --git a/autorepacked/config.py b/autorepacked/config.py new file mode 100644 index 0000000..a032a02 --- /dev/null +++ b/autorepacked/config.py @@ -0,0 +1,19 @@ +import os + + +class Config: + def __init__(self): + + required_vars = [ + "REPO_PATH" + ] + + missing_vars = [var for var in required_vars if var.upper() not in os.environ] + if missing_vars: + raise ValueError(f"Missing required environment variables: {', '.join(missing_vars)}") + + for key in os.environ: + setattr(self, key.lower(), os.environ[key]) + + def get(self, key): + return getattr(self, key.lower(), None) \ No newline at end of file diff --git a/autorepacked/providers/code/__init__.py b/autorepacked/providers/code/__init__.py new file mode 100644 index 0000000..2abb9fd --- /dev/null +++ b/autorepacked/providers/code/__init__.py @@ -0,0 +1,11 @@ +from autorepacked.base_provider import BaseProvider + + +class CodeProvider(BaseProvider): + _name = 'code' + + DOWNLOAD_URL = "https://code.visualstudio.com/sha/download?build=stable&os=linux-rpm-x64" + + +def get_provider(config): + return CodeProvider(config) diff --git a/autorepacked/providers/discord/__init__.py b/autorepacked/providers/discord/__init__.py new file mode 100644 index 0000000..3485a68 --- /dev/null +++ b/autorepacked/providers/discord/__init__.py @@ -0,0 +1,11 @@ +from autorepacked.base_provider import BaseProvider + + +class DiscordProvider(BaseProvider): + _name = 'discord' + + DOWNLOAD_URL = "https://discord.com/api/download?platform=linux&format=deb" + + +def get_provider(config): + return DiscordProvider(config) diff --git a/autorepacked/providers/rustdesk/__init__.py b/autorepacked/providers/rustdesk/__init__.py new file mode 100644 index 0000000..693538d --- /dev/null +++ b/autorepacked/providers/rustdesk/__init__.py @@ -0,0 +1,31 @@ +import subprocess + +from autorepacked.base_provider import BaseProvider + + +class RustdeskProvider(BaseProvider): + _name = 'rustdesk' + _release_url = 'https://github.com/rustdesk/rustdesk/releases' + _release_file = '[0-9]/rustdesk-[0-9].[0-9].[0-9].deb' + + def get_download_url(self): + url = subprocess.run( + args=[ + 'epm', + '--silent', + 'tool', + 'eget', + '--list', + '--latest', + '--get-real-url', + self._release_url, + self._release_file, + ], + stdout=subprocess.PIPE + ).stdout.decode('utf-8') + + return url + + +def get_provider(config): + return RustdeskProvider(config)