Browse code

Merge pull request #38957 from ajatkj/mkimage-yum-update

mkimage yum update

Tianon Gravi authored on 2019/03/30 06:28:28
Showing 1 changed files
... ...
@@ -13,9 +13,9 @@ usage() {
13 13
 $(basename $0) [OPTIONS] <name>
14 14
 OPTIONS:
15 15
   -p "<packages>"  The list of packages to install in the container.
16
-                   The default is blank.
16
+                   The default is blank. Can use multiple times.
17 17
   -g "<groups>"    The groups of packages to install in the container.
18
-                   The default is "Core".
18
+                   The default is "Core". Can use multiple times.
19 19
   -y <yumconf>     The path to the yum config to install packages from. The
20 20
                    default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
21 21
   -t <tag>         Specify Tag information.
... ...
@@ -30,7 +30,9 @@ if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then
30 30
 	yum_config=/etc/dnf/dnf.conf
31 31
 	alias yum=dnf
32 32
 fi
33
-install_groups="Core"
33
+# for names with spaces, use double quotes (") as install_groups=('Core' '"Compute Node"')
34
+install_groups=()
35
+install_packages=()
34 36
 version=
35 37
 while getopts ":y:p:g:t:h" opt; do
36 38
     case $opt in
... ...
@@ -41,10 +43,10 @@ while getopts ":y:p:g:t:h" opt; do
41 41
             usage
42 42
             ;;
43 43
         p)
44
-            install_packages="$OPTARG"
44
+            install_packages+=("\"$OPTARG\"")
45 45
             ;;
46 46
         g)
47
-            install_groups="$OPTARG"
47
+            install_groups+=("\"$OPTARG\"")
48 48
             ;;
49 49
         t)
50 50
             version="$OPTARG"
... ...
@@ -62,6 +64,11 @@ if [[ -z $name ]]; then
62 62
     usage
63 63
 fi
64 64
 
65
+# default to Core group if not specified otherwise
66
+if [ ${#install_groups[*]} -eq 0 ]; then
67
+   install_groups=('Core')
68
+fi
69
+
65 70
 target=$(mktemp -d --tmpdir $(basename $0).XXXXXX)
66 71
 
67 72
 set -x
... ...
@@ -87,13 +94,13 @@ fi
87 87
 if [[ -n "$install_groups" ]];
88 88
 then
89 89
     yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
90
-        --setopt=group_package_types=mandatory -y groupinstall "$install_groups"
90
+        --setopt=group_package_types=mandatory -y groupinstall "${install_groups[*]}"
91 91
 fi
92 92
 
93 93
 if [[ -n "$install_packages" ]];
94 94
 then
95 95
     yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
96
-        --setopt=group_package_types=mandatory -y install "$install_packages"
96
+        --setopt=group_package_types=mandatory -y install "${install_packages[*]}"
97 97
 fi
98 98
 
99 99
 yum -c "$yum_config" --installroot="$target" -y clean all