apkdroid/apkdroid.py

103 lines
2.7 KiB
Python
Raw Normal View History

2018-05-22 11:17:49 +02:00
import requests
import logging
import re
import os
import shutil
2018-05-22 11:40:12 +02:00
import webdav.client as wc
davoptions = {
'webdav_hostname': "https://fdroid.lsd.cat",
'webdav_login': "login",
'webdav_password': "password"
}
2018-05-22 11:17:49 +02:00
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')
2018-05-22 11:40:12 +02:00
def publish(repo, davoptions):
client = wc.Client(davoptions)
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for file in files:
client.upload_sync(remote_path="/" + file, local_path=file)
def main():
check_env(repo)
for url in urls:
get_apk(url)
build(repo)
publish(repo, davoptions)
2018-05-22 11:17:49 +02:00
2018-05-22 11:40:12 +02:00
main()