-
Notifications
You must be signed in to change notification settings - Fork 6
/
rocky-offline-repo-switcher.sh
executable file
·71 lines (64 loc) · 1.65 KB
/
rocky-offline-repo-switcher.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
#!/usr/bin/bash
usage() {
echo "Options: e - Enable Offline Repos, d - Disable Offline Repos" >&2
}
while getopts "ed" o; do
case "${o}" in
e)
ENABLE_OFFLINE=true
;;
d)
DISABLE_OFFLINE=true
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
if [[ -n $ENABLE_OFFLINE && -n $DISABLE_OFFLINE ]]; then
echo "cannot use both e and d options simultaneously"
exit 1
fi
OFFLINE_REPO_FILES=$(ls -al /etc/yum.repos.d | grep .*-local.repo | awk '{print $NF}')
OFFLINE_REPOS=''
for repofile in $OFFLINE_REPO_FILES; do
OFFLINE_REPOS+=$(grep -oP '\[.*?\]' /etc/yum.repos.d/$repofile | sed 's/[][]//g')" "
done
#echo $OFFLINE_REPOS
ONLINE_REPOS=''
for repo in $OFFLINE_REPOS; do
ONLINE_REPOS+=$(echo $repo | sed 's/-local//g')" "
done
#echo $ONLINE_REPOS
if [[ -n $ENABLE_OFFLINE ]]; then
echo "Disabling Online Repos:"
echo $ONLINE_REPOS
for repo in $ONLINE_REPOS; do
dnf config-manager --set-disabled $repo
done
dnf config-manager --set-disabled ceph_stable
dnf config-manager --set-disabled ceph_stable_noarch
echo "Enabling Offline Repos:"
echo $OFFLINE_REPOS
for repo in $OFFLINE_REPOS; do
dnf config-manager --set-enabled $repo
done
elif [[ -n $DISABLE_OFFLINE ]]; then
echo "Disabling Offline Repos:"
echo $OFFLINE_REPOS
for repo in $OFFLINE_REPOS; do
dnf config-manager --set-disabled $repo
done
echo "Enabling Online Repos:"
echo $ONLINE_REPOS
for repo in $ONLINE_REPOS; do
dnf config-manager --set-enabled $repo
done
dnf config-manager --set-enabled ceph_stable
dnf config-manager --set-enabled ceph_stable_noarch
else
usage
exit 1
fi