Skip to content

Instantly share code, notes, and snippets.

@wangjiezhe
Last active August 29, 2015 14:04
Show Gist options
  • Save wangjiezhe/c0541622f3da63534d00 to your computer and use it in GitHub Desktop.
Save wangjiezhe/c0541622f3da63534d00 to your computer and use it in GitHub Desktop.
a simple script to change proxy used in yum repo
#!/usr/bin/env bash
GOAGENT="proxy=http://127.0.0.1:8087"
SSLCACERT="sslcacert=/home/wangjiezhe/Downloads/googleappengine/goagent/local/CA.crt"
IPV6="proxy=http://pkuproxy.acg.gd:1898"
YUM_PATH="/etc/yum.repos.d"
error() {
echo "Usage: $(basename "$0") goagent|ipv6|none"
exit 1
}
if [ $# -ne 1 ]
then
error
fi
case $1 in
goagent)
for file in $YUM_PATH/*
do
sed -i -e "/proxy/s@\(.*\)\($GOAGENT\)\(.*\)@\2@" "$file"
sed -i -e "s@\(.*\)\($SSLCACERT\)\(.*\)@\2@" "$file"
sed -i -e "/proxy/s@\(.*\)\($IPV6\)\(.*\)@# \2@" "$file"
done
;;
ipv6)
for file in $YUM_PATH/*
do
sed -i -e "/proxy/s@\(.*\)\($GOAGENT\)\(.*\)@# \2@" "$file"
sed -i -e "s@\(.*\)\($SSLCACERT\)\(.*\)@# \2@" "$file"
sed -i -e "/proxy/s@\(.*\)\($IPV6\)\(.*\)@\2@" "$file"
done
;;
none)
for file in $YUM_PATH/*
do
sed -i -e "/proxy/s@\(.*\)\($GOAGENT\)\(.*\)@# \2@" "$file"
sed -i -e "s@\(.*\)\($SSLCACERT\)\(.*\)@# \2@" "$file"
sed -i -e "/proxy/s@\(.*\)\($IPV6\)\(.*\)@# \2@" "$file"
done
;;
dev)
for file in $YUM_PATH/russianfedora*
do
sed -i -e "/proxy/s@\(.*\)\($GOAGENT\)\(.*\)@# \2@" "$file"
sed -i -e "s@\(.*\)\($SSLCACERT\)\(.*\)@# \2@" "$file"
sed -i -e "s@^mirrorlist.*@#&@" "$file"
sed -i -e "s@\(.*\)\(baseurl=.*\)\(/releases\)\(.*\)\(/Everything\)\(.*\)@\2/development\4\6@" "$file"
done
;;
*)
error
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment