#!/bin/bash
# /etc/os-release 파일에서 정보를 가져옵니다.
if [[ -f /etc/os-release ]]; then
os_name=$(grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"')
os_version=$(grep '^VERSION_ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"')
# /etc/redhat-release 파일이 있을 경우 처리
elif [[ -f /etc/redhat-release ]]; then
os_info=$(cat /etc/redhat-release)
case "$os_info" in
*Rocky*)
os_name="rocky"
os_version=$(echo "$os_info" | grep -o '[0-9]*' | head -1)
;;
*CentOS*)
os_name="centos"
os_version=$(echo "$os_info" | grep -o '[0-9]*' | head -1)
;;
*Red\ Hat*)
os_name="redhat"
os_version=$(echo "$os_info" | grep -o '[0-9]*' | head -1)
;;
*)
os_name="unknown"
os_version="unknown"
;;
esac
else
os_name="unknown"
os_version="unknown"
fi
# 메이저 버전 추출 (주 버전만 남김)
major_version=$(echo "$os_version" | cut -d. -f1)
# 결과 출력
echo "OS: $os_name"
echo "메이저 버전: $major_version"