Skip to content

Instantly share code, notes, and snippets.

@ihashacks
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihashacks/8957892 to your computer and use it in GitHub Desktop.
Save ihashacks/8957892 to your computer and use it in GitHub Desktop.
switches a Linode guest to use Linode's repository mirrors
#!/bin/bash
################################################################################
# License
################################################################################
#
# Copyright (c) 2014 Brandon Pierce <brandon@ihashacks.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
# Description
################################################################################
#
# switches a Linode guest to use Linode's repository mirrors
#
PATHBKUP=/tmp
MSGBKUP="backing up original repository files to $PATHBKUP"
# test the distro and act accordingly
if lsb_release -i | grep Ubuntu > /dev/null; then
# Ubuntu
echo $MSGBKUP
cp /etc/apt/sources.list $PATHBKUP
sed -i '/^deb/s/\(us.archive\|security\).ubuntu.com/mirrors.linode.com/g' /etc/apt/sources.list
elif [ -e /etc/debian_version ]; then
# Debian
echo $MSGBKUP
cp /etc/apt/sources.list
sed -i '/^deb/s/\(\(us\|security\|cdn\).debian.\(org\|net\)\)/mirrors.linode.com/g' /etc/apt/sources.list
elif [ -e /etc/redhat-release ]; then
# CentOS
echo $MSGBKUP
cp /etc/yum/pluginconf.d/fastestmirror.conf $PATHBKUP
cp /etc/yum.repos.d/CentOS-Base.repo $PATHBKUP
sed -i '/^enabled/s/1/0/' /etc/yum/pluginconf.d/fastestmirror.conf
sed -i '/^mirrorlist/s/^/#/' /etc/yum.repos.d/CentOS-Base.repo
sed -i '/^#baseurl/s/#//' /etc/yum.repos.d/CentOS-Base.repo
sed -i '/^baseurl/s/mirror.centos.org/mirrors.linode.com/' /etc/yum.repos.d/CentOS-Base.repo
else
# something else
echo "Unable to determine distribution or unsupported distribution"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment