#!/usr/bin/env python3 import argparse from pathlib import Path import re import subprocess import sys import urllib.parse parser = argparse.ArgumentParser( description=""" noRMS for APT-based systems (Debian, Ubuntu, etc). Checks to see which installed packages are attached to RMS (i.e. the FSF and GNU). """ ) parser.add_argument('--verbose', '-v', help='Print more stuff', action='count', default=0) args = parser.parse_args() verbose = args.verbose PACKAGE = re.compile(r'^(?P[^/ ]+).*$') # from https://directory.fsf.org/wiki/GNU: # `new Set([].map.call(document.querySelectorAll('table tr td:nth-child(3)'), x => new URL(x.innerText).host))` GNU_DOMAINS = set([ "www.gnu.org", "puszcza.gnu.org.ua", "gcc.gnu.org", "gcompris.net", "gmplib.org", # "www.gnome.org", # the GNOME foundation signed https://rms-open-letter.github.io/ so they're OK "www.gnucash.org", "gnunet.org", "www.gnuhealth.org", "www.list.org", "www.midnight-commander.org", "mediagoblin.org", "www.multiprecision.org", "www.mpfr.org", "www.nano-editor.org", "jemarch.net", "www.r-project.org", "savannah.gnu.org", "www.texmacs.org", "unifoundry.com" ]) rms_count = 0 all_packages = subprocess.check_output(['apt', 'list', '--installed'], text=True) packages = [PACKAGE.match(line)['name'] for line in all_packages.splitlines() if line != 'Listing...'] all_info = subprocess.check_output(['apt', 'show', *packages], text=True) infos = [x for x in all_info.split('\n\n') if len(x.strip()) > 0] package_homepage_map = dict() for info in infos: lines = info.splitlines() package_lines = [line for line in lines if line.startswith('Package: ')] if len(package_lines) == 0: print('what uhhhh the fuck?') print(info) print() continue package = package_lines[0][len('Package: '):] homepage_lines = [line for line in info.splitlines() if line.startswith('Homepage: ')] if len(homepage_lines) == 0: if verbose >= 1: print(f'no webpage found for {package}, skipping') continue homepage = homepage_lines[0][len('Homepage: '):] package_homepage_map[package] = homepage for package in packages: if package not in package_homepage_map: continue webpage = package_homepage_map[package] parsed_url = urllib.parse.urlparse(webpage) host = parsed_url.netloc if verbose >= 2: print('package:', package, 'host:', host, 'webpage:', webpage) if host in GNU_DOMAINS: print(f'error: {package} is GNU software (website is {webpage})') rms_count += 1 print() print('Total RMS-affiliated packages found:', rms_count) if rms_count == 0: print('Hell yeah!') sys.exit(0) else: sys.exit(1)