New features in mkimage-yum.sh script

Added -g and -p options for the contrib/mkimage-yum.sh script to allow generating images with the dependencies you want. I use this because I generate images where I only need "glibc" with its dependencies or "java-1.8.0-openjdk-headless" and so on. This makes sure that I don't get a lot of bogus packages from the Core group.

Possible usages now include sudo ./mkimage-yum.sh -y yum.conf -g '' -p java-1.8.0-openjdk-headless.

Also changed the "test" at the end to add --rm parameter to docker run so it doesn't leave a junk container and use bash to echo "success" in case you don't get coreutils in your dependencies tree.

Signed-off-by: Florin Asavoaie <florin.asavoaie@gmail.com>
This commit is contained in:
Florin Asavoaie 2015-12-20 14:20:30 +02:00
Родитель cc6f0df2e4
Коммит c8badcbd26
1 изменённых файлов: 28 добавлений и 7 удалений

Просмотреть файл

@ -10,8 +10,12 @@ usage() {
cat <<EOOPTS cat <<EOOPTS
$(basename $0) [OPTIONS] <name> $(basename $0) [OPTIONS] <name>
OPTIONS: OPTIONS:
-y <yumconf> The path to the yum config to install packages from. The -p "<packages>" The list of packages to install in the container.
default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora The default is blank.
-g "<groups>" The groups of packages to install in the container.
The default is "Core".
-y <yumconf> The path to the yum config to install packages from. The
default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora
EOOPTS EOOPTS
exit 1 exit 1
} }
@ -21,8 +25,9 @@ yum_config=/etc/yum.conf
if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then
yum_config=/etc/dnf/dnf.conf yum_config=/etc/dnf/dnf.conf
alias yum=dnf alias yum=dnf
fi fi
while getopts ":y:h" opt; do install_groups="Core"
while getopts ":y:p:g:h" opt; do
case $opt in case $opt in
y) y)
yum_config=$OPTARG yum_config=$OPTARG
@ -30,6 +35,12 @@ while getopts ":y:h" opt; do
h) h)
usage usage
;; ;;
p)
install_packages="$OPTARG"
;;
g)
install_groups="$OPTARG"
;;
\?) \?)
echo "Invalid option: -$OPTARG" echo "Invalid option: -$OPTARG"
usage usage
@ -65,8 +76,18 @@ if [ -d /etc/yum/vars ]; then
cp -a /etc/yum/vars "$target"/etc/yum/ cp -a /etc/yum/vars "$target"/etc/yum/
fi fi
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \ if [[ -n "$install_groups" ]];
--setopt=group_package_types=mandatory -y groupinstall Core then
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y groupinstall $install_groups
fi
if [[ -n "$install_packages" ]];
then
yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y install $install_packages
fi
yum -c "$yum_config" --installroot="$target" -y clean all yum -c "$yum_config" --installroot="$target" -y clean all
cat > "$target"/etc/sysconfig/network <<EOF cat > "$target"/etc/sysconfig/network <<EOF
@ -108,6 +129,6 @@ fi
tar --numeric-owner -c -C "$target" . | docker import - $name:$version tar --numeric-owner -c -C "$target" . | docker import - $name:$version
docker run -i -t $name:$version echo success docker run -i -t --rm $name:$version /bin/bash -c 'echo success'
rm -rf "$target" rm -rf "$target"