1. ホーム
  2. スクリプト・コラム
  3. リナックスシェル

ローカル yum ソース設定用ワンクリック・シェル・スクリプト

2022-02-08 23:30:29

その効果は以下の通りです。

コード

#! /bin/bash
#Author:GaoHongYu
#QQ:1061767621
#Time:2019-12-26 16:30:19
#Name:yumgz.sh
#Version:V1.0
CKGZ=$( df -Th | grep -o "iso9660" )
KJGZ=$( cat /etc/fstab | grep -o "iso9660" )
read -p "Welcome to the Yum automount script, y start|n exit: " xw
    if [ $xw == y ];then
      echo "$CKGZ" &> /dev/null
    if [ "$CKGZ" == 'iso9660' ];then
      echo "Your CD was detected mounted"
    elif [ $? -ne 0 ];then
      echo "Your disc is not mounted, it will be mounted automatically next! "
      mount /dev/sr0 /media/cdrom &> /dev/null
    fi
    if [ $? -eq 0 ];then
      echo "CD was mounted successfully! "
      echo "Next the local Yum source will be configured automatically! "
      echo "Configuration in progress, please wait patiently... "
      cd /etc/yum.repos.d/
      mkdir bak &> /dev/null
      mv C* bak &> /dev/null
      rm -rf /etc/yum.repos.d/local.repo
      echo "[local]" > /etc/yum.repos.d/local.repo
      echo "name=local" >> /etc/yum.repos.d/local.repo
      echo "baseurl=file:///media/cdrom" >> /etc/yum.repos.d/local.repo
      echo "gpgcheck=0" >> /etc/yum.repos.d/local.repo
      echo "enabled=1" >> /etc/yum.repos.d/local.repo
      yum -y clean all &> /dev/null
      yum makecache &> /dev/null
    fi
      echo "$KJGZ" &> /dev/null
    if [ "$KJGZ" == 'iso9660' ];then
      echo "You have set the CD-ROM boot mount, no need to repeat the setting"
    else
      echo "We are setting up automatic boot mount for you! "
      echo "/dev/sr0 /media/cdrom iso9660 defaults 0 0" >> /etc/fstab
      echo "The boot automount has been configured for you! "
      echo "Congratulations, the local Yum source has been successfully configured for you! "
    fi
    elif [ "$xw" == 'n' ];then
      echo "Exit the program successfully! "
      exit 0
fi

以上、ワンクリックでローカルのyumソースを設定するシェルスクリプトの詳細でした。ローカルyumソースのシェル設定について詳しくは、スクリプトハウスの他の関連記事も参考にしてみてください