on master help sign in
utils/lxc.sh install: support installation on selected containers
3c19f2fMarkus Heiser
utils/lxc-searx.env+3−1
@@ -10,10 +10,12 @@
10# config
10# config
11# ----------------------------------------------------------------------------
11# ----------------------------------------------------------------------------
12
12
13+# shellcheck disable=SC2034
14+LXC_SUITE_NAME="searx"
13lxc_set_suite_env() {
15lxc_set_suite_env() {
14 # name of https://images.linuxcontainers.org
16 # name of https://images.linuxcontainers.org
15 export LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
17 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}"
17 export LXC_SUITE=(
19 export LXC_SUITE=(
18
20
19 # to disable containers, comment out lines ..
21 # to disable containers, comment out lines ..
utils/lxc.sh+19−16
@@ -82,7 +82,7 @@ usage::
82 $_cmd [start|stop] [containers|<name>]
82 $_cmd [start|stop] [containers|<name>]
83 $_cmd show [images|suite|info|config [<name>]]
83 $_cmd show [images|suite|info|config [<name>]]
84 $_cmd cmd [--|<name>] '...'
84 $_cmd cmd [--|<name>] '...'
85− $_cmd install [suite|base]
85+ $_cmd install [suite|base [<name>]]
86
86
87build
87build
88 :containers: build, launch all containers and 'install base' packages
88 :containers: build, launch all containers and 'install base' packages
@@ -105,32 +105,26 @@ cmd
105 -- run command '...' in all containers of the LXC suite
105 -- run command '...' in all containers of the LXC suite
106 :<name>: run command '...' in container <name>
106 :<name>: run command '...' in container <name>
107install
107install
108− :suite: install LXC suite; ${LXC_SUITE_INSTALL_INFO}
109 :base: prepare LXC; install basic packages
108 :base: prepare LXC; install basic packages
109+ :suite: install LXC ${LXC_SUITE_NAME} suite into all (or <name>) containers
110
110
111EOF
111EOF
112− usage_images
113− echo
114 usage_containers
112 usage_containers
115− echo
116 [ -n "${1+x}" ] && err_msg "$1"
113 [ -n "${1+x}" ] && err_msg "$1"
117}
114}
118
115
119usage_containers() {
116usage_containers() {
120 cat <<EOF
117 cat <<EOF
118+LXC suite: ${LXC_SUITE_NAME}
119+$(echo " ${LXC_SUITE_INSTALL_INFO}" | $FMT)
120+suite images:
121+$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
121−LXC suite containers:
122+suite containers:
122$(echo " ${CONTAINERS[*]}" | $FMT)
123$(echo " ${CONTAINERS[*]}" | $FMT)
123EOF
124EOF
124 [ -n "${1+x}" ] && err_msg "$1"
125 [ -n "${1+x}" ] && err_msg "$1"
125}
126}
126
127
127−usage_images() {
128− cat <<EOF
129−LXC suite images:
130−$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
131−EOF
132−}
133−
134lxd_info() {
128lxd_info() {
135
129
136 cat <<EOF
130 cat <<EOF
@@ -216,6 +210,7 @@ main() {
216 config)
210 config)
217 case $3 in
211 case $3 in
218 ${LXC_HOST_PREFIX}-*)
212 ${LXC_HOST_PREFIX}-*)
213+ ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
219 lxc config show "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
214 lxc config show "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
220 ;;
215 ;;
221 *)
216 *)
@@ -230,6 +225,7 @@ main() {
230 info)
225 info)
231 case $3 in
226 case $3 in
232 ${LXC_HOST_PREFIX}-*)
227 ${LXC_HOST_PREFIX}-*)
228+ ! lxc_exists "$3" && usage_containers "unknown container: $3" && exit 42
233 lxc info "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
229 lxc info "$3" | prefix_stdout "[${_BBlue}${3}${_creset}] "
234 ;;
230 ;;
235 *)
231 *)
@@ -259,14 +255,21 @@ main() {
259 shift
255 shift
260 lxc_exec_cmd "${name}" "$@"
256 lxc_exec_cmd "${name}" "$@"
261 ;;
257 ;;
262− *) usage "uknown or missing container <name> $1"; exit 42;;
258+ *) usage_containers "unknown container: $1" && exit 42
263− esac
259+ esac
264 ;;
260 ;;
265 install)
261 install)
266 sudo_or_exit
262 sudo_or_exit
267 case $2 in
263 case $2 in
268 suite|base)
264 suite|base)
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+ ;;
269− lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2"
270+ '') lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" ;;
271+ *) usage_containers "unknown container: $3" && exit 42
272+ esac
270 ;;
273 ;;
271 *) usage "$_usage"; exit 42 ;;
274 *) usage "$_usage"; exit 42 ;;
272 esac
275 esac