-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathyum2aliyun.sh
131 lines (121 loc) · 3.28 KB
/
yum2aliyun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# author : Alliot
# date : 2019-7-8
# blog : www.iots.vip
green='\e[1;32m' # green
red='\e[1;31m' # red
blue='\e[1;34m' # blue
nc='\e[0m' # normal
# clean the screen
clear
# Backup the old YUM Repos
backup () {
echo -e "[${blue}Backuping the old YUM Repos...${nc}]"
sleep 0.5
# rename the old Repos file name to *.back
cd /etc/yum.repos.d
rename .repo .back *.repo
if [ $? == 0 ] ; then
echo -e "[${green}Backup success${nc}]"
else
echo -e "[${red}Backup failed,no such files${nc}]"
exit 1
fi
}
# Replace the YUM Repos with Aliyun YUM Repos
replace(){
echo -e "[${blue}Replaceing the YUM Repos with Aliyun YUM Repos...${nc}]"
sleep 0.5
wget -O /etc/yum.repos.d/Centos-Base.repo $1
if [ $? == 0 ] ; then
echo -e "[${green}Replace success${nc}]"
else
echo -e "[${red}Replace failed${nc}]"
exit 1
fi
}
# Return the systemVersion
systemVersion(){
v=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
if [ $v -eq 5 ]; then
return 5
fi
if [ $v -eq 6 ]; then
return 6
fi
if [ $v -eq 7 ]; then
return 7
fi
}
# judge runing user
if [ $UID -ne 0 ];then
echo -e "[${red}please runing this script by root user${nc}"
exit 1
fi
cat << EOF
================================================================================
This script will automatically replace the yum source to the Aliyun yum source.
author : Alliot
date : 2019-7-8
blog : www.iots.vip
USER: $USER
HOST: $HOSTNAME
KERNEL: `uname -r`
DISK :`ls /dev/sd?`
================================================================================
EOF
read -t 30 -p "Do you want to continue? (input 'yes' or 'no')" start
if [ $start == yes ];then
systemVersion
case $? in
5)
backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
replace http://mirrors.aliyun.com/repo/Centos-5.repo
sed -i 's/$releasever/5/g' /etc/yum.repos.d/Centos-Base.repo
rpm --import http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-5
result=$?
if [ $result == 0 ] ; then
echo -e "[${green}Success for CentOS/RedHat-5${nc}]"
else
echo -e "[${red}Failed for CentOS/RedHat-5${nc}]"
exit 1
fi
;;
6)
backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
replace http://mirrors.aliyun.com/repo/Centos-6.repo
sed -i 's/$releasever/6/g' /etc/yum.repos.d/Centos-Base.repo
rpm --import http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
result=$?
if [ $result == 0 ] ; then
echo -e "[${green}Success for CentOS/RedHat-6${nc}]"
else
echo -e "[${red}Failed for CentOS/RedHat-6${nc}]"
exit 1
fi
;;
7)
backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
replace http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i 's/$releasever/7/g' /etc/yum.repos.d/Centos-Base.repo
rpm --import http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
result=$?
if [ $result == 0 ] ; then
echo -e "[${green}Success for CentOS/RedHat-7${nc}]"
else
echo -e "[${red}Failed for CentOS/RedHat-7${nc}]"
exit 1
fi
;;
esac
yum clean all
yum makecache
echo -e "[${green}All done.Bye!${nc}]"
elif [ $start == "no" ];then
echo "Installation cancelled"
else
echo "your input was wrong!"
fi