Skip to content

Instantly share code, notes, and snippets.

@xr09
Created January 9, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xr09/26bc2952e72a9197d1d85209f7a90598 to your computer and use it in GitHub Desktop.
Save xr09/26bc2952e72a9197d1d85209f7a90598 to your computer and use it in GitHub Desktop.
download alpine repo

generate urls

python3 alpine.py > urls

feed urls to aria2c

aria2c -d main/x86_64/ -i urls

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os.path
import tarfile
import urllib.request
import logging
BASE_URL = 'https://mirror.us.leaseweb.net/alpine/v3.5/main/x86_64/'
INDEX_FILE = 'APKINDEX.tar.gz'
INDEX_URL = BASE_URL + INDEX_FILE
REPO_PATH = 'main/x86_64'
INDEX_PATH = os.path.join(REPO_PATH, INDEX_FILE)
FORBIDDEN = "linux-firmware gcc-gnat dbg doc src.rpm abiword gnome gtk xfce\
firefox thunderbird dahdi email linux-vanilla-dev perl-dev\
ffmpeg asterisk gimp gnumeric gparted guile sound valgrind icon-theme qt4\
qt5 office vlc qt- qemu libvirt boost-dev tests xorg ntop clang-libs\
django ghostscript country wireshark rt4 phonenumbers freeswitch\
twisted graphviz pidgin xen- motif gfortran hydrogen ffmpeg xscreensaver\
mesa- mpd- ipptool teeworld vala- thunar xfdesk".split()
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('alpine.log')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
def init_repo():
os.makedirs(REPO_PATH, exist_ok=True)
if not os.path.exists(INDEX_PATH):
logger.info('Downloading %s' % INDEX_URL)
urllib.request.urlretrieve(INDEX_URL, INDEX_PATH)
else:
logger.info('index ok')
def get_packages():
index = read_index()
packages = []
name = ''
for line in index:
if line.startswith(b'P:'):
name = line.strip(b'\n').split(b':')[1]
elif line.startswith(b'V:'):
packages.append((str(name, 'UTF-8'), str(line.strip(b'\n').split(b':')[1], 'UTF-8')))
return packages
def read_index():
if os.path.exists(INDEX_PATH):
logger.info('reading file %s' % INDEX_PATH)
return read_gz_index(INDEX_PATH)
else:
logger.error('index not found')
raise Exception("Index file not found, check download process")
def read_gz_index(file_path):
with tarfile.open(file_path, 'r:gz') as gz_file:
return gz_file.extractfile('APKINDEX').readlines()
def bad_package(name):
for bad in FORBIDDEN:
if bad in name:
return True
return False
if __name__ == '__main__':
init_repo()
p = get_packages()
for i, v in p:
if not bad_package(i):
if not os.path.exists(os.path.join(REPO_PATH, "%s-%s.apk" % (i, v))):
print("%s%s-%s.apk" % (BASE_URL, i, v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment