on master help sign in
LXC: separate lxc-suite from lxc & improved command line.
b1e90cfMarkus Heiser
Makefile+1−1
@@ -110,7 +110,7 @@ test.sh:
110 shellcheck -x utils/searx.sh
110 shellcheck -x utils/searx.sh
111 shellcheck -x utils/morty.sh
111 shellcheck -x utils/morty.sh
112 shellcheck -x utils/lxc.sh
112 shellcheck -x utils/lxc.sh
113− shellcheck -x utils/lxc.env
113+ shellcheck -x utils/lxc-searx.env
114 shellcheck -x .config.sh
114 shellcheck -x .config.sh
115
115
116test.pep8: pyenvinstall
116test.pep8: pyenvinstall
utils/filtron.sh+1−1
@@ -6,7 +6,7 @@
6# shellcheck source=utils/lib.sh
6# shellcheck source=utils/lib.sh
7source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
7source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
8source_dot_config
8source_dot_config
9−source "${REPO_ROOT}/utils/lxc.env"
9+source "${REPO_ROOT}/utils/lxc-searx.env"
10
10
11# ----------------------------------------------------------------------------
11# ----------------------------------------------------------------------------
12# config
12# config
utils/lib.sh+60−5
@@ -1062,14 +1062,69 @@ EOF
1062# containers
1062# containers
1063# ----------
1063# ----------
1064
1064
1065−is_container() {
1065+in_container() {
1066− sudo_or_exit
1066+ # Test if shell runs in a container.
1067−
1068− # usage: is_container && echo "process running inside a LXC container"
1069− # is_container || echo "process is not running inside a LXC container"
1070 #
1067 #
1071 # hint: Reads init process environment, therefore root access is required!
1068 # hint: Reads init process environment, therefore root access is required!
1069+ #
1070+ # usage: in_container && echo "process running inside a LXC container"
1071+ # in_container || echo "process is not running inside a LXC container"
1072+ #
1072
1073
1074+ sudo_or_exit
1073 # to be safe, take a look at the environment of process 1 (/sbin/init)
1075 # to be safe, take a look at the environment of process 1 (/sbin/init)
1074 grep -qa 'container=lxc' /proc/1/environ
1076 grep -qa 'container=lxc' /proc/1/environ
1075}
1077}
1078+
1079+
1080+lxc_exists(){
1081+
1082+ # usage: lxc_exists <name> || echo "container <name> does not exists"
1083+
1084+ lxc info "$1" &>/dev/null
1085+}
1086+
1087+lxc_image_exists(){
1088+ # usage: lxc_image_exists <alias> || echo "image <alias> does locally not exists"
1089+
1090+ lxc image info "local:$1" &>/dev/null
1091+
1092+}
1093+
1094+lxc_delete_container() {
1095+
1096+ # usage: lxc_delete_container <container-name>
1097+
1098+ if lxc info "$1" &>/dev/null; then
1099+ info_msg "stop & delete instance ${_BBlue}${1}${_creset}"
1100+ lxc stop "$1" &>/dev/null
1101+ lxc delete "$1" | prefix_stdout
1102+ else
1103+ warn_msg "instance '$1' does not exist / can't delete :o"
1104+ fi
1105+}
1106+
1107+lxc_delete_local_image() {
1108+
1109+ # usage: lxc_delete_local_image <container-name>
1110+
1111+ info_msg "delete image 'local:$i'"
1112+ lxc image delete "local:$i"
1113+}
1114+
1115+
1116+# IP
1117+# --
1118+
1119+global_IPs(){
1120+ # usage: global_IPS
1121+ #
1122+ # print list of host's SCOPE global addresses and adapters e.g::
1123+ #
1124+ # $ global_IPs
1125+ # enp4s0|192.168.1.127
1126+ # lxdbr0|10.246.86.1
1127+ # lxdbr0|fd42:8c58:2cd:b73f::1
1128+
1129+ ip -o addr show | sed -nr 's/[0-9]*:\s*([a-z0-9]*).*inet[6]?\s*([a-z0-9.:]*).*scope global.*/\1|\2/p'
1130+}
utils/lxc-searx.envnew file+62
@@ -0,0 +1,62 @@
1+# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
2+# SPDX-License-Identifier: AGPL-3.0-or-later
3+# shellcheck shell=bash
4+
5+# This file is a setup of a LXC suite. It is sourced from different context, do
6+# not manipulate the environment directly, implement functions and manipulate
7+# environment only is subshells!
8+
9+# ----------------------------------------------------------------------------
10+# config
11+# ----------------------------------------------------------------------------
12+
13+lxc_set_suite_env() {
14+ # name of https://images.linuxcontainers.org
15+ export LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
16+ export LXC_HOST_PREFIX="${LXC_HOST_PREFIX:-searx}"
17+ export LXC_SUITE=(
18+ # end of standard support see https://wiki.ubuntu.com/Releases
19+ "$LINUXCONTAINERS_ORG_NAME:ubuntu/16.04" "ubu1604" # April 2021
20+ "$LINUXCONTAINERS_ORG_NAME:ubuntu/18.04" "ubu1804" # April 2023
21+ "$LINUXCONTAINERS_ORG_NAME:ubuntu/19.10" "ubu1910" # July 2020
22+ "$LINUXCONTAINERS_ORG_NAME:ubuntu/20.04" "ubu2004" # future (EOL 2030)
23+
24+ # EOL see https://fedoraproject.org/wiki/Releases
25+ "$LINUXCONTAINERS_ORG_NAME:fedora/31" "fedora31"
26+
27+ # rolling releases see https://www.archlinux.org/releng/releases/
28+ "$LINUXCONTAINERS_ORG_NAME:archlinux" "archlinux"
29+ )
30+ export FILTRON_API="0.0.0.0:4005"
31+ export FILTRON_LISTEN="0.0.0.0:4004"
32+ export MORTY_LISTEN="0.0.0.0:3000"
33+}
34+
35+lxc_suite_install() {
36+ (
37+ lxc_set_suite_env
38+ export FORCE_TIMEOUT=0
39+ "${LXC_REPO_ROOT}/utils/searx.sh" install all
40+ "${LXC_REPO_ROOT}/utils/morty.sh" install all
41+ "${LXC_REPO_ROOT}/utils/filtron.sh" install all
42+
43+ rst_title "suite installation finished ($(hostname))" part
44+ lxc_suite_info
45+ echo
46+ )
47+}
48+
49+lxc_suite_info() {
50+ (
51+ lxc_set_suite_env
52+ for ip in $(global_IPs) ; do
53+ if [[ $ip =~ .*:.* ]]; then
54+ info_msg "(${ip%|*}) IPv6: http://[${ip#*|}]"
55+ else
56+ # IPv4:
57+ info_msg "(${ip%|*}) filtron: http://${ip#*|}:4004/"
58+ info_msg "(${ip%|*}) morty: http://${ip#*|}:3000/"
59+ fi
60+ done
61+ )
62+}
utils/lxc.envdeleted−14
@@ -1,14 +0,0 @@
1−# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
2−# SPDX-License-Identifier: AGPL-3.0-or-later
3−
4−# Herein we place all, what is needed to know when inside containers. Its
5−# sourced from different context --> do not manipulate the environment directly,
6−# implement functions!
7−
8−# shellcheck shell=sh
9−
10−searx_suite_set_env() {
11− export FILTRON_API="0.0.0.0:4005"
12− export FILTRON_LISTEN="0.0.0.0:4004"
13− export MORTY_LISTEN="0.0.0.0:3000"
14−}
utils/lxc.sh+212−151
@@ -5,7 +5,11 @@
5# shellcheck source=utils/lib.sh
5# shellcheck source=utils/lib.sh
6source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
6source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
7source_dot_config
7source_dot_config
8+
9+# load environment of the LXC suite
8−source "${REPO_ROOT}/utils/lxc.env"
10+LXC_ENV="${LXC_ENV:-${REPO_ROOT}/utils/lxc-searx.env}"
11+source "$LXC_ENV"
12+lxc_set_suite_env
9
13
10# ----------------------------------------------------------------------------
14# ----------------------------------------------------------------------------
11# config
15# config
@@ -14,33 +18,27 @@ source "${REPO_ROOT}/utils/lxc.env"
14# read also:
18# read also:
15# - https://lxd.readthedocs.io/en/latest/
19# - https://lxd.readthedocs.io/en/latest/
16
20
17−# name of https://images.linuxcontainers.org
21+LXC_HOST_PREFIX="${LXC_HOST_PREFIX:-test}"
18−LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
19−HOST_PREFIX="${HOST_PREFIX:-searx}"
20
22
21# where all folders from HOST are mounted
23# where all folders from HOST are mounted
22LXC_SHARE_FOLDER="/share"
24LXC_SHARE_FOLDER="/share"
23LXC_REPO_ROOT="${LXC_SHARE_FOLDER}/$(basename "${REPO_ROOT}")"
25LXC_REPO_ROOT="${LXC_SHARE_FOLDER}/$(basename "${REPO_ROOT}")"
24
26
25−TEST_IMAGES=(
27+ubu1604_boilerplate="
26− "$LINUXCONTAINERS_ORG_NAME:ubuntu/18.04" "ubu1804"
27− "$LINUXCONTAINERS_ORG_NAME:ubuntu/19.04" "ubu1904"
28− "$LINUXCONTAINERS_ORG_NAME:ubuntu/19.10" "ubu1910"
29− "$LINUXCONTAINERS_ORG_NAME:ubuntu/20.04" "ubu2004"
30− "$LINUXCONTAINERS_ORG_NAME:archlinux" "archlinux"
31− "$LINUXCONTAINERS_ORG_NAME:fedora/31" "fedora31"
32−)
33−
34−ubu1804_boilerplate="
35export DEBIAN_FRONTEND=noninteractive
28export DEBIAN_FRONTEND=noninteractive
36apt-get update -y
29apt-get update -y
37apt-get upgrade -y
30apt-get upgrade -y
38apt-get install -y git curl wget
31apt-get install -y git curl wget
39"
32"
33+ubu1804_boilerplate="$ubu1604_boilerplate"
40ubu1904_boilerplate="$ubu1804_boilerplate"
34ubu1904_boilerplate="$ubu1804_boilerplate"
41ubu1910_boilerplate="$ubu1904_boilerplate"
35ubu1910_boilerplate="$ubu1904_boilerplate"
36+
42# shellcheck disable=SC2034
37# shellcheck disable=SC2034
43−ubu2004_boilerplate="$ubu1910_boilerplate"
38+ubu2004_boilerplate="
39+$ubu1910_boilerplate
40+echo 'Set disable_coredump false' >> /etc/sudo.conf
41+"
44
42
45# shellcheck disable=SC2034
43# shellcheck disable=SC2034
46archlinux_boilerplate="
44archlinux_boilerplate="
@@ -57,11 +55,13 @@ echo 'Set disable_coredump false' >> /etc/sudo.conf
57"
55"
58
56
59REMOTE_IMAGES=()
57REMOTE_IMAGES=()
58+CONTAINERS=()
60LOCAL_IMAGES=()
59LOCAL_IMAGES=()
61
60
62−for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
61+for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
63− REMOTE_IMAGES=("${REMOTE_IMAGES[@]}" "${TEST_IMAGES[i]}")
62+ REMOTE_IMAGES=("${REMOTE_IMAGES[@]}" "${LXC_SUITE[i]}")
64− LOCAL_IMAGES=("${LOCAL_IMAGES[@]}" "${HOST_PREFIX}-${TEST_IMAGES[i+1]}")
63+ CONTAINERS=("${CONTAINERS[@]}" "${LXC_HOST_PREFIX}-${LXC_SUITE[i+1]}")
64+ LOCAL_IMAGES=("${LOCAL_IMAGES[@]}" "${LXC_SUITE[i+1]}")
65done
65done
66
66
67HOST_USER="${SUDO_USER:-$USER}"
67HOST_USER="${SUDO_USER:-$USER}"
@@ -71,36 +71,48 @@ HOST_GROUP_ID=$(id -g "${HOST_USER}")
71# ----------------------------------------------------------------------------
71# ----------------------------------------------------------------------------
72usage() {
72usage() {
73# ----------------------------------------------------------------------------
73# ----------------------------------------------------------------------------
74−
74+ _cmd="$(basename "$0")"
75 cat <<EOF
75 cat <<EOF
76
76
77usage::
77usage::
78
78
79− $(basename "$0") build [containers]
79+ $_cmd build [containers]
80− $(basename "$0") install [searx-suite]
80+ $_cmd copy [images]
81− $(basename "$0") remove [containers|subordinate]
81+ $_cmd remove [containers|<name>|images|subordinate]
82+ $_cmd add [subordinate]
82− $(basename "$0") [start|stop] [containers|<container-name>]
83+ $_cmd [start|stop] [containers|<name>]
83− $(basename "$0") show [info|config|searx-suite]
84+ $_cmd show [info|config|suite|images]
84− $(basename "$0") cmd ...
85+ $_cmd cmd [--|<name>] ...
85−
86+ $_cmd install [suite]
87+
86−build / remove
88+build
87− :containers: build & launch (or remove) all LXC containers
89+ :containers: build & launch all LXC containers of the suite
90+copy:
91+ :images: copy remote images of the suite into local storage
92+remove
93+ :containers: delete all 'containers' or only <container-name>
94+ :images: delete local images of the suite
88add / remove
95add / remove
89− :subordinate: lxd permission to map ${HOST_USER}'s user/group id through
96+ :subordinate: LXD permission to map ${HOST_USER}'s user/group id through
90start/stop
97start/stop
91− :containers: start/stop of all 'containers' or only <container-name>
98+ :containers: start/stop all 'containers' from the suite
99+ :<name>: start/stop conatiner <name> from suite
92show
100show
93− :info: show info of all containers
101+ :info: show info of all the containers from LXC suite
94− :config: show config of all containers
102+ :config: show config of all the containers from the LXC suite
95− :searx-suite: show searx-suite services of all containers
103+ :suite: show services of all the containers from the LXC suite
104+ :images: show information of local images
96−cmd ...
105+cmd
97− run commandline ... in all containers
106+ -- run command ... in all containers of the LXC suite
107+ :<name>: run command ... in container <name>
98install
108install
99− :searx-suite: install searx suite, includes morty & filtron
109+ :suite: install LXC suite, includes morty & filtron
100
110
101−all LXC containers:
111+Images of the LXC suite:
102− ${LOCAL_IMAGES[@]}
112+$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
103
113
114+Containers of the LXC suite:
115+$(echo " ${CONTAINERS[*]}" | $FMT)
104EOF
116EOF
105 [ -n "${1+x}" ] && err_msg "$1"
117 [ -n "${1+x}" ] && err_msg "$1"
106}
118}
@@ -122,10 +134,12 @@ main() {
122 local exit_val
134 local exit_val
123 local _usage="unknown or missing $1 command $2"
135 local _usage="unknown or missing $1 command $2"
124
136
137+ # don't check prerequisite when in recursion
138+ if [[ ! $1 == __* ]]; then
125− if [[ ! $1 == __* ]] && ! required_commands lxc; then
139+ ! required_commands lxc && lxd_info && exit 42
126− lxd_info
140+ [[ -z $LXC_SUITE ]] && err_msg "missing LXC_SUITE" && exit 42
127− exit 42
128 fi
141 fi
142+
129 case $1 in
143 case $1 in
130 --source-only) ;;
144 --source-only) ;;
131 -h|--help) usage; exit 0;;
145 -h|--help) usage; exit 0;;
@@ -133,16 +147,28 @@ main() {
133 build)
147 build)
134 sudo_or_exit
148 sudo_or_exit
135 case $2 in
149 case $2 in
136− containers) build_instances ;;
150+ ''|containers) build_instances ;;
151+ *) usage "$_usage"; exit 42;;
152+ esac
153+ ;;
154+ copy)
155+ case $2 in
156+ ''|images) lxc_copy_images_localy;;
137 *) usage "$_usage"; exit 42;;
157 *) usage "$_usage"; exit 42;;
138 esac
158 esac
139 ;;
159 ;;
140 remove)
160 remove)
141 sudo_or_exit
161 sudo_or_exit
142 case $2 in
162 case $2 in
143− containers) remove_instances ;;
163+ ''|containers) remove_instances ;;
164+ images) lxc_delete_images_localy ;;
144 subordinate) echo; del_subordinate_ids ;;
165 subordinate) echo; del_subordinate_ids ;;
145− *) usage "$_usage"; exit 42;;
166+ ${LXC_HOST_PREFIX}-*)
167+ if ask_yn "Do you really want to delete conatiner $2"; then
168+ lxc_delete_container "$2"
169+ fi
170+ ;;
171+ *) usage "unknown (or mising) container <name> $2"; exit 42;;
146 esac
172 esac
147 ;;
173 ;;
148 add)
174 add)
@@ -155,116 +181,86 @@ main() {
155 start|stop)
181 start|stop)
156 sudo_or_exit
182 sudo_or_exit
157 case $2 in
183 case $2 in
158− containers) lxc_cmd "$1" ;;
184+ ''|containers) lxc_cmd "$1" ;;
159− *)
185+ ${LXC_HOST_PREFIX}-*)
160 info_msg "lxc $1 $2"
186 info_msg "lxc $1 $2"
161 lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
187 lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
162 ;;
188 ;;
189+ *) usage "ukknown or missing container <name> $2"; exit 42;;
163 esac
190 esac
164 ;;
191 ;;
165 show)
192 show)
166 sudo_or_exit
193 sudo_or_exit
167 case $2 in
194 case $2 in
168− config) lxc_cmd config show;;
169− info) lxc_cmd info;;
170− searx-suite)
195+ suite) show_suite ;;
171− for i in "${LOCAL_IMAGES[@]}"; do
196+ images) show_images ;;
172− info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install $2${_creset}"
197+ config)
173− lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show "$2" | prefix_stdout "[${i}] "
198+ rst_title "container configurations"
174− done
199+ echo
200+ lxc list "$LXC_HOST_PREFIX-"
201+ echo
202+ lxc_cmd config show
203+ ;;
204+ info)
205+ rst_title "container info"
206+ echo
207+ lxc_cmd info
175 ;;
208 ;;
176 *) usage "$_usage"; exit 42;;
209 *) usage "$_usage"; exit 42;;
177 esac
210 esac
178 ;;
211 ;;
179 __show)
212 __show)
180 case $2 in
213 case $2 in
181− searx-suite) searx_suite_info ;;
214+ suite) lxc_suite_info ;;
182 esac
215 esac
183 ;;
216 ;;
184 cmd)
217 cmd)
185 sudo_or_exit
218 sudo_or_exit
186 shift
219 shift
187− for i in "${LOCAL_IMAGES[@]}"; do
220+ case $1 in
188− exit_val=
221+ --)
189− info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${*}${_creset}"
222+ shift
190− lxc exec "${i}" -- "$@"
223+ for name in "${CONTAINERS[@]}"; do
191− exit_val=$?
224+ lxc_exec_cmd "${name}" "$@"
192− if [[ $exit_val -ne 0 ]]; then
193− warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
194− else
195− info_msg "[${_BBlue}${i}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
196− fi
197− echo
198− done
225+ done
226+ ;;
227+ ${LXC_HOST_PREFIX}-*)
228+ local name=$1
229+ shift
230+ lxc_exec_cmd "${name}" "$@"
231+ ;;
232+
233+ *) usage "unknown <name>: $1"; exit 42
234+ ;;
235+ esac
199 ;;
236 ;;
200 install)
237 install)
201 sudo_or_exit
238 sudo_or_exit
202 case $2 in
239 case $2 in
203− searx-suite)
240+ suite) install_suite ;;
204− for i in "${LOCAL_IMAGES[@]}"; do
205− info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install $2${_creset}"
206− lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" | prefix_stdout "[${i}] "
207− done
208− ;;
209− *) usage "$_usage"; exit 42;;
241+ *) usage "$_usage"; exit 42 ;;
210 esac
242 esac
211 ;;
243 ;;
212 __install)
244 __install)
213 case $2 in
245 case $2 in
214− searx-suite) searx_suite_install ;;
246+ suite) lxc_suite_install ;;
215 esac
247 esac
216 ;;
248 ;;
217 doc)
249 doc)
218 echo
250 echo
219 echo ".. generic utils/lxc.sh documentation"
251 echo ".. generic utils/lxc.sh documentation"
220 ;;
252 ;;
221−
253+ -*) usage "unknown option $1"; exit 42;;
222− *)
223− usage "unknown or missing command $1"; exit 42;;
254+ *) usage "unknown or missing command $1"; exit 42;;
224 esac
255 esac
225}
256}
226
257
227−searx_suite_install() {
228− (
229− searx_suite_set_env
230− export FORCE_TIMEOUT=0
231− "${LXC_REPO_ROOT}/utils/searx.sh" install all
232− "${LXC_REPO_ROOT}/utils/morty.sh" install all
233− "${LXC_REPO_ROOT}/utils/filtron.sh" install all
234−
235− rst_title "searx-suite installation finished ($(hostname))" part
236− searx_suite_info
237− echo
238− )
239−}
240−
241−searx_suite_info() {
242− (
243− searx_suite_set_env
244− rst_para "Services of the container $(hostname)"
245− for ip in $(hostname -I); do
246− echo
247− if [[ $ip =~ .*:.* ]]; then
248− :
249− # IPv6: not yet implemented / tested
250− # echo " searx (filtron) --> http://[$ip]:4004/"
251− # echo " morty --> http://[$ip]:3000/"
252− else
253− # IPv4:
254− echo " searx (filtron) --> http://$ip:4004/"
255− echo " morty --> http://$ip:3000/"
256− fi
257− done
258− )
259−}
260
258
261build_instances() {
259build_instances() {
262 rst_title "Build LXC instances"
260 rst_title "Build LXC instances"
263−
264− rst_title "copy images" section
265 echo
261 echo
262+ add_subordinate_ids
266 lxc_copy_images_localy
263 lxc_copy_images_localy
267− # lxc image list local: && wait_key
268 echo
264 echo
269 rst_title "build containers" section
265 rst_title "build containers" section
270 echo
266 echo
@@ -272,64 +268,141 @@ build_instances() {
272 lxc_config_containers
268 lxc_config_containers
273 lxc_boilerplate_containers
269 lxc_boilerplate_containers
274 echo
270 echo
275− lxc list "$HOST_PREFIX"
271+ lxc list "$LXC_HOST_PREFIX"
276}
272}
277
273
278remove_instances() {
274remove_instances() {
279 rst_title "Remove LXC instances"
275 rst_title "Remove LXC instances"
280− lxc list "$HOST_PREFIX"
276+ rst_para "existing containers matching ${_BGreen}$LXC_HOST_PREFIX-*${_creset}"
277+ echo
278+ lxc list "$LXC_HOST_PREFIX-"
281− echo -en "\\nLXC containers(s)::\\n\\n ${LOCAL_IMAGES[*]}\\n" | $FMT
279+ echo -en "\\n${_BRed}LXC containers to delete::${_creset}\\n\\n ${CONTAINERS[*]}\\n" | $FMT
282− if ask_yn "Do you really want to delete all images"; then
280+ if ask_yn "Do you really want to delete these conatiners"; then
283− lxc_delete_containers
281+ for i in "${CONTAINERS[@]}"; do
282+ lxc_delete_container "$i"
283+ done
284 fi
284 fi
285 echo
285 echo
286− lxc list "$HOST_PREFIX"
286+ lxc list "$LXC_HOST_PREFIX-"
287− # lxc image list local: && wait_key
288}
287}
289
288
290# images
289# images
291# ------
290# ------
292
291
293lxc_copy_images_localy() {
292lxc_copy_images_localy() {
293+ rst_title "copy images" section
294+ echo
294− for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
295+ for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
295− if lxc image info "local:${TEST_IMAGES[i+1]}" &>/dev/null; then
296+ if lxc_image_exists "local:${LXC_SUITE[i+1]}"; then
296− info_msg "image ${TEST_IMAGES[i]} already copied --> ${TEST_IMAGES[i+1]}"
297+ info_msg "image ${LXC_SUITE[i]} already copied --> ${LXC_SUITE[i+1]}"
297 else
298 else
298− info_msg "copy image locally ${TEST_IMAGES[i]} --> ${TEST_IMAGES[i+1]}"
299+ info_msg "copy image locally ${LXC_SUITE[i]} --> ${LXC_SUITE[i+1]}"
299− lxc image copy "${TEST_IMAGES[i]}" local: \
300+ lxc image copy "${LXC_SUITE[i]}" local: \
300− --alias "${TEST_IMAGES[i+1]}" | prefix_stdout
301+ --alias "${LXC_SUITE[i+1]}" | prefix_stdout
301 fi
302 fi
302 done
303 done
304+ # lxc image list local: && wait_key
303}
305}
304
306
305lxc_delete_images_localy() {
307lxc_delete_images_localy() {
308+ rst_title "Delete LXC images"
309+ rst_para "local existing images"
306 echo
310 echo
311+ lxc image list local:
312+ echo -en "\\n${_BRed}LXC images to delete::${_creset}\\n\\n ${LOCAL_IMAGES[*]}\\n"
313+ if ask_yn "Do you really want to delete these images"; then
314+ for i in "${LOCAL_IMAGES[@]}"; do
315+ lxc_delete_local_image "$i"
316+ done
317+ fi
318+ echo
319+ lxc image list local:
320+}
321+
322+show_images(){
323+ rst_title "local images"
324+ echo
325+ lxc image list local:
326+ echo -en "\\n${_Green}LXC suite images::${_creset}\\n\\n ${LOCAL_IMAGES[*]}\\n"
327+ wait_key
307 for i in "${LOCAL_IMAGES[@]}"; do
328 for i in "${LOCAL_IMAGES[@]}"; do
329+ if lxc_image_exists "$i"; then
308− info_msg "delete image 'local:$i'"
330+ info_msg "lxc image info ${_BBlue}${i}${_creset}"
309− lxc image delete "local:$i"
331+ lxc image info "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
332+ else
333+ warn_msg "image ${_BBlue}$i${_creset} does not yet exists"
334+ fi
310 done
335 done
311− #lxc image list local:
336+
312}
337}
313
338
339+
314# container
340# container
315# ---------
341# ---------
316
342
343+show_suite(){
344+ rst_title "LXC suite ($LXC_HOST_PREFIX-*)"
345+ echo
346+ lxc list "$LXC_HOST_PREFIX-"
347+ echo
348+ for i in "${CONTAINERS[@]}"; do
349+ if ! lxc_exists "$i"; then
350+ warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
351+ else
352+ lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show suite \
353+ | prefix_stdout "[${_BBlue}${i}${_creset}] "
354+ fi
355+ done
356+}
357+
358+install_suite() {
359+ for i in "${CONTAINERS[@]}"; do
360+ if ! lxc_exists "$i"; then
361+ warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
362+ else
363+ info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install suite${_creset}"
364+ lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install suite \
365+ | prefix_stdout "[${_BBlue}${i}${_creset}] "
366+ fi
367+ done
368+}
369+
317lxc_cmd() {
370lxc_cmd() {
318− for i in "${LOCAL_IMAGES[@]}"; do
371+ for i in "${CONTAINERS[@]}"; do
372+ if ! lxc_exists "$i"; then
373+ warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
374+ else
319− info_msg "lxc $* $i"
375+ info_msg "lxc $* $i"
320− lxc "$@" "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
376+ lxc "$@" "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
377+ echo
378+ fi
321 done
379 done
322}
380}
323
381
382+lxc_exec_cmd() {
383+ local name="$1"
384+ shift
385+ exit_val=
386+ info_msg "[${_BBlue}${name}${_creset}] ${_BGreen}${*}${_creset}"
387+ lxc exec "${name}" -- "$@"
388+ exit_val=$?
389+ if [[ $exit_val -ne 0 ]]; then
390+ warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
391+ else
392+ info_msg "[${_BBlue}${i}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
393+ fi
394+ echo
395+}
396+
324lxc_init_containers() {
397lxc_init_containers() {
325
398
326 local image_name
399 local image_name
327 local container_name
400 local container_name
328
401
329− for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
402+ for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
330
403
331− image_name="${TEST_IMAGES[i+1]}"
404+ image_name="${LXC_SUITE[i+1]}"
332− container_name="${HOST_PREFIX}-${image_name}"
405+ container_name="${LXC_HOST_PREFIX}-${image_name}"
333
406
334 if lxc info "${container_name}" &>/dev/null; then
407 if lxc info "${container_name}" &>/dev/null; then
335 info_msg "container '${container_name}' already exists"
408 info_msg "container '${container_name}' already exists"
@@ -341,7 +414,7 @@ lxc_init_containers() {
341}
414}
342
415
343lxc_config_containers() {
416lxc_config_containers() {
344− for i in "${LOCAL_IMAGES[@]}"; do
417+ for i in "${CONTAINERS[@]}"; do
345 info_msg "[${_BBlue}${i}${_creset}] configure container ..."
418 info_msg "[${_BBlue}${i}${_creset}] configure container ..."
346
419
347 info_msg "[${_BBlue}${i}${_creset}] map uid/gid from host to container"
420 info_msg "[${_BBlue}${i}${_creset}] map uid/gid from host to container"
@@ -364,10 +437,10 @@ lxc_boilerplate_containers() {
364 local container_name
437 local container_name
365 local boilerplate_script
438 local boilerplate_script
366
439
367− for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
440+ for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
368
441
369− image_name="${TEST_IMAGES[i+1]}"
442+ image_name="${LXC_SUITE[i+1]}"
370− container_name="${HOST_PREFIX}-${image_name}"
443+ container_name="${LXC_HOST_PREFIX}-${image_name}"
371 boilerplate_script="${image_name}_boilerplate"
444 boilerplate_script="${image_name}_boilerplate"
372 boilerplate_script="${!boilerplate_script}"
445 boilerplate_script="${!boilerplate_script}"
373
446
@@ -386,18 +459,6 @@ lxc_boilerplate_containers() {
386 done
459 done
387}
460}
388
461
389−lxc_delete_containers() {
390− for i in "${LOCAL_IMAGES[@]}"; do
391− if lxc info "$i" &>/dev/null; then
392− info_msg "stop & delete instance ${_BBlue}${i}${_creset}"
393− lxc stop "$i" &>/dev/null
394− lxc delete "$i" | prefix_stdout
395− else
396− warn_msg "instance '$i' does not exist / can't delete :o"
397− fi
398− done
399−}
400−
401# subordinates
462# subordinates
402# ------------
463# ------------
403#
464#
utils/morty.sh+1−1
@@ -5,7 +5,7 @@
5# shellcheck source=utils/lib.sh
5# shellcheck source=utils/lib.sh
6source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
6source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
7source_dot_config
7source_dot_config
8−source "${REPO_ROOT}/utils/lxc.env"
8+source "${REPO_ROOT}/utils/lxc-searx.env"
9
9
10# ----------------------------------------------------------------------------
10# ----------------------------------------------------------------------------
11# config
11# config
utils/searx.sh+6−6
@@ -6,7 +6,7 @@
6# shellcheck source=utils/lib.sh
6# shellcheck source=utils/lib.sh
7source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
7source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
8source_dot_config
8source_dot_config
9−source "${REPO_ROOT}/utils/lxc.env"
9+source "${REPO_ROOT}/utils/lxc-searx.env"
10
10
11# ----------------------------------------------------------------------------
11# ----------------------------------------------------------------------------
12# config
12# config
@@ -544,13 +544,13 @@ EOF
544 uWSGI_app_available "$SEARX_UWSGI_APP" \
544 uWSGI_app_available "$SEARX_UWSGI_APP" \
545 || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
545 || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
546
546
547− if is_container; then
547+ if in_container; then
548 warn_msg "runnning inside container ..."
548 warn_msg "runnning inside container ..."
549− for ip in $(hostname -I); do
549+ for ip in $(global_IPs); do
550 if [[ $ip =~ .*:.* ]]; then
550 if [[ $ip =~ .*:.* ]]; then
551− info_msg " public HTTP service (IPv6) --> http://[$ip]"
551+ info_msg " public HTTP service (IPv6) --> http://${ip#*|}"
552 else
552 else
553− info_msg " public HTTP service (IPv4) --> http://$ip"
553+ info_msg " public HTTP service (IPv4) --> http://${ip#*|}"
554 fi
554 fi
555 done
555 done
556 warn_msg "SEARX_INTERNAL_URL not available from outside"
556 warn_msg "SEARX_INTERNAL_URL not available from outside"
@@ -564,7 +564,7 @@ EOF
564
564
565 if ! service_is_available "${PUBLIC_URL}"; then
565 if ! service_is_available "${PUBLIC_URL}"; then
566 warn_msg "Public service at ${PUBLIC_URL} is not available!"
566 warn_msg "Public service at ${PUBLIC_URL} is not available!"
567− if is_container; then
567+ if in_container; then
568 warn_msg "Check if public name is correct and routed or use the public IP from above."
568 warn_msg "Check if public name is correct and routed or use the public IP from above."
569 fi
569 fi
570 fi
570 fi