蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行离线 Debian 脚本核对 64 位架构、主机名规范、分区表挂载点与 ISO 清单

BASH本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。explore-install.sh
explore-install.sh83 行
#!/usr/bin/env bash
set -euo pipefail

WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT

VERSION="Debian bookworm-slim GNU bash ${BASH_VERSION%%(*} (--network none)"

# Case 1: system_arch_and_hostname_format
bits=$(getconf LONG_BIT)
sample_host="alex.chen"
host_valid=false
if [[ "$sample_host" =~ ^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+$ ]]; then
  host_valid=true
fi
etc_hostname_exists=false
[ -f /etc/hostname ] && etc_hostname_exists=true
c1_actual="{\"arch_bits\":${bits},\"hostname_pattern_ok\":${host_valid},\"etc_hostname_exists\":${etc_hostname_exists}}"
c1_expected='{"arch_bits":64,"hostname_pattern_ok":true,"etc_hostname_exists":true}'
c1_passed=$([ "$c1_actual" = "$c1_expected" ] && echo true || echo false)

# Case 2: partition_mountpoints_and_home_check
cat <<'FSTAB' > "$WORKDIR/fstab.sample"
/dev/sda1 /boot ext4 defaults 1 2
/dev/sda2 /     ext4 defaults 1 1
/dev/sda3 /home ext4 defaults 1 2
/dev/sda4 swap  swap defaults 0 0
FSTAB
mount_count=$(wc -l < "$WORKDIR/fstab.sample" | tr -d ' ')
has_home=$(awk '$2=="/home"{print "true"}' "$WORKDIR/fstab.sample")
real_dirs_ok=false
[ -d / ] && [ -d /home ] && [ -d /boot ] && real_dirs_ok=true
c2_actual="{\"fstab_entries\":${mount_count},\"home_partition_defined\":${has_home},\"root_home_boot_exist\":${real_dirs_ok}}"
c2_expected='{"fstab_entries":4,"home_partition_defined":true,"root_home_boot_exist":true}'
c2_passed=$([ "$c2_actual" = "$c2_expected" ] && echo true || echo false)

# Case 3: iso_variant_and_locale_inventory
cat <<'ISOS' > "$WORKDIR/iso_list.txt"
CentOS-7.0-x86_64-DVD-1503-01.iso
CentOS-7.0-x86_64-NetInstall-1503-01.iso
CentOS-7.0-x86_64-Everything-1503-01.iso
CentOS-7.0-x86_64-GnomeLive-1503-01.iso
CentOS-7.0-x86_64-KdeLive-1503-01.iso
CentOS-7.0-x86_64-livecd-1503-01.iso
CentOS-7.0-x86_64-minimal-1503-01.iso
ISOS
iso_count=$(wc -l < "$WORKDIR/iso_list.txt" | tr -d ' ')
x64_count=$(grep -c 'x86_64' "$WORKDIR/iso_list.txt")
posix_locale_ok=false
locale -a 2>/dev/null | grep -qx 'POSIX' && posix_locale_ok=true
c3_actual="{\"iso_variants\":${iso_count},\"x86_64_count\":${x64_count},\"posix_locale_available\":${posix_locale_ok}}"
c3_expected='{"iso_variants":7,"x86_64_count":7,"posix_locale_available":true}'
c3_passed=$([ "$c3_actual" = "$c3_expected" ] && echo true || echo false)

cat <<EOF
{
  "version": "${VERSION}",
  "cases": [
    {
      "name": "system_arch_and_hostname_format",
      "summary": "核对 64 位架构、英文名.姓主机名格式校验及 /etc/hostname 文件存在",
      "expected": ${c1_expected},
      "actual": ${c1_actual},
      "passed": ${c1_passed}
    },
    {
      "name": "partition_mountpoints_and_home_check",
      "summary": "验证 /、/boot、/home 挂载点目录结构及含 /home 与 swap 的分区表条目",
      "expected": ${c2_expected},
      "actual": ${c2_actual},
      "passed": ${c2_passed}
    },
    {
      "name": "iso_variant_and_locale_inventory",
      "summary": "核对 7 种 64 位 CentOS ISO 变体清单及系统 POSIX 英文基准区域支持",
      "expected": ${c3_expected},
      "actual": ${c3_actual},
      "passed": ${c3_passed}
    }
  ]
}
EOF
本例需在 本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。

入口文件:projects/linux-install-lab/explore-install.sh

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-install.sh,或下载右侧课程工程包。
  2. 确认本地已准备 本地离线 Docker 容器(debian:bookworm-slim,GNU bash 5.2.15,--network none)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Linux

课程关联工程包(登记关联32章) · 含当前章节或实例 · mbskycom202612a1487.zip

下载课程关联工程包:Linux

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a1495.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习