h-sendai / daqmw-rpm

0 stars 0 forks source link

lsb_release -aを使うのをやめる #4

Open h-sendai opened 2 years ago

h-sendai commented 2 years ago

シェルスクリプト daqmw-rpm でもlsb_releaseコマンドをつかっているので https://github.com/h-sendai/DAQ-Middleware/issues/21 と同様にCS 9以降で問題になりそうだ。

h-sendai commented 2 years ago
#!/bin/sh

if [ -f /etc/os-release ]; then
    :
else
    echo "This script requires /etc/os-release file to find which OS you are using"
    echo "Please install following pacakge:"
    echo "RHEL 8: redhat-release"
    echo "Scientific Linux 7: sl-release"
    echo "CentOS Stream 8/9: centos-stream-release"
    exit 1
fi

os_name=$(grep '^ID=' /etc/os-release | awk -F'=' '{print $2}' | sed -e 's/"//g')
os_major_version=$(grep '^VERSION_ID=' /etc/os-release | awk -F'=' '{print $2}' | sed -e 's/"//g' | sed -e 's/\..*//')
el_name="el$os_major_version"

echo os_name: $os_name
echo os_major_version: $os_major_version
echo el_name: $el_name

RHEL 8はVERSION_IDに8.5のようにマイナーリリース番号も入っている。

上のスクリプトを走らせた結果

Scientific Linux 7

os_name: scientific
os_major_version: 7
el_name: el7

CentOS 7

os_name: centos
os_major_version: 7
el_name: el7

CentOS Stream 8

os_name: centos
os_major_version: 8
el_name: el8

CentOS Stream 9

os_name: centos
os_major_version: 9
el_name: el9

RHEL 8

os_name: rhel
os_major_version: 8
el_name: el8