#!/bin/bash
#***************************************************************#
# ScriptName: grade01.sh
# Author: xhy
# Create Date: 2025-07-01 20:58
# Modify Author: xhy
# Modify Date: 2025-07-02 11:52
# Version: v1
#***************************************************************#
# 初始化总分
total_score=0

mount -a

# a: 检查20G磁盘 (3分)
if lsblk | grep -q "20G" && vgs vgdata &>/dev/null; then
    echo "a: 正确 (3分)"
    total_score=$((total_score + 3))
else
    echo "a: 未找到20G磁盘或VG创建失败!"
fi

# b: 检查vg卷组 (3分)
if vgs vgdata &>/dev/null; then
    echo "b: 正确 (3分)"
    total_score=$((total_score + 3))
else
    echo "b: vgdata卷组不存在!"
fi

# c: 检查lv逻辑卷 (3分)
if lvs vgdata/lvmysql &>/dev/null && lvs vgdata/lvhttp &>/dev/null; then
    mysql_size=$(lvs vgdata/lvmysql -o lv_size --units g --noheadings | sed 's/g//' | awk '{print int($1)}')
    http_size=$(lvs vgdata/lvhttp -o lv_size --units g --noheadings | sed 's/g//' | awk '{print int($1)}')
    
    if [[ $mysql_size -eq 8 && $http_size -eq 2 ]]; then
        echo "c: 正确 (3分)"
        total_score=$((total_score + 3))
    else
        echo "c: 逻辑卷大小不符 (MySQL:${mysql_size}G HTTP:${http_size}G)"
    fi
else
    echo "c: 逻辑卷不存在!"
fi

# d: 检查挂载点 (5分)
if findmnt /datamysql | grep -q xfs && findmnt /datahttp | grep -q xfs; then
    echo "d: 正确 (5分)"
    total_score=$((total_score + 5))
else
    echo "d: 挂载点或文件系统错误!"
fi

# e: 检查UUID挂载 (3分)
if grep -q "UUID.*/datamysql" /etc/fstab && grep -q "UUID.*/datahttp" /etc/fstab; then
    echo "e: 正确 (3分)"
    total_score=$((total_score + 3))
else
    echo "e: /etc/fstab中缺少UUID配置!"
fi

# f: 检查NFS服务 (6分)
if systemctl is-active nfs &>/dev/null && 
   grep -q "/datamysql" /etc/exports && 
   grep -q "/datahttp" /etc/exports; then
    echo "f: 正确 (6分)"
    total_score=$((total_score + 6))
else
    echo "f: NFS服务未启用或配置错误!"
fi

# g: 检查防火墙规则 (5分)
if firewall-cmd --list-services | grep -q nfs && 
   firewall-cmd --list-services | grep -q rpc-bind; then
    echo "g: 正确 (5分)"
    total_score=$((total_score + 5))
else
    echo "g: 防火墙规则缺失"
fi

# h: 检查NFS访问控制 (5分)
if grep -q "172.24.8.0/24" /etc/exports; then
    echo "h: 正确 (5分)"
    total_score=$((total_score + 5))
else
    echo "h: 访问控制网段未配置!"
fi

# 输出总分
echo -e "\n第一题得分/总分: $total_score/33分\n\n"
