diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-07 20:24:08 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-07 20:24:08 +0100 |
commit | b1e90cff23eae2181d2b430e77471f488947d1a9 (patch) | |
tree | 18d1c0ce98f034cdb2c38840b3138f81654ff945 /utils/lib.sh | |
parent | a258358633e18d3e5768223ebb05201bbd2e8ca4 (diff) | |
download | searxng-b1e90cff23eae2181d2b430e77471f488947d1a9.tar.gz searxng-b1e90cff23eae2181d2b430e77471f488947d1a9.zip |
LXC: separate lxc-suite from lxc & improved command line.
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'utils/lib.sh')
-rwxr-xr-x | utils/lib.sh | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/utils/lib.sh b/utils/lib.sh index 09883df3b..26a26d750 100755 --- a/utils/lib.sh +++ b/utils/lib.sh @@ -1062,14 +1062,69 @@ EOF # containers # ---------- -is_container() { - sudo_or_exit - - # usage: is_container && echo "process running inside a LXC container" - # is_container || echo "process is not running inside a LXC container" +in_container() { + # Test if shell runs in a container. # # hint: Reads init process environment, therefore root access is required! + # + # usage: in_container && echo "process running inside a LXC container" + # in_container || echo "process is not running inside a LXC container" + # + sudo_or_exit # to be safe, take a look at the environment of process 1 (/sbin/init) grep -qa 'container=lxc' /proc/1/environ } + + +lxc_exists(){ + + # usage: lxc_exists <name> || echo "container <name> does not exists" + + lxc info "$1" &>/dev/null +} + +lxc_image_exists(){ + # usage: lxc_image_exists <alias> || echo "image <alias> does locally not exists" + + lxc image info "local:$1" &>/dev/null + +} + +lxc_delete_container() { + + # usage: lxc_delete_container <container-name> + + if lxc info "$1" &>/dev/null; then + info_msg "stop & delete instance ${_BBlue}${1}${_creset}" + lxc stop "$1" &>/dev/null + lxc delete "$1" | prefix_stdout + else + warn_msg "instance '$1' does not exist / can't delete :o" + fi +} + +lxc_delete_local_image() { + + # usage: lxc_delete_local_image <container-name> + + info_msg "delete image 'local:$i'" + lxc image delete "local:$i" +} + + +# IP +# -- + +global_IPs(){ + # usage: global_IPS + # + # print list of host's SCOPE global addresses and adapters e.g:: + # + # $ global_IPs + # enp4s0|192.168.1.127 + # lxdbr0|10.246.86.1 + # lxdbr0|fd42:8c58:2cd:b73f::1 + + ip -o addr show | sed -nr 's/[0-9]*:\s*([a-z0-9]*).*inet[6]?\s*([a-z0-9.:]*).*scope global.*/\1|\2/p' +} |