From c2b8f459ddc3c3dcda2e8df35bde7879dc95027b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 7 Mar 2019 15:11:27 +0100 Subject: [PATCH] Global check prevented to run ynh-dev inside the LXC ... factorized stuff to a single check_lxc_setup function --- ynh-dev | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ynh-dev b/ynh-dev index f93e9ac..326a524 100755 --- a/ynh-dev +++ b/ynh-dev @@ -30,8 +30,6 @@ function main() [ -z "$ACTION" ] && show_usage && exit 0 - check_lxc_version - case "${ACTION}" in help|-h|--help) show_usage $ARGUMENTS ;; @@ -113,22 +111,23 @@ function create_sym_link() { # Actions # ################################################################## -function check_lxc_version() +function check_lxc_setup() { local LXC_VERSION=$(lxc-info --version) - if [ "${LXC_VERSION:0:1}" != 3 ] - then - echo "ERROR: you need at least version 3 of LXC otherwise the box won't work" - exit 1 - fi + [[ "${LXC_VERSION:0:1}" == 3 ]] \ + || critical "You need at least version 3 of LXC otherwise the box won't work" + + [[ $(systemctl is-active lxc-net) == "active" ]] \ + || critical "Service lxc-net should be running ... You probably need to fix your lxc network conf before being able to use lxc's." + + ip a | grep -q lxcbr0 \ + || critical "There is no 'lxcbr0' interface. You probably need to fix your lxc network conf before being able to use lxc's." } function start_ynhdev() { - [[ $(systemctl is-active lxc-net) == "active" ]] || critical "Service lxc-net should be running ... You probably need to fix your lxc network conf before being able to use lxc's." - - ip a | grep lxcbr0 -q || critical "There is no 'lxcbr0' interface. You probably need to fix your lxc network conf before being able to use lxc's." + check_lxc_setup local NAME=${1:-ynh-dev} local BOX_NAME="yunohost/$NAME" @@ -150,21 +149,21 @@ function start_ynhdev() function ssh_ynhdev() { + check_lxc_setup local NAME=${1:-ynh-dev} vagrant ssh $NAME -c "echo 'You are now inside the LXC !'; cd /ynh-dev; sudo su" } function destroy_ynhdev() { + check_lxc_setup local NAME=${1:-ynh-dev} vagrant destroy $NAME } function rebuild_ynhdev() { - [[ $(systemctl is-active lxc-net) == "active" ]] || critical "Service lxc-net should be running ... You probably need to fix your lxc network conf before being able to use lxc's." - - ip a | grep lxcbr0 -q || critical "There is no 'lxcbr0' interface. You probably need to fix your lxc network conf before being able to use lxc's." + check_lxc_setup local BOX="ynh-dev"