Skip to content

Instantly share code, notes, and snippets.

@lesstif
Last active December 7, 2023 15:25
Show Gist options
  • Select an option

  • Save lesstif/80101df2e23a57825f141a279c39f59d to your computer and use it in GitHub Desktop.

Select an option

Save lesstif/80101df2e23a57825f141a279c39f59d to your computer and use it in GitHub Desktop.

Revisions

  1. lesstif revised this gist Jun 23, 2021. No changes.
  2. lesstif revised this gist Jun 23, 2021. 1 changed file with 57 additions and 1 deletion.
    58 changes: 57 additions & 1 deletion change-centos-mirror.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1 +1,57 @@
    #!/bin/bash
    #!/usr/bin/env bash

    BASE_REPOS=/etc/yum.repos.d/CentOS-Linux-BaseOS.repo
    PARAM="r:hkn"

    KAKAO="mirror.kakao.com\/centos"
    NAVER="mirror.navercorp.com\/centos"

    if [ "$(id -u)" != "0" ]; then
    echo "'$0' must be run as root" 1>&2
    exit 1
    fi

    function usage {
    echo "USAGE: $0 [OPTION] ";
    echo -e "\r\n-b : make backup file";
    echo "-r[repostiroy.file] : specify yum repository file (default ${BASE_REPOS})"
    echo "-k : use kakao mirror (${KAKAO})"
    echo "-n : use naver mirror (${NAVER})"

    exit 0;
    }

    REPOS=${KAKAO}

    releasever=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f1)
    basearch=x86_64

    while getopts $PARAM opt; do
    case $opt in
    r)
    echo "-r option was supplied. OPTARG: $OPTARG" >&2
    BASE_REPOS=$OPTARG;
    ;;
    k)
    echo "Using Kakao repository(${REPOS})." >&2
    REPOS=${KAKAO}
    ;;
    n)
    echo "Using naver repository(${NAVER})." >&2
    REPOS=${NAVER}
    ;;
    h)
    usage;
    ;;
    esac
    done

    FULL_REPOS="http:\/\/${REPOS}\/${releasever}\/BaseOS\/${basearch}\/os"

    echo "using repository(${REPOS})"

    ## change mirror
    sed -i.bak -re "s/^(mirrorlist(.*))/##\1/g" -re "s/[#]*baseurl(.*)/baseurl=${FULL_REPOS}/" ${BASE_REPOS}

    ## check
    yum update
  3. lesstif created this gist Jun 23, 2021.
    1 change: 1 addition & 0 deletions change-centos-mirror.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    #!/bin/bash