Quantcast
Channel: Programming – Gea-Suan Lin's BLOG
Viewing all articles
Browse latest Browse all 137

把 APT 的 Legacy Format 轉成 DEB822

$
0
0

機器升級到 Ubuntu 24.04 後,/etc/apt 下面的預設格式都變成 DEB822 格式了,看起來在「[Spec] APT deb822 sources by default」這邊有討論。

舊有的格式還是會吃,但總是想翻掉,我依照我有遇到的 case (但不是所有 legacy format 的 case) 用 AWK 一行轉完:

gawk '{if ($1 ~ /^deb/) {printf("Enabled: yes\nTypes: %s\nURIs: %s\nSuites: %s\nComponents: %s\n%s", $1, $(NF-2), $(NF-1), $NF, signedby); if (match($0, /arch=([^ \]]*)/, a)) printf("Architectures: %s\n", a[1]); if (match($0, /signed-by=([^ \]]*)/, a)) printf("Signed-by: %s\n", a[1])}}'

這邊是 stdin 輸入 & stdout 輸出的設計,可以前面加上 cat ooxx.list,後面加上 sudo tee ooxx.sources 的用法。

要注意這邊無法使用 Ubuntu 系統內的 AWK,因為 mawkmatch() 不支援透過第三個參數把 group 的內容存到 array,你需要用 GNU Awk 才支援這個用法。

寫到這邊才想到,這邊好像可以考慮用 Perl 或是 Python?因為大多數升級上去的系統都有內建,之後找時間來寫好了...


Viewing all articles
Browse latest Browse all 137