-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_from_factory.sh
executable file
·142 lines (120 loc) · 5.11 KB
/
sync_from_factory.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
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
set -eux
PROJECT="home:steven.hardy:testing:Cloud:OpenStack:Bobcat"
UPPER_CONSTRAINTS="https://opendev.org/openstack/requirements/raw/branch/stable/2023.2/upper-constraints.txt"
IRONIC_REQUIREMENTS="https://opendev.org/openstack/ironic/raw/branch/stable/2023.2/requirements.txt"
if [ $# != 1 ]; then
echo "Usasge: $0 <package name>"
exit 1
fi
PACKAGE=$1
# checkout out openSUSE:Factory package or update if it already exists
if [ -d "openSUSE:Factory/${PACKAGE}" ]; then
echo "openSUSE:Factory/${PACKAGE} exists"
osc -A https://api.opensuse.org update openSUSE:Factory/${PACKAGE}
else
echo "openSUSE:Factory/${PACKAGE} does not exist"
osc -A https://api.opensuse.org checkout openSUSE:Factory/${PACKAGE}
fi
NUM_SOURCES=$(grep "^Source" openSUSE:Factory/${PACKAGE}/*.spec | wc -l)
if [ ${NUM_SOURCES} -ne 1 ]; then
echo "Error only one Source file supported"
exit 1
fi
FACTORY_SOURCE=$(grep "^Source" openSUSE:Factory/${PACKAGE}/*.spec)
# checkout the target package or update if it already exists
if [ -d "${PROJECT}/${PACKAGE}" ]; then
echo "${PROJECT}/${PACKAGE} exists"
osc -A https://api.opensuse.org update ${PROJECT}/${PACKAGE}
else
echo "${PROJECT}/${PACKAGE} does not exist"
osc -A https://api.opensuse.org checkout ${PROJECT}/${PACKAGE}
fi
NUM_SOURCES=$(grep "^Source" ${PROJECT}/${PACKAGE}/*.spec | wc -l)
if [ ${NUM_SOURCES} -ne 1 ]; then
echo "Error only one Source file supported"
exit 1
fi
TARGET_SOURCE=$(grep "^Source" ${PROJECT}/${PACKAGE}/*.spec)
REQ_NAME=$(echo ${PACKAGE} | sed 's/python-//g')
echo "REQ_NAME=${REQ_NAME}"
TARGET_URL=$(echo ${TARGET_SOURCE} | awk '{print $2}')
FACTORY_URL=$(echo ${FACTORY_SOURCE} | awk '{print $2}')
TARGET_VERSION=$(basename -s '.tar.gz' ${TARGET_URL} | sed "s/^${REQ_NAME}-//")
FACTORY_VERSION=$(basename -s '.tar.gz' ${FACTORY_URL} | sed "s/^${REQ_NAME}-//")
if [ "${TARGET_URL}" != "${FACTORY_URL}" ]; then
echo "${TARGET_URL} != ${FACTORY_URL}"
echo "${TARGET_VERSION} != ${FACTORY_VERSION}"
else
echo "${TARGET_URL}" =!= "${FACTORY_URL}, nothing to do"
exit 0
fi
if [ ! -f ${PROJECT}/upper-constraints.txt ]; then
curl ${UPPER_CONSTRAINTS} -o ${PROJECT}/upper-constraints.txt
fi
if [ ! -f ${PROJECT}/ironic-requirements.txt ]; then
curl ${IRONIC_REQUIREMENTS} -o ${PROJECT}/ironic-requirements.txt
fi
# Check the factory version meets the ironic constraints
if grep ${REQ_NAME} ${PROJECT}/ironic-requirements.txt; then
IRONIC_REQ=$(grep ${REQ_NAME} ${PROJECT}/ironic-requirements.txt)
echo "IRONIC_REQ=${IRONIC_REQ}"
IFS=',' read -ra IRONIC_REQS <<< $(echo ${IRONIC_REQ} | sed "s/^${REQ_NAME}//" | sed 's/#.*$//')
for req in "${IRONIC_REQS[@]}"; do
echo "req=$req"
if [[ ${req} =~ ^'>=' ]]; then
ver=$(echo ${req} | sed 's/^>=//')
if printf '%s\n' "${FACTORY_VERSION}" "${ver}" | sort -C -V; then
echo "Version ${FACTORY_VERSION} does not satisfy requirement ${req}"
exit 1
fi
elif [[ ${req} =~ ^'!=' ]]; then
ver=$(echo ${req} | sed 's/^!=//')
if [[ ${FACTORY_VERSION} == ${ver} ]]; then
echo "Version ${FACTORY_VERSION} does not satisfy requirement ${req}"
exit 1
fi
elif [[ ${req} =~ ^'==' ]]; then
ver=$(echo ${req} | sed 's/^==//')
if [[ ${FACTORY_VERSION} != ${ver} ]]; then
echo "Version ${FACTORY_VERSION} does not satisfy requirement ${req}"
exit 1
fi
else
echo "Unexpected requirement ${req}"
exit 1
fi
done
else
echo "${REQ_NAME} not found in ${PROJECT}/ironic-requirements.txt"
fi
# Check the factory version does not exceed the upper contraint
UPPER_REQ=$(grep $REQ_NAME ${PROJECT}/upper-constraints.txt)
echo "UPPER_REQ=${UPPER_REQ}"
UPPER_VERSION=$(echo ${UPPER_REQ} | sed "s/^${REQ_NAME}===//" | sed 's/#.*$//')
echo "UPPER_VERSION=${UPPER_VERSION}"
if ! printf '%s\n' "${FACTORY_VERSION}" "${UPPER_VERSION}"; then
echo "${FACTORY_VERSION} exceeds upper constraint ${UPPER_VERSION}"
exit 1
fi
# If we got here it should be safe to update the source
FACTORY_SRC_FILE=$(basename ${FACTORY_URL})
if [ ! -f "openSUSE:Factory/${PACKAGE}/${FACTORY_SRC_FILE}" ]; then
echo "openSUSE:Factory/${PACKAGE}/${FACTORY_SRC_FILE} does not exist!"
exit 1
else
echo "copying openSUSE:Factory/${PACKAGE}/${FACTORY_SRC_FILE}"
cp openSUSE:Factory/${PACKAGE}/${FACTORY_SRC_FILE} ${PROJECT}/${PACKAGE}
osc add ${PROJECT}/${PACKAGE}/${FACTORY_SRC_FILE}
TARGET_SRC_FILE=$(basename ${TARGET_URL})
osc rm ${PROJECT}/${PACKAGE}/${TARGET_SRC_FILE}
sed -i "s;${TARGET_SOURCE};${FACTORY_SOURCE};" ${PROJECT}/${PACKAGE}/*.spec
FACTORY_SPEC_VERSION=$(grep "^Version:" openSUSE:Factory/${PACKAGE}/*.spec)
TARGET_SPEC_VERSION=$(grep "^Version:" ${PROJECT}/${PACKAGE}/*.spec)
sed -i "s;${TARGET_SPEC_VERSION};${FACTORY_SPEC_VERSION};" ${PROJECT}/${PACKAGE}/*.spec
FACTORY_SPEC_AUTOSETUP=$(grep "^%autosetup" openSUSE:Factory/${PACKAGE}/*.spec)
TARGET_SPEC_AUTOSETUP=$(grep "^%autosetup" ${PROJECT}/${PACKAGE}/*.spec)
sed -i "s;${TARGET_SPEC_AUTOSETUP};${FACTORY_SPEC_AUTOSETUP};" ${PROJECT}/${PACKAGE}/*.spec
osc diff ${PROJECT}/${PACKAGE}
echo "Done - if OK then osc ci -m \"Updated to $FACTORY_VERSION\" ${PROJECT}/${PACKAGE}"
fi