on master help sign in
utils/lxc.sh install: support installation on selected containers

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit3c19f2f1cef31fd512975c70a25442d078992a42 authorMarkus Heiser <markus.heiser@darmarit.de> dateSat 4 Apr 2020, 12:40 (7 years ago) parent84daf99
2 files changed+22−17
utils/lxc-searx.env+3−1 utils/lxc.sh+19−16
utils/lxc-searx.env+3−1
@@ -10,10 +10,12 @@
1010# config
1111# ----------------------------------------------------------------------------
1212
13+# shellcheck disable=SC2034
14+LXC_SUITE_NAME="searx"
1315lxc_set_suite_env() {
1416 # name of https://images.linuxcontainers.org
1517 export LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
16− export LXC_HOST_PREFIX="${LXC_HOST_PREFIX:-searx}"
18+ export LXC_HOST_PREFIX="${LXC_SUITE_NAME:-searx}"
1719 export LXC_SUITE=(
1820
1921 # to disable containers, comment out lines ..
utils/lxc.sh+19−16
@@ -82,7 +82,7 @@ usage::
8282 $_cmd [start|stop] [containers|<name>]
8383 $_cmd show [images|suite|info|config [<name>]]
8484 $_cmd cmd [--|<name>] '...'
85− $_cmd install [suite|base]
85+ $_cmd install [suite|base [<name>]]
8686
8787build
8888 :containers: build, launch all containers and 'install base' packages
@@ -105,32 +105,26 @@ cmd
105105 -- run command '...' in all containers of the LXC suite
106106 :<name>: run command '...' in container <name>
107107install
108− :suite: install LXC suite; ${LXC_SUITE_INSTALL_INFO}
109108 :base: prepare LXC; install basic packages
109+ :suite: install LXC ${LXC_SUITE_NAME} suite into all (or <name>) containers
110110
111111EOF
112− usage_images
113− echo
114112 usage_containers
115− echo
116113 [ -n "${1+x}" ] && err_msg "$1"
117114}
118115
119116usage_containers() {
120117 cat <<EOF
121−LXC suite containers:
118+LXC suite: ${LXC_SUITE_NAME}
119+$(echo " ${LXC_SUITE_INSTALL_INFO}" | $FMT)
120+suite images:
121+$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
122+suite containers:
122123$(echo " ${CONTAINERS[*]}" | $FMT)
123124EOF
124125 [ -n "${1+x}" ] && err_msg "$1"
125126}
126127
127−usage_images() {
128− cat <<EOF
129−LXC suite images:
130−$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
131−EOF
132−}
133−
134128lxd_info() {
135129
136130 cat <<EOF
@@ -216,6 +210,7 @@ main() {
216210 config)
217211 case $3 in
218212 ${LXC_HOST_PREFIX}-*)
213+ ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
219214 lxc config show "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
220215 ;;
221216 *)
@@ -230,6 +225,7 @@ main() {
230225 info)
231226 case $3 in
232227 ${LXC_HOST_PREFIX}-*)
228+ ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
233229 lxc info "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
234230 ;;
235231 *)
@@ -259,14 +255,21 @@ main() {
259255 shift
260256 lxc_exec_cmd "${name}" "$@"
261257 ;;
262− *) usage "uknown or missing container <name> $1"; exit 42;;
263− esac
258+ *) usage_containers "unknown container: $1" && exit 42
259+ esac
264260 ;;
265261 install)
266262 sudo_or_exit
267263 case $2 in
268264 suite|base)
269− lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2"
265+ case $3 in
266+ ${LXC_HOST_PREFIX}-*)
267+ ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
268+ lxc_exec_cmd "$3" "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2"
269+ ;;
270+ '') lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" ;;
271+ *) usage_containers "unknown container: $3" && exit 42
272+ esac
270273 ;;
271274 *) usage "$_usage"; exit 42 ;;
272275 esac