diff --git a/README.md b/README.md index a48852c..5e3f48c 100644 --- a/README.md +++ b/README.md @@ -123,8 +123,11 @@ be able to install `snapd` using the system package manager (or even apt install git snapd sudo snap install lxd -# You need to add /snap/bin to your PATH variable ... maybe add this to your .bashrc! -PATH=$PATH:/snap/bin +# Adding lxc/lxd to /usr/local/bin to make sure we can use them easily even +# with sudo for which the PATH is defined in /etc/sudoers and probably doesn't +# include /snap/bin +sudo ln -s /snap/bin/lxc /usr/local/bin/lxc +sudo ln -s /snap/bin/lxd /usr/local/bin/lxd ``` Then you shall initialize LXD which will ask you a bunch of question. Usually diff --git a/ynh-dev b/ynh-dev index d85fa9a..23aed36 100755 --- a/ynh-dev +++ b/ynh-dev @@ -1,7 +1,5 @@ #!/bin/bash -lxc="sudo /snap/bin/lxc" - function show_usage() { cat </dev/null \ + || critical "You need to have LXD installed for ynh-dev to be usable from the host machine. Refer to the README to know how to install it." - [[ -n "$LXD_VERSION" ]] \ - || critical "You need to have LXD install for ynh-dev to be usable from the host machine. From a debian-like system, you can install it with 'apt install snap' then 'snap install lxd'. (Don't forget to add /snap/bin to your \$PATH somehow. Then you can run 'lxd init' (keeping all the default option is usally okay!)" + # Check that we'll be able to use lxc/lxd using sudo (for which the PATH is defined in /etc/sudoers and probably doesn't include /snap/bin) + if [[ ! -e /usr/bin/lxc ]] && [[ ! -e /usr/bin/lxd ]] + then + [[ -e /usr/local/bin/lxc ]] && [[ -e /usr/local/bin/lxd ]] \ + || critical "You might want to add lxc and lxd inside /usr/local/bin so that there's no tricky PATH issue with sudo. If you installed lxd/lxc with snapd, this should do the trick: sudo ln -s /snap/bin/lxc /usr/local/bin/lxc && sudo ln -s /snap/bin/lxd /usr/local/bin/lxd" + fi ip a | grep -q lxdbr0 \ || critical "There is no 'lxdbr0' interface... Did you ran 'lxd init' ?" @@ -130,12 +134,12 @@ function start_ynhdev() local BOX=${1:-ynh-dev} - $lxc info $BOX &>/dev/null && critical "The container already exist. Use 'attach' to enter the LXC, or 'destroy' if you aim to recreate it." - $lxc image info $BOX-base &>/dev/null || critical "You should first build the base YunoHost LXC using ./ynh-dev rebuild" + sudo lxc info $BOX &>/dev/null && critical "The container already exist. Use 'attach' to enter the LXC, or 'destroy' if you aim to recreate it." + sudo lxc image info $BOX-base &>/dev/null || critical "You should first build the base YunoHost LXC using ./ynh-dev rebuild" set -eu set -x - $lxc launch $BOX-base $BOX - $lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$PWD" + sudo lxc launch $BOX-base $BOX + sudo lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$PWD" set +x attach_ynhdev $BOX @@ -145,16 +149,16 @@ function attach_ynhdev() { check_lxd_setup local BOX=${1:-ynh-dev} - $lxc start $BOX 2>/dev/null || true - $lxc exec $BOX -- /bin/bash + sudo lxc start $BOX 2>/dev/null || true + sudo lxc exec $BOX -- /bin/bash } function destroy_ynhdev() { check_lxd_setup local BOX=${1:-ynh-dev} - $lxc stop $BOX - $lxc delete $BOX + sudo lxc stop $BOX + sudo lxc delete $BOX } function rebuild_ynhdev() @@ -164,14 +168,14 @@ function rebuild_ynhdev() local BOX=${1:-ynh-dev} set -x - $lxc info $BOX-rebuild >/dev/null && $lxc delete $BOX-rebuild --force - $lxc launch images:debian/stretch/amd64 $BOX-rebuild - $lxc config set $BOX-rebuild security.privileged true - $lxc restart $BOX-rebuild - $lxc exec $BOX-rebuild -- apt install curl -y - $lxc exec $BOX-rebuild -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable" - $lxc stop $BOX-rebuild - $lxc publish $BOX-rebuild --alias $BOX-base + sudo lxc info $BOX-rebuild >/dev/null && sudo lxc delete $BOX-rebuild --force + sudo lxc launch images:debian/stretch/amd64 $BOX-rebuild + sudo lxc config set $BOX-rebuild security.privileged true + sudo lxc restart $BOX-rebuild + sudo lxc exec $BOX-rebuild -- apt install curl -y + sudo lxc exec $BOX-rebuild -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable" + sudo lxc stop $BOX-rebuild + sudo lxc publish $BOX-rebuild --alias $BOX-base set +x }