Created
April 18, 2024 18:41
-
-
Save NightFeather/6a5f6f9ccae22a251decc6243b1f5bfd to your computer and use it in GitHub Desktop.
I don't know why I made this.
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
func h2b(pair) { s="0123456789abcdef"; return index(s, tolower(substr(pair,1,1)))*16+index(s, tolower(substr(pair,2,1)))-17; } | |
func h2d_le(str) { x=0; for(i=length(str)-2;i>=0;i-=2) { x=x*256+h2b(substr(str,i+1,2)) } return x } | |
func h2d_be(str) { x=0; for(i=0;i<length(str);i+=2) { x=x*256+h2b(substr(str,i+1,2)) } return x } | |
func h2z(str) { x=""; for(i=0;i<length(str);i+=2) { v=h2b(substr(str,i+1,2)); if(v==0) { break } x=x sprintf("%c", v); }; return x} | |
func h2bs(str) { x=""; for(i=0;i<length(str);i+=2) { v=h2b(substr(str,i+1,2)); x=x sprintf("%c", v); }; return x} | |
BEGIN { | |
EXCLUDED_PACKAGES["gpg-pubkey"]=0 | |
if(!cols) { | |
cols=108 | |
} | |
half=sprintf("%d", cols/2) | |
} | |
func rpminfo(data) { | |
if(length(data) < 16) { return; } | |
hdrlen = h2d_be(substr(data,1,8))*32 # in hex nibbles | |
bdylen = h2d_be(substr(data,9,8))*2 | |
if(hdrlen+bdylen+16 > length(data)) { return; } | |
ptr=17; noff = -1; voff = -1; roff = -1; eoff = -1; aoff = -1; | |
while(ptr<hdrlen) { | |
if(noff >= 0 && voff >= 0 && roff >= 0 && eoff >= 0 && aoff >= 0) { break; } | |
tag = h2d_be(substr(data, ptr, 8)) | |
off = h2d_be(substr(data, ptr+16, 8))*2 | |
if(tag == 1000) { noff = off } | |
else if(tag == 1001) { voff = off } | |
else if(tag == 1002) { roff = off } | |
else if(tag == 1003) { eoff = off } | |
else if(tag == 1022) { aoff = off } | |
ptr += 32 | |
} | |
name = h2z(substr(data, 16+hdrlen+noff+1)) | |
version = h2z(substr(data, 16+hdrlen+voff+1)) | |
release = h2z(substr(data, 16+hdrlen+roff+1)) | |
if(name in EXCLUDED_PACKAGES) { return; } | |
if(eoff>=0){ | |
epoch = h2d_be(substr(data, 16+hdrlen+eoff+1, 8)) | |
} else { | |
epoch = 0 | |
} | |
if(aoff>=0){ | |
arch = ""h2z(substr(data, 16+hdrlen+aoff+1)) | |
} else { | |
arch = "noarch" | |
} | |
if(eoff >= 0 && epoch > 0) { | |
version=epoch":"version | |
} | |
repo = "" | |
ret = "sqlite3 /var/lib/dnf/history.sqlite\ | |
\"select r.repoid from trans_item as ti\ | |
inner join repo as r inner join rpm\ | |
on ti.repo_id = r.id and ti.item_id = rpm.item_id\ | |
where rpm.name = '"name"'\ | |
ORDER BY ti.id DESC LIMIT 1\"\ | |
" | getline repo | |
if(repo == "") { repo = "System" } | |
left = sprintf("%s.%s", name, arch) | |
mid = sprintf("%s-%s", version, release) | |
right = sprintf("@%s", repo) | |
pad1 = sprintf("%"(half-length(left))"s", "") | |
pad2 = sprintf("%"(half-length(right)-length(mid))"s", "") | |
printf "%s%s%s%s%s\n", left, pad1, mid, pad2, right | |
} | |
/HEADER=END/,/DATA=END/ { if($0 !~ /=END$/) { line=$1 } } | |
line { rpminfo(line) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment