Skip to content

Commit a95e293

Browse files
committed
rewrite path logic to be cleaner, more understandable, and shorter
1 parent 6397efd commit a95e293

File tree

1 file changed

+73
-102
lines changed

1 file changed

+73
-102
lines changed

xCAT/postscripts/ospkgs

Lines changed: 73 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fi
196196

197197

198198
argnum=$#;
199-
args=$@
199+
args="$*"
200200
keeprepo=0
201201
if [ $argnum -gt 0 ]; then
202202
if ( pmatch "$args" "*keeprepo*" ); then
@@ -247,122 +247,93 @@ array_empty os_path
247247
index=0
248248
for dir in ${array_ospkgdirs[@]}
249249
do
250-
251-
default_pkgdir="$INSTALLDIR/$OSVER/$ARCH"
252-
OSPKGDIR="$OSPKGDIR"
250+
# Strip trailing slash if it exists
251+
dir="$(echo $dir|sed 's#/$##')"
253252
if [ $mounted -eq 0 ]; then
254-
#OSPKGDIR="$OSPKGDIR"
255253
ospkgdir="${NFSSERVER}:${HTTPPORT}$dir"
256254
else
257255
ospkgdir="$dir"
258256
fi
259257

260-
# for the os base pkg dir(default_pkgdir) , there are some special cases.
261-
# (1)for rhels6, there is one repodata in the os base dir; so keep it here, and handle the other cases below
262-
# (2)for sles, we should specified the baseurl should be ./install/sles11/ppc64/1
263-
# (3)for SL5, we should append the /SL
264-
# (4)for rhels8/9, centos8/9, ol8/9, alma8/9 and rocky8/9 we should append /BaseOS and /AppStream to base directory
265-
# (5) for other os, we just keep it here.
266-
# For other pkg paths, we just keep it here.
267-
if [ $dir == $default_pkgdir ] || [ $dir == "$default_pkgdir/" ]; then
268-
if ( pmatch "$OSVER" "sle*" ); then
269-
OSPKGDIR="$OSPKGDIR/1"
270-
ospkgdir="$ospkgdir/1"
271-
elif ( pmatch "$OSVER" "SL5*" ); then
272-
OSPKGDIR="$OSPKGDIR/SL"
273-
ospkgdir="$ospkgdir/SL"
274-
fi
275-
fi
276-
if ( ! pmatch "$OSVER" "rhels[89]*" &&
277-
! pmatch "$OSVER" "centos[89]*" &&
278-
! pmatch "$OSVER" "rocky[89]*" &&
279-
! pmatch "$OSVER" "alma[89]*" &&
280-
! pmatch "$OSVER" "ol[89]*"); then
281-
# For rhels8/9, centos8/9, ol8/9, alma8/9 and rocky8 do not put $ospkgdir by itself
282-
array_set_element os_path $index $ospkgdir
283-
fi
284-
array_set_element os_path $index $ospkgdir
285-
if [ $dir == $default_pkgdir ] || [ $dir == "$default_pkgdir/" ]; then
286-
ospkgdir=$(echo $ospkgdir|sed 's/\/1$/\/2/')
258+
if [ $index -eq 0 ]; then
259+
# For the default pkg dir (first element of osimage.pkgdir), there are some special cases.
260+
# Specialized matches first, before more generalized matches
261+
# (1)for sle15*, we append the list of repos to the baseurl with /2/ as infix i.e. ./install/sles15*/$ARCH/2/
262+
# (2)for other sle*, we should specified the baseurl should be ./install/sles*/$ARCH/1
263+
# (3)for SL5, we should append the /SL
264+
# (4)for rhels8/9, centos8/9, ol8/9, alma8/9 and rocky8/9 we should append /BaseOS and /AppStream to base directory
265+
# (5) for other os, we just keep it here.
266+
# (1)for rhels6, there is one repodata in the os base dir; so keep it here, and handle the other cases below
267+
# For other pkg paths, we just keep it here.
287268
if ( pmatch "$OSVER" "sle15*" ); then
288-
if [ $ARCH == "x86_64" ]; then
289-
for arg in "Product-SLES" "Module-Desktop-Applications" "Module-Live-Patching" \
290-
"Module-Web-Scripting" "Module-Basesystem" "Module-Development-Tools" "Module-Public-Cloud" \
291-
"Product-HA" "Product-SLES_SAP" "Module-CAP-Tools" "Module-HPC" "Module-SAP-Applications" \
292-
"Product-HPC" "Product-WE" "Module-Containers" "Module-Legacy" "Module-Server-Applications" "Product-SLED"
269+
# Common repository paths
270+
for arg in "Product-SLES" "Module-Desktop-Applications" "Module-Live-Patching" \
271+
"Module-Web-Scripting" "Module-Basesystem" "Module-Development-Tools" "Module-Public-Cloud" \
272+
"Product-HA" "Product-SLES_SAP" "Module-SAP-Applications" \
273+
"Module-Containers" "Module-Legacy" "Module-Server-Applications"
274+
do
275+
array_set_element os_path $index "$ospkgdir/2/$arg"
276+
index=$(expr $index + 1)
277+
done
278+
# extra repository paths for x86_64
279+
if [ "$ARCH" == "x86_64" ]; then
280+
for arg in "Module-CAP-Tools" "Module-HPC" "Product-HPC" "Product-WE" "Product-SLED"
293281
do
294-
ospkgdir_ok="$ospkgdir/$arg"
282+
array_set_element os_path $index "$ospkgdir/2/$arg"
295283
index=$(expr $index + 1)
296-
array_set_element os_path $index $ospkgdir_ok
297-
done
298-
elif [ $ARCH == "ppc64le" ]; then
299-
for arg in "Product-SLES" "Module-Desktop-Applications" "Module-Live-Patching" \
300-
"Module-Web-Scripting" "Module-Basesystem" "Module-Development-Tools" "Module-Public-Cloud" \
301-
"Product-HA" "Product-SLES_SAP" "Module-SAP-Applications" \
302-
"Module-Containers" "Module-Legacy" "Module-Server-Applications"
303-
do
304-
ospkgdir_ok="$ospkgdir/$arg"
305-
index=$(expr $index + 1)
306-
array_set_element os_path $index $ospkgdir_ok
307284
done
308285
fi
309-
fi
310-
fi
311-
if ( pmatch "$OSVER" "rhel*" ||
312-
pmatch "$OSVER" "centos*" ||
313-
pmatch "$OSVER" "rocky*" ||
314-
pmatch "$OSVER" "alma*" ||
315-
pmatch "$OSVER" "ol*"); then
316-
#default_pkgdir="$INSTALLDIR/$OSVER/$ARCH"
317-
if [ $dir == $default_pkgdir ] || [ $dir == "$default_pkgdir/" ]; then
318-
319-
if ( pmatch "$OSVER" "rhels6*" ); then
320-
if [ $ARCH == "ppc64" ]; then
321-
ospkgdir_ok="$ospkgdir/Server"
322-
index=$(expr $index + 1)
323-
array_set_element os_path $index $ospkgdir_ok
324-
fi
325-
326-
if [ $ARCH == "x86_64" ]; then
327-
for arg in "Server" "ScalableFileSystem" "HighAvailability" "ResilientStorage" "LoadBalancer"
286+
elif ( pmatch "$OSVER" "sle*" ); then
287+
array_set_element os_path $index "$ospkgdir/1"
288+
elif ( pmatch "$OSVER" "SL5*" ); then
289+
array_set_element os_path $index "$ospkgdir/SL"
290+
elif ( pmatch "$OSVER" "rhels[89]*" ||
291+
pmatch "$OSVER" "centos[89]*" ||
292+
pmatch "$OSVER" "rocky[89]*" ||
293+
pmatch "$OSVER" "alma[89]*" ||
294+
pmatch "$OSVER" "ol[89]*"); then
295+
# For rhels8/9, ol8/9, and supported clones, repodata is in ./BaseOS, ./AppStream, not in ./
296+
for arg in "BaseOS" "AppStream"
297+
do
298+
array_set_element os_path $index "$ospkgdir/$arg"
299+
index=$(expr $index + 1)
300+
done
301+
elif ( pmatch "$OSVER" "rhels6*" ); then
302+
# for rhels6, the repodata is in ./Server, ./ScalableFileSystem, ./HighAvailability, ./ResilientStorage, ./LoadBalancer, not in ./
303+
# Common for all rhels6 ARCH
304+
array_set_element os_path $index "$ospkgdir/Server"
305+
index=$(expr $index + 1)
306+
307+
# Extras for all rhels6 x86_64
308+
if [ "$ARCH" == "x86_64" ]; then
309+
for arg in "ScalableFileSystem" "HighAvailability" "ResilientStorage" "LoadBalancer"
328310
do
329-
ospkgdir_ok="$ospkgdir/$arg"
311+
array_set_element os_path $index "$ospkgdir/$arg"
330312
index=$(expr $index + 1)
331-
array_set_element os_path $index $ospkgdir_ok
332313
done
333-
fi
334-
335-
elif ( pmatch "$OSVER" "rhels5*" ); then
336-
# for rhels5, the repodata is in ./Server, ./Cluster, ./CusterStorage, not in ./
337-
ospkgdir_ok="$ospkgdir/Server"
338-
array_set_element os_path $index $ospkgdir_ok
339-
340-
if [ $ARCH == "x86_64" ]; then
341-
for arg in "Cluster" "ClusterStorage"
342-
do
343-
ospkgdir_ok="$ospkgdir/$arg"
344-
index=$(expr $index + 1)
345-
array_set_element os_path $index $ospkgdir_ok
346-
done
347-
fi # x86_64
348-
elif ( pmatch "$OSVER" "rhels[89]*" ||
349-
pmatch "$OSVER" "centos[89]*" ||
350-
pmatch "$OSVER" "rocky[89]*" ||
351-
pmatch "$OSVER" "alma[89]*" ||
352-
pmatch "$OSVER" "ol[89]*"); then
353-
# for rhels8/9, centos8/9, ol8/9, alma8/9 and rocky8/9 the repodata is in ./BaseOS, ./AppStream, not in ./
354-
for arg in "BaseOS" "AppStream"
355-
do
356-
ospkgdir_ok="$ospkgdir/$arg"
357-
index=$(expr $index + 1)
358-
array_set_element os_path $index $ospkgdir_ok
359-
done
360-
fi # if...elif..fi
361-
fi # eq default_pkgdir
362-
fi # match rhel*
363-
364-
index=$(expr $index + 1)
314+
fi
315+
elif ( pmatch "$OSVER" "rhels5*" ); then
316+
# for rhels5, the repodata is in ./Server, ./Cluster, ./CusterStorage, not in ./
317+
array_set_element os_path $index "$ospkgdir/Server"
318+
index=$(expr $index + 1)
365319

320+
if [ "$ARCH" == "x86_64" ]; then
321+
for arg in "Cluster" "ClusterStorage"
322+
do
323+
array_set_element os_path $index "$ospkgdir/$arg"
324+
index=$(expr $index + 1)
325+
done
326+
fi # x86_64
327+
else
328+
# all the rest is the standard, i.e. "$INSTALLDIR/$OSVER/$ARCH"
329+
array_set_element os_path $index $ospkgdir
330+
index=$(expr $index + 1)
331+
fi # eq default_pkgdir
332+
else
333+
# Not the first index anymore, just attach as expected. no special processing.
334+
array_set_element os_path $index $ospkgdir
335+
index=$(expr $index + 1)
336+
fi
366337
done
367338

368339
IFS=$OIFS

0 commit comments

Comments
 (0)