forked from skonfig/base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request skonfig#16 from sideeffect42/feature/type/__getssl
__getssl: new types
- Loading branch information
Showing
26 changed files
with
1,052 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh -e | ||
# | ||
# 2021 Dennis Camera (skonfig at dtnr.ch) | ||
# | ||
# This file is part of skonfig-extra. | ||
# | ||
# skonfig-extra is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# skonfig-extra is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with skonfig-extra. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# Prints the "active" getssl.cfg values | ||
|
||
CONF_DIR=/etc/getssl | ||
|
||
test -e "${CONF_DIR:?}/getssl.cfg" || exit 0 | ||
|
||
sed -e 's/^[ \t]*\(.*\)[ \t]*$/\1/' -e '/^#/d' -e '/^$/d' \ | ||
"${CONF_DIR}/getssl.cfg" \ | ||
| sort |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import sys | ||
|
||
from functools import reduce | ||
|
||
|
||
class Cksum: | ||
__slots__ = ("_cksum", "_size") | ||
|
||
CRCTAB = ( | ||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, | ||
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, | ||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, | ||
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, | ||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, | ||
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, | ||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, | ||
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, | ||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, | ||
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, | ||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, | ||
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, | ||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, | ||
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, | ||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, | ||
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, | ||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, | ||
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, | ||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, | ||
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, | ||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, | ||
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, | ||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, | ||
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, | ||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, | ||
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, | ||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, | ||
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, | ||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, | ||
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, | ||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, | ||
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, | ||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, | ||
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, | ||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, | ||
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, | ||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, | ||
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, | ||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, | ||
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, | ||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, | ||
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, | ||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4) | ||
|
||
@staticmethod | ||
def __uint32(n): | ||
return n & 0xffffffff | ||
|
||
def __init__(self): | ||
self._cksum = 0 | ||
self._size = 0 | ||
|
||
def update(self, b): | ||
self._cksum = reduce( | ||
lambda s, c: self.__uint32(s<<8) ^ self.CRCTAB[(s>>24)^c], # ord(c)?? | ||
b, self._cksum) | ||
self._size += len(b) | ||
|
||
def cksum(self): | ||
s, n = self._cksum, self._size | ||
while n: | ||
s = self.__uint32(s << 8) ^ self.CRCTAB[(s >> 24) ^ (n & 0xFF)] | ||
n >>= 8 | ||
return self.__uint32(~s) | ||
|
||
def size(self): | ||
return self._size | ||
|
||
|
||
def process_fd(fd, path): | ||
c = Cksum() | ||
while True: | ||
data = fd.read(4096) | ||
if not data: | ||
break | ||
c.update(data) | ||
|
||
if path: | ||
sys.stdout.write("%d %d %s\n" % (c.cksum(), c.size(), path)) | ||
else: | ||
sys.stdout.write("%d %d\n" % (c.cksum(), c.size())) | ||
|
||
|
||
if __name__ == "__main__": | ||
for path in sys.argv[1:] or [""]: | ||
if path == "-" or not path: | ||
process_fd(sys.stdin, path) | ||
else: | ||
f = open(path, "rb") | ||
process_fd(f, path) | ||
f.close() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# vers@gitref sha256sum cksum #octets | ||
v1.0 342738cd6e31075faaf90bbfc5f4b28270a2e71ececd62011afcd4503b23b194 1298128142 43300 | ||
v1.84 efaa0258ce7b1ce98143b90222d7bcff946f63ab20f0990e4ce1af0ae55be5fe 4246272524 73968 | ||
v1.85 235edecabff3d872f8a01b6fa8e4012d59b360c4c8b0a1439f13e0582d922f45 1006972390 74270 | ||
v1.87 1e08dfe3c16ccd88b909b568f5dce1558e936fc2e0b7ada7b63aee2a4fd53b5e 1100070227 75431 | ||
v1.92 f4d497e8353092879de7f9453eea2944eff132e577d1aa6bd5b43af6d9951778 2673050928 77093 | ||
v2.00 265efa21b350996d5dc67fbee0c3c92f55e4d8dd22ed9828634964bd2d0501dd 4042445164 77620 | ||
v2.03 4e130c9406f4cf1943b7731d8d7b276009f7050147ae77f4bdb54fe614ef7fe1 1652617783 80255 | ||
v2.09 61d77e8d33915ac4026033091600628991463b55aadf367d8408efb933d4d613 2578987232 84767 | ||
v2.10 d46df3c9bdc44d3937660770fc2c289d5b5950a84ab5e72c370a8d3f2ea72afa 3235659078 85116 | ||
v2.11 207af7378c990dd7c7670bf63d451eff058627c38788bbe5bc36c9997e9a1f4b 118512755 85297 | ||
v2.12 9f17dc25b0399b86bdc8a57941e9623aa712af674e806efec75a8c96b7f8963a 76495664 85400 | ||
v2.13 bb5d57808f33d959e426d9263509969a5a7131e50451f87c7f53ae18c389e912 1987028142 85481 | ||
v2.14 9a900bd23f717c15393fae277fb3867d25f14487b337151b6cc99783dbfa4f12 3502431209 97673 | ||
v2.16 852a4fda7492014f351c506d9a245741a8f48aff9e106a78ae3fd54b262f0e7f 2440520339 99004 | ||
v2.17 ab082e306a7b4fd6b493a2a5fb757dc9aebef63ce0c67f47b502fda1bc62f5c4 2654028945 101406 | ||
v2.18 507f03e3d68827c046f87abe08c614a63428f7636ff38463e0f62b379529a779 1506669166 103325 | ||
v2.19 8856e6fe7146419c1a53da0d59b87b2c973717b0110078c7c9250aa04a306c62 762083183 103401 | ||
v2.20 545d2a818c509c8e0a40b7a2761823c82527034c91233295482f12f0be83ad90 1701777419 104006 | ||
v2.21 bbc4240f9f3dcd3dce3a69e3980a5ae49572c4d017d8ac36712c7d5c4e15404f 3796053050 106784 | ||
v2.22 7e73e54b11c131e805c6e55b05605d09c4808df37203cc946617c1dda03f83a7 4163280293 107333 | ||
v2.24 df1ffdcfa8034a422d5289c959f185638a1907d2b9eefc771196416d182b6ac9 2420335029 108669 | ||
v2.26 d04b597e97506a9145a3c5c4f24502a2f9deff601adaf2df344c49d68f218b6e 224152343 108785 | ||
v2.27 140615fca20e66a985db9e34b517cfb644713eb35e131e250a157ab55a4fd842 2343364619 109164 | ||
v2.28 61833590bcf7948f1df29c5bbf19c4ea000c81cabc9aeb82a5192ca4dc594139 1175685050 110776 | ||
[email protected] 140af06cea87f0e1932115753d029a41602886cdc8238c3c37875bd6c3855e74 3835215315 110967 | ||
v2.30 b17134a41c92c89ee645ccafcd54a1752cfdaa7e01b1ffed0c14bc6d6a4bbd42 673895873 112739 | ||
v2.31 3bd2216ca6080690151ff1a5688416cc714b4a5815a4bb4e28f8d8cead83a815 3219258588 117106 | ||
v2.32 8faf6caca9771d072b98364af6cad9eab7fdf7604eca22da4ef88da338f8caba 3856212121 118318 | ||
v2.33 a70cf78e830ef8bf8db4cb5ffebb81cd45810bcaee2b690a5a17eff5f2eb8041 2610311015 118387 | ||
v2.34 a36a7fde26c3b33239a8569fc457d964b4d5d711945d5cdedaf233cb2730b182 305285124 120733 | ||
v2.35 9e464afec7e8ad26e1972f8c3ca065562da14dbe610b7c7ae202a5e0068bd4f9 4024741063 126153 | ||
v2.36 59971ee59a0a7f2fc9c70fde3a3d28c906f3169564492cc956b9524486096917 838014400 128012 | ||
v2.37 88599f317e6e1e769167574333e10da779c951d5058d5d0abb2874ffdea345e1 3254399720 130495 | ||
v2.38 87ed46d99542459ca88f5847e5d34d36d48b2c69d4a424297e2099860f17b1ca 18736094 130524 | ||
v2.39 893588c9f1e7cc154f47cf72283ebd752f7c4c9dabc7e045a53994680236284c 634390958 132305 | ||
v2.40 05ef3388328d5e8d9a45c5ff85e44da506d8552c63ca5d250e54d863e4473878 4129772745 132428 | ||
v2.41 a3c1af7aa351f2631bedc8e1f8b60e0f54b4dc5725194e7ec7ff4749bb320108 105953090 133560 | ||
v2.42 490f71a658c9410d889953bf996f1eb4c30770c7a34c88608a65a644e63acce6 636431985 138243 | ||
v2.43 733b37ce7b72aea795d5d84bc190e23b6e3179c5d7d92bd4cc04c34cc0d407e1 1736295700 135937 | ||
v2.44 ff9e3653f193510b82e429eab3d6ddb945c19586a743c6880efe6702049e5deb 2752479244 137386 | ||
v2.45 2f1e82576aa32d8257d602a53d5738adaa10481d4367e3ef8f72feea0e745853 357935678 138012 | ||
v2.46 1d05824bed32b5b1d5bdc546b338abf1ed2a48d0c8c6f903cc15883b2412614d 2984206281 140937 | ||
v2.48 bf5186c769887384eedee3ec3bbdd1a0f2587015e681f47d850970ffffa8c984 506612158 144472 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import collections | ||
import hashlib | ||
import json | ||
import re | ||
import sys | ||
import urllib.request | ||
|
||
from cksum import Cksum | ||
|
||
GITHUB_REPO = "https://github.com/srvrco/getssl" | ||
|
||
class CksumLine(collections.namedtuple("CksumLine", ( | ||
"id", "sha256", "cksum"))): | ||
__slots__ = () | ||
|
||
@classmethod | ||
def from_line(cls, line): | ||
cols = line.rstrip("\r\n").split("\t") | ||
return cls(*cols) | ||
|
||
def to_line(self): | ||
return "\t".join(getattr(self, k, "") or "" for k in self._fields) | ||
|
||
@property | ||
def version(self): | ||
if "@" in self.id: | ||
return self.id[:self.id.find("@")] | ||
else: | ||
return self.id | ||
|
||
@property | ||
def gitref(self): | ||
return self.id[self.id.find("@")+1:] | ||
|
||
|
||
def extract_github_repo_path(repo_url): | ||
return re.sub(r"^.*github\.com", "", repo_url, flags=re.ASCII) | ||
|
||
|
||
def fetch_github_releases(repo_url): | ||
repo_path = extract_github_repo_path(repo_url) | ||
releases_url = "https://api.github.com/repos%s/releases" % (repo_path) | ||
page = 0 | ||
releases = [] | ||
while True: | ||
page += 1 | ||
with urllib.request.urlopen(urllib.request.Request( | ||
"%s?per_page=10&page=%u" % (releases_url, page), | ||
headers={ | ||
"Accept": "application/vnd.github.v3+json", | ||
})) as resp: | ||
rlist = json.loads(resp.read().decode()) | ||
if not rlist: | ||
break | ||
releases += rlist | ||
return releases | ||
|
||
|
||
def github_file_url(repo_url, ref, path): | ||
return "https://raw.githubusercontent.com%s/%s%s" % ( | ||
extract_github_repo_path(repo_url), ref, path) | ||
|
||
|
||
def perform_hash(algo, contents): | ||
if algo == "cksum": | ||
c = Cksum() | ||
c.update(contents) | ||
return "%d %u" % (c.cksum(), c.size()) | ||
else: | ||
return getattr(hashlib, algo)(contents).hexdigest() | ||
|
||
|
||
def checksum_url(url): | ||
with urllib.request.urlopen(url) as f: | ||
contents = f.read() | ||
return { | ||
algo: perform_hash(algo, contents) | ||
for algo in ("sha256", "cksum") | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
with open(sys.argv[1], "r+") as f: | ||
cksums = {} | ||
for line in filter(lambda l: l and not re.match(r"^#", l), f): | ||
cksum = CksumLine.from_line(line) | ||
if cksum.version in cksums: | ||
raise RuntimeError( | ||
"Duplicate version in cksums.txt: %s" % (cksum.version)) | ||
cksums[cksum.version] = cksum | ||
|
||
if len(sys.argv) > 2: | ||
# manual entry | ||
if "@" in sys.argv[2]: | ||
# it's a commit | ||
releases = [sys.argv[2].split("@", 1)] | ||
else: | ||
# it's a tag | ||
releases = [(sys.argv[2], sys.argv[2])] | ||
else: | ||
# automatically insert all found releases | ||
releases = [ | ||
(r["tag_name"], r["tag_name"]) | ||
for r in sorted( | ||
fetch_github_releases(GITHUB_REPO), | ||
key=lambda r: r["published_at"])] | ||
|
||
for (version, gitref) in releases: | ||
if version in cksums: | ||
continue | ||
|
||
getssl_bin_url = github_file_url(GITHUB_REPO, gitref, "/getssl") | ||
checksums = checksum_url(getssl_bin_url) | ||
|
||
if version != gitref: | ||
version_id = version + "@" + gitref | ||
else: | ||
version_id = version | ||
|
||
cksum = CksumLine(version_id, **checksums) | ||
|
||
# Append cksum to file | ||
f.write(cksum.to_line() + "\n") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# FIXME: This script does not handle multi-line options, e.g. bash arrays. | ||
|
||
BEGIN { | ||
FS = RS | ||
|
||
# Store the should state read from stdin in should array | ||
while (("cat" | getline should_line)) { | ||
k = substr(should_line, 1, index(should_line, "=") - 1) | ||
v = substr(should_line, length(k) + 2) | ||
|
||
if (k !~ /^[A-Z_]+$/) { | ||
printf "Suspicious key: %s\n", k | "cat >&2" | ||
suspicious_keys = 1 | ||
} | ||
|
||
should[k] = v | ||
} | ||
close("cat") | ||
if (suspicious_keys) exit (e=1) | ||
} | ||
|
||
{ | ||
line = $0 | ||
sub(/^[ \t]*/, "", line) | ||
|
||
is_comment = (line ~ /^#/) | ||
|
||
if (is_comment) { | ||
# keep comments | ||
sub(/^#*[ \t]*/, "", line) | ||
} | ||
} | ||
|
||
line { | ||
key = substr(line, 1, index(line, "=") - 1) | ||
value = substr(line, length(key) + 2) | ||
|
||
if ((key in should)) { | ||
# update option | ||
if (should[key] != value || is_comment) { | ||
printf "%s=%s\n", key, should[key] | ||
} else { | ||
print # keep line | ||
} | ||
delete should[key] | ||
next | ||
} else { | ||
# drop option | ||
next | ||
} | ||
} | ||
|
||
# Do not print comments, they have already been printed above | ||
!is_comment { print } | ||
|
||
END { | ||
if (!e) { | ||
for (key in should) { | ||
printf "%s=%s\n", key, should[key] | ||
} | ||
} | ||
} |
Oops, something went wrong.