From 1125e053fb0dbaad73437ed02e435f36e766fc2b Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sun, 21 Feb 2016 01:31:19 +0100 Subject: [PATCH] lxc-alpine: allow to install additional packages Signed-off-by: Jakub Jirutka --- templates/lxc-alpine.in | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in index ef3323d6e..18feda9f2 100644 --- a/templates/lxc-alpine.in +++ b/templates/lxc-alpine.in @@ -67,7 +67,9 @@ usage() { cat <<-EOF Template specific options can be passed to lxc-create after a '--' like this: - lxc-create --name=NAME [lxc-create-options] -- [template-options] + lxc-create --name=NAME [lxc-create-options] -- [template-options] [PKG...] + + PKG Additional APK package(s) to install into the container. Template options: -a ARCH, --arch=ARCH The container architecture (e.g. x86, x86_64); defaults @@ -230,6 +232,7 @@ install() { local dest="$1" local arch="$2" local branch="$3" + local extra_packages="$4" local apk_cache="$LXC_CACHE_DIR/apk/$arch" local repo_url="$MIRROR_URL/$branch/main" @@ -244,13 +247,9 @@ install() { mkdir -p etc/apk ln -s "$apk_cache" etc/apk/cache - - $APK --update-cache --initdb --arch="$arch" \ - --root=. --keys-dir="$APK_KEYS_DIR" --repository="$repo_url" \ - add alpine-base - echo "$repo_url" > etc/apk/repositories + install_packages "$arch" alpine-base $extra_packages make_dev_nodes setup_inittab setup_hosts @@ -264,6 +263,14 @@ install() { cd - >/dev/null } +install_packages() { + local arch="$1"; shift + local packages="$@" + + $APK --arch="$arch" --root=. --keys-dir="$APK_KEYS_DIR" \ + --update-cache --initdb add $packages +} + make_dev_nodes() { mkdir -p -m 755 dev/pts mkdir -p -m 1777 dev/shm @@ -454,6 +461,8 @@ while [ $# -gt 0 ]; do esac done +extra_packages="$@" + [ "$debug" = 'yes' ] && set -x # Set global variables. @@ -482,7 +491,7 @@ fi # Here we go! run_exclusively 'bootstrap' 10 bootstrap -run_exclusively "$arch" 30 install "$rootfs" "$arch" "$release" +run_exclusively "$arch" 30 install "$rootfs" "$arch" "$release" "$extra_packages" configure_container "$path/config" "$name" "$arch" einfo "Container's rootfs and config have been created" -- 2.47.2