This commit is contained in:
Maxim Slipenko 2024-01-16 17:32:13 +03:00
commit 250fe07bf0
9 changed files with 181 additions and 0 deletions

0
.env.example Normal file
View File

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

12
Dockerfile Normal file
View File

@ -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"]

5
README.md Normal file
View File

@ -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
```

View File

@ -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)

19
autorepacked/config.py Normal file
View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)