109 lines
3.0 KiB
Python
109 lines
3.0 KiB
Python
import requests
|
|
import logging
|
|
import re
|
|
import os
|
|
import shutil
|
|
import webdav.client as wc
|
|
|
|
davoptions = {
|
|
'webdav_hostname': "https://fdroid.lsd.cat",
|
|
'webdav_login': "login",
|
|
'webdav_password': "password"
|
|
}
|
|
|
|
repo_url = "https://fdroid.lsd.cat"
|
|
repo_name = "lsd.cat Proprietary Apps Repo"
|
|
repo_icon = "fdroid-icon.png"
|
|
repo_description = """
|
|
This is a repository to install proprietary apps via fdroid
|
|
"""
|
|
|
|
repo_original_url = "https://MyFirstFDroidRepo.org/fdroid/repo"
|
|
repo_original_name = "My First F-Droid Repo Demo"
|
|
repo_original_icon = "fdroid-icon.png"
|
|
repo_original_description = """
|
|
This is a repository of apps to be used with F-Droid. Applications in this
|
|
repository are either official binaries built by the original application
|
|
developers, or are binaries built from source by the admin of f-droid.org
|
|
using the tools on https://gitlab.com/u/fdroid.
|
|
"""
|
|
|
|
keystore = None
|
|
keystorepass = None
|
|
|
|
repo = 'fdroid/'
|
|
urls = [
|
|
"https://www.whatsapp.com/android/",
|
|
"https://help.netflix.com/en/node/57688",
|
|
"https://download.spotify.com/android/SpotifyAndroid.apk",
|
|
"https://updates.signal.org/android/latest.json",
|
|
"https://wire.com/en/download/"
|
|
]
|
|
|
|
def get_apk(baseurl):
|
|
page = requests.get(baseurl)
|
|
if page.headers['content-type'] == 'application/vnd.android.package-archive':
|
|
name = baseurl.rsplit('/', 1)[-1]
|
|
logging.info('Downloading ' + name)
|
|
with open('repo/' + name, 'wb') as handle:
|
|
for block in page.iter_content(1024):
|
|
handle.write(block)
|
|
else:
|
|
url = re.findall('https\:\/\/(.*)\.apk', page.text)[0]
|
|
get_apk('https://' + url + '.apk')
|
|
|
|
def check_env(repo):
|
|
if not shutil.which('fdroid'):
|
|
logging.error('Please install fdroidserver')
|
|
sys.exit(1)
|
|
|
|
if os.path.isdir(repo) is False:
|
|
try:
|
|
os.mkdir(repo)
|
|
except:
|
|
logging.error('Cannot create repository directory')
|
|
|
|
|
|
if ('repo' or 'config.py') not in os.listdir(repo):
|
|
logging.info('Initializing a new repository')
|
|
os.chdir(repo)
|
|
os.system('fdroid init')
|
|
|
|
with open('config.py', 'r') as file :
|
|
filedata = file.read()
|
|
|
|
filedata = filedata.replace(repo_original_url, repo_url)
|
|
filedata = filedata.replace(repo_original_name, repo_name)
|
|
filedata = filedata.replace(repo_original_description, repo_description)
|
|
|
|
with open('config.py', 'w') as file:
|
|
file.write(filedata)
|
|
|
|
else:
|
|
os.chdir(repo)
|
|
logging.info('Repo already exists')
|
|
# TODO import keystore and check keys
|
|
|
|
def build(repo):
|
|
os.system('fdroid update -c')
|
|
|
|
def publish(repo, davoptions):
|
|
client = wc.Client(davoptions)
|
|
files = os.listdir('repo/')
|
|
for file in files:
|
|
if os.path.isfile(file):
|
|
client.upload_sync(remote_path="/repo/" + file, local_path="repo/" +file)
|
|
|
|
for size in ['/', '-120/', '-160/', '-240/', '-320/', '-480/', '-640/']:
|
|
files = os.listdir('repo/icons' + size)
|
|
for file in files:
|
|
client.upload_sync(remote_path="/repo/icons" + size + file, local_path="repo/icons" + size + file)
|
|
|
|
def main():
|
|
check_env(repo)
|
|
for url in urls:
|
|
get_apk(url)
|
|
build(repo)
|
|
publish(repo, davoptions)
|
|
|
|
main() |