@@ -29,11 +29,50 @@ info() {
29
29
echo " INFO:" " $@ " >&2
30
30
}
31
31
32
+ cleanup_repos () {
33
+ # if we had installed the packages and created symlinks, remove it
34
+ if rpm -q centos-release-cloud; then
35
+ dnf remove -y centos-release-{cloud,nfv,virt}-common
36
+ find " /usr/share/distribution-gpg-keys/centos" -type l -exec rm -f {} \;
37
+ echo " Removed all symbolic links and packages installed for scos"
38
+ fi
39
+ # remove ocp.repo file
40
+ if [ -n " $ocp_manifest " ]; then
41
+ if [ -z " $output_dir " ]; then
42
+ output_dir=$( dirname " $ocp_manifest " )
43
+ fi
44
+ else
45
+ if [ -z " $output_dir " ]; then
46
+ output_dir=" $cosa_workdir /src/config"
47
+ fi
48
+ fi
49
+ rm " $output_dir /ocp.repo"
50
+ echo " Removed repo file $output_dir /ocp.repo"
51
+ }
52
+
53
+ create_gpg_keys () {
54
+ # Check if centos-stream-release is installed and centos-release-cloud is not
55
+ if rpm -q centos-stream-release && ! rpm -q centos-release-cloud; then
56
+ dnf install -y centos-release-{cloud,nfv,virt}-common
57
+ fi
58
+
59
+ # Create directory for CentOS distribution GPG keys
60
+ mkdir -p /usr/share/distribution-gpg-keys/centos
61
+ # Create symbolic links for GPG keys
62
+ if [ ! -e " /usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official" ]; then
63
+ ln -s /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial /usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-Official
64
+ ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Cloud
65
+ ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
66
+ ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-NFV
67
+ ln -s {/etc/pki/rpm-gpg,/usr/share/distribution-gpg-keys/centos}/RPM-GPG-KEY-CentOS-SIG-Virtualization
68
+ fi
69
+ }
70
+
32
71
cosa_workdir=
33
72
ocp_manifest=
34
73
output_dir=
35
74
rc=0
36
- options=$( getopt --options h --longoptions help,cosa-workdir:,ocp-layer:,output-dir: -- " $@ " ) || rc=$?
75
+ options=$( getopt --options h --longoptions help,cosa-workdir:,ocp-layer:,output-dir:,cleanup,create-gpg-keys -- " $@ " ) || rc=$?
37
76
[ $rc -eq 0 ] || print_usage_and_exit
38
77
eval set -- " $options "
39
78
while [ $# -ne 0 ]; do
@@ -42,6 +81,8 @@ while [ $# -ne 0 ]; do
42
81
--cosa-workdir) cosa_workdir=$2 ; shift ;;
43
82
--ocp-layer) ocp_manifest=$2 ; shift ;;
44
83
--output-dir) output_dir=$2 ; shift ;;
84
+ --cleanup) cleanup_repos; exit 0;;
85
+ --create-gpg-keys) create_gpg_keys; exit 0;;
45
86
--) break ;;
46
87
* ) echo " $0 : invalid argument: $1 " >&2 ; exit 1;;
47
88
esac
50
91
51
92
if [ -n " $ocp_manifest " ]; then
52
93
# --ocp-layer path
53
- rhel_version=$( source /usr/lib/os-release; echo ${VERSION_ID// ./ } )
54
- info " Got RHEL version $rhel_version from /usr/lib/os-release"
55
94
ocp_version=$( rpm-ostree compose tree --print-only " $ocp_manifest " | jq -r ' .metadata.ocp_version' )
56
95
ocp_version=${ocp_version// ./ -}
57
96
info " Got OpenShift version $ocp_version from $ocp_manifest "
@@ -61,6 +100,21 @@ if [ -n "$ocp_manifest" ]; then
61
100
if [ -z " $output_dir " ]; then
62
101
output_dir=$( dirname " $ocp_manifest " )
63
102
fi
103
+
104
+ # get rhel version corresponding to the release so we can get the
105
+ # correct OpenShift rpms from those for scos. These packages are not
106
+ # available in CentOS Stream
107
+ if [ " $osname " = scos ]; then
108
+ workdir=$( dirname " $ocp_manifest " )
109
+ manifest=" $workdir /manifest.yaml"
110
+ json=$( rpm-ostree compose tree --print-only " $manifest " )
111
+ version=$( jq -r ' .["automatic-version-prefix"]' <<< " $json" )
112
+ rhel_version=$( cut -f2 -d. <<< " $version" )
113
+ info " Got RHEL version $rhel_version from rhel manifest for scos"
114
+ else
115
+ rhel_version=$( source /usr/lib/os-release; echo ${VERSION_ID// ./ } )
116
+ info " Got RHEL version $rhel_version from /usr/lib/os-release"
117
+ fi
64
118
else
65
119
[ -n " $cosa_workdir " ]
66
120
# --cosa-workdir path
132
186
if [ " $osname " = scos ]; then
133
187
info " Neutering RHEL repos for SCOS"
134
188
awk ' /server-ose/,/^$/' " $repo_path " > " $repo_path .tmp"
189
+ # only pull in certain Openshift packages as the rest come from the c9s repo
190
+ sed -i ' /^baseurl = /a includepkgs=openshift-* ose-aws-ecr-* ose-azure-acr-* ose-gcp-gcr-*' " $repo_path .tmp"
191
+ # add the contents of the CentOS Stream repo
192
+ workdir=" $cosa_workdir /src/config"
193
+ if [ -n " $ocp_manifest " ]; then
194
+ workdir=$( dirname " $ocp_manifest " )
195
+ fi
196
+ cat " $workdir /c9s.repo" >> " $repo_path .tmp"
135
197
mv " $repo_path .tmp" " $repo_path "
198
+ create_gpg_keys
136
199
fi
137
200
138
201
cat " $repo_path "
0 commit comments