1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/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 APK-based systems (Alpine).
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<name>\S+)-[\d\w\._]+-r\d+ \S+ \{(?P<origin>[^}]+)\} \([^)]+\) \[installed\]$')
# 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"
])
origins = dict()
all_packages = subprocess.check_output(['apk', 'list', '--installed'], text=True)
for package in all_packages.splitlines():
match = PACKAGE.match(package)
if match is None:
print('oops!', package)
name, origin = match['name'], match['origin']
if origin not in origins:
origins[origin] = []
origins[origin].append(name)
info_output = subprocess.check_output(['apk', 'info', '-wv', *origins.keys()], text=True)
package_webpage_map = dict(x.split(': ', 1) for x in info_output.splitlines())
rms_count = 0
for origin in origins:
webpage = package_webpage_map[origin]
parsed_url = urllib.parse.urlparse(webpage)
host = parsed_url.netloc
if verbose >= 1:
print('origin:', origin, 'host:', host, 'webpage:', webpage)
if host in GNU_DOMAINS:
subpackages = [x for x in origins[origin] if x != origin]
if len(subpackages) == 0:
package_text = ''
else:
package_text = ' (& ' + ', '.join(sorted(subpackages)) + ')'
print(f'error: {origin}{package_text} 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)
|