Last active
July 11, 2024 08:16
-
-
Save leiless/a4f89b6c887033aa454385781bef11eb to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use autodie; | |
my $mirrors = 'https://mirrors.tuna.tsinghua.edu.cn/centos-stream'; | |
if (@ARGV < 1) { | |
die "Usage: $0 <filename1> <filename2> ...\n"; | |
} | |
while (my $filename = shift @ARGV) { | |
my $backup_filename = $filename . '.bak'; | |
rename $filename, $backup_filename; | |
open my $input, "<", $backup_filename; | |
open my $output, ">", $filename; | |
while (<$input>) { | |
s/^metalink/# metalink/; | |
if (m/^name/) { | |
my (undef, $repo, $arch) = split /-/; | |
$repo =~ s/^\s+|\s+$//g; | |
($arch = defined $arch ? lc($arch) : '') =~ s/^\s+|\s+$//g; | |
if ($repo =~ /^Extras/) { | |
$_ .= "baseurl=${mirrors}/SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common\n"; | |
} else { | |
$_ .= "baseurl=${mirrors}/\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os") . "\n"; | |
} | |
} | |
print $output $_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://mirrors.tuna.tsinghua.edu.cn/help/centos-stream/