Last active
January 6, 2017 19:09
-
-
Save Mic92/2cbb6f7f4a02be57ae4e68afcfc1066d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~aurrepo/.makepkg.conf | |
GPGKEY="<GPG_KEY_ID>" | |
PKGDEST=/var/lib/aurrepo | |
PACKAGER="name <email@address>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import fnmatch | |
import os, sys, re | |
import subprocess | |
import shlex | |
import argparse | |
try: | |
import pyalpm | |
except ImportError: | |
print("pyalpm is missing and required, install it with: pacman -S pyalpm", file=sys.stderr) | |
sys.exit(1) | |
def sh(cmd, verbose=False): | |
if verbose: | |
args = ' '.join(map(lambda s: shlex.quote(s), cmd[1:])) | |
print("$ %s %s" % (cmd[0], args)) | |
subprocess.call(cmd) | |
def force_symlink(target, link_name, verbose=False): | |
if os.path.realpath(link_name) == target: | |
return | |
if verbose: | |
print("$ ln -sf %s %s", shlex.quote(target), shlex.quote(link_name)) | |
if os.exists(link_name): | |
os.remove(link_name) | |
os.symlink(target, link_name) | |
def get_packages(db): | |
pkgs = {} | |
for pkg in db.search(""): | |
arch = "x86_64" if pkg.arch == None else pkg.arch | |
basename = "-".join([pkg.name, pkg.version, arch]) | |
pkgs[basename] = pkg | |
return pkgs | |
def open_repo_db(repo_path, repo_archive, verbose=False): | |
# create symlink $REPO_PATH/sync/repo.db -> $REPO_PATH/repo.db, | |
# to open file with register_syncdb | |
sync_db_path = os.path.join(repo_path, "sync") | |
repo_db = os.path.join(sync_db_path, "repo.db") | |
os.makedirs(sync_db_path, exist_ok=True) | |
force_symlink(repo_archive, repo_db, verbose=verbose) | |
handle = pyalpm.Handle("/", repo_path) | |
return handle.register_syncdb("repo", pyalpm.SIG_DATABASE_OPTIONAL) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--pacman-db', | |
help='pacman database directory (default: /var/lib/pacman)', | |
default="/var/lib/pacman") | |
parser.add_argument('--repo-path', | |
help='repository path (default: /var/lib/aurrepo)', | |
default="/var/lib/aurrepo") | |
parser.add_argument('--repo-archive', | |
help='repository archive path (default: /var/lib/aurrepo/aurrepo.db.tar.xz)') | |
parser.add_argument('--repo-add', | |
help='repo-add executable path (default: /usr/bin/repo-add)', | |
default="/usr/bin/repo-add") | |
parser.add_argument('--repo-remove', | |
help='repo-remove executable path (default: /usr/bin/repo-remove)', | |
default="/usr/bin/repo-remove") | |
parser.add_argument('--sign', | |
help='sign repo (default: off)', | |
action='store_true', default=False) | |
parser.add_argument('--verbose', | |
help='verbose logging (default: off)', | |
action='store_true', default=False) | |
options = parser.parse_args() | |
if options.repo_archive == None: | |
options.repo_archive = os.path.join(options.repo_path, "aurrepo.db.tar.xz") | |
h = pyalpm.Handle("/", options.pacman_db) | |
db = h.get_localdb() | |
packages = get_packages(db) | |
repo_db = open_repo_db(options.repo_path, options.repo_archive, | |
verbose=options.verbose) | |
added_packages = get_packages(repo_db) | |
new_pkgs = [] | |
obsolete_pkgs = [] | |
for file in os.listdir(options.repo_path): | |
path = os.path.join(options.repo_path, file) | |
match = re.search(r"(.*)\.pkg\.tar\..+", file) | |
if match: | |
basename = match.group(1) | |
if basename in packages: | |
if file.endswith(".sig"): | |
continue | |
if not basename in added_packages: | |
new_pkgs.append(path) | |
else: | |
if basename in added_packages: | |
obsolete_pkgs.append(added_packages[basename].name) | |
if options.verbose: | |
print("$ rm %s" % shlex.quote(path)) | |
os.unlink(path) | |
if basename in added_packages: | |
del added_packages[basename] | |
for pkg in added_packages.values(): | |
obsolete_pkgs.append(pkg.name) | |
sign = ["--sign"] if options.sign else [] | |
if len(obsolete_pkgs) > 0: | |
cmd = [options.repo_remove] + sign + ["--quiet", options.repo_archive] | |
sh(cmd + obsolete_pkgs, verbose=options.verbose) | |
if len(new_pkgs) > 0: | |
cmd = [options.repo_add] + sign + ["--quiet", options.repo_archive] | |
sh(cmd + new_pkgs, verbose=options.verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ $EUID -ne 0 ]; then | |
echo "Must be root!" >&2 | |
exit 1 | |
fi | |
cd / | |
export PATH=$PATH:/usr/local/bin CWD=/ | |
lxc-attach --name login -- sudo -u aurrepo -- aurrepo --sign --verbose | |
lxc-attach --name login -- sudo -u aurrepo -- yaourt "$@" | |
lxc-attach --name login -- sudo -u aurrepo -- aurrepo --sign --verbose | |
lxc-attach --name login -- pacman -Sy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment