core: 支持不输入版本号

This commit is contained in:
bin456789 2023-09-10 22:23:04 +08:00
parent 2385a43844
commit 7405a7f242
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 37 additions and 25 deletions

View File

@ -23,22 +23,23 @@ jobs:
- name: Run Script
shell: bash # https://github.com/actions/runner-images/issues/6668
run: |
${{ matrix.command }} centos-7
${{ matrix.command }} centos 7
${{ matrix.command }} alma-8
${{ matrix.command }} rocky-9
${{ matrix.command }} alpine-3.18
${{ matrix.command }} ubuntu-22.04
${{ matrix.command }} debian-12
${{ matrix.command }} rocky 8
${{ matrix.command }} fedora
${{ matrix.command }} ubuntu
${{ matrix.command }} debian 12
${{ matrix.command }} alpine
${{ matrix.command }} dd --img=https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.3.8.tar.xz
# 测试 cloud image
${{ matrix.command }} centos-7 --ci
${{ matrix.command }} alma-8 --ci
${{ matrix.command }} rocky-9 --ci
${{ matrix.command }} centos --ci
${{ matrix.command }} alma --ci
${{ matrix.command }} rocky --ci
${{ matrix.command }} fedora-38 --ci
${{ matrix.command }} ubuntu-22.04 --ci
${{ matrix.command }} debian-12 --ci
${{ matrix.command }} opensuse-15.5
${{ matrix.command }} ubuntu 22.04 --ci
${{ matrix.command }} debian --ci
${{ matrix.command }} opensuse
${{ matrix.command }} arch
# 测试失败例子

View File

@ -477,23 +477,34 @@ is_distro_like_redhat() {
# 检查是否为正确的系统名
verify_os_string() {
for os in \
'centos-7|8|9' \
'alma-8|9' \
'rocky-8|9' \
'fedora-37|38' \
'ubuntu-20.04|22.04' \
'alpine-3.16|3.17|3.18' \
'debian-10|11|12' \
'opensuse-15|15.4|15.5|tumbleweed' \
'arch-' \
'windows-' \
'dd-'; do
ds=$(echo $os | cut -d- -f1)
vers=$(echo $os | cut -d- -f2 | sed 's \. \\\. g')
finalos=$(echo "$@" | tr '[:upper:]' '[:lower:]' | sed -n -E "s,^($ds)[ :-]?($vers)$,\1:\2,p")
'centos 7|8|9' \
'alma 8|9' \
'rocky 8|9' \
'fedora 37|38' \
'debian 10|11|12' \
'ubuntu 20.04|22.04' \
'alpine 3.16|3.17|3.18' \
'opensuse 15|15.4|15.5|tumbleweed' \
'arch' \
'windows' \
'dd'; do
ds=$(awk '{print $1}' <<<"$os")
vers=$(awk '{print $2}' <<<"$os" | sed 's \. \\\. g')
finalos=$(echo "$@" | tr '[:upper:]' '[:lower:]' | sed -n -E "s,^($ds)[ :-]?(|$vers)$,\1:\2,p")
if [ -n "$finalos" ]; then
distro=$(echo $finalos | cut -d: -f1)
releasever=$(echo $finalos | cut -d: -f2)
if [ -z "$releasever" ]; then
# 默认版本号
if grep -q '|' <<<$os; then
if [ "$distro" = opensuse ]; then
field='NF-1'
else
field='NF'
fi
releasever=$(awk '{print $2}' <<<$os | awk -F'|' "{print \$($field)}")
fi
fi
return
fi
done