mirror of
https://github.com/YunoHost/ynh-dev.git
synced 2024-09-03 20:05:59 +02:00
Add lxc/lxd to /usr/local/bin so that it works nicely with sudo
This commit is contained in:
parent
360c25c747
commit
ea22e9409d
2 changed files with 30 additions and 23 deletions
|
@ -123,8 +123,11 @@ be able to install `snapd` using the system package manager (or even
|
||||||
apt install git snapd
|
apt install git snapd
|
||||||
sudo snap install lxd
|
sudo snap install lxd
|
||||||
|
|
||||||
# You need to add /snap/bin to your PATH variable ... maybe add this to your .bashrc!
|
# Adding lxc/lxd to /usr/local/bin to make sure we can use them easily even
|
||||||
PATH=$PATH:/snap/bin
|
# 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
|
Then you shall initialize LXD which will ask you a bunch of question. Usually
|
||||||
|
|
46
ynh-dev
46
ynh-dev
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
lxc="sudo /snap/bin/lxc"
|
|
||||||
|
|
||||||
function show_usage() {
|
function show_usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
|
@ -115,10 +113,16 @@ function create_sym_link() {
|
||||||
|
|
||||||
function check_lxd_setup()
|
function check_lxd_setup()
|
||||||
{
|
{
|
||||||
local LXD_VERSION=$(lxd --version)
|
# Check lxd is installed somehow
|
||||||
|
[[ -e /snap/bin/lxd ]] || which lxd 2>/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" ]] \
|
# 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)
|
||||||
|| 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!)"
|
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 \
|
ip a | grep -q lxdbr0 \
|
||||||
|| critical "There is no 'lxdbr0' interface... Did you ran 'lxd init' ?"
|
|| critical "There is no 'lxdbr0' interface... Did you ran 'lxd init' ?"
|
||||||
|
@ -130,12 +134,12 @@ function start_ynhdev()
|
||||||
|
|
||||||
local BOX=${1:-ynh-dev}
|
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."
|
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."
|
||||||
$lxc image info $BOX-base &>/dev/null || critical "You should first build the base YunoHost LXC using ./ynh-dev rebuild"
|
sudo lxc image info $BOX-base &>/dev/null || critical "You should first build the base YunoHost LXC using ./ynh-dev rebuild"
|
||||||
set -eu
|
set -eu
|
||||||
set -x
|
set -x
|
||||||
$lxc launch $BOX-base $BOX
|
sudo lxc launch $BOX-base $BOX
|
||||||
$lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$PWD"
|
sudo lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$PWD"
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
attach_ynhdev $BOX
|
attach_ynhdev $BOX
|
||||||
|
@ -145,16 +149,16 @@ function attach_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxd_setup
|
check_lxd_setup
|
||||||
local BOX=${1:-ynh-dev}
|
local BOX=${1:-ynh-dev}
|
||||||
$lxc start $BOX 2>/dev/null || true
|
sudo lxc start $BOX 2>/dev/null || true
|
||||||
$lxc exec $BOX -- /bin/bash
|
sudo lxc exec $BOX -- /bin/bash
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroy_ynhdev()
|
function destroy_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxd_setup
|
check_lxd_setup
|
||||||
local BOX=${1:-ynh-dev}
|
local BOX=${1:-ynh-dev}
|
||||||
$lxc stop $BOX
|
sudo lxc stop $BOX
|
||||||
$lxc delete $BOX
|
sudo lxc delete $BOX
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuild_ynhdev()
|
function rebuild_ynhdev()
|
||||||
|
@ -164,14 +168,14 @@ function rebuild_ynhdev()
|
||||||
local BOX=${1:-ynh-dev}
|
local BOX=${1:-ynh-dev}
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
$lxc info $BOX-rebuild >/dev/null && $lxc delete $BOX-rebuild --force
|
sudo lxc info $BOX-rebuild >/dev/null && sudo lxc delete $BOX-rebuild --force
|
||||||
$lxc launch images:debian/stretch/amd64 $BOX-rebuild
|
sudo lxc launch images:debian/stretch/amd64 $BOX-rebuild
|
||||||
$lxc config set $BOX-rebuild security.privileged true
|
sudo lxc config set $BOX-rebuild security.privileged true
|
||||||
$lxc restart $BOX-rebuild
|
sudo lxc restart $BOX-rebuild
|
||||||
$lxc exec $BOX-rebuild -- apt install curl -y
|
sudo 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"
|
sudo lxc exec $BOX-rebuild -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable"
|
||||||
$lxc stop $BOX-rebuild
|
sudo lxc stop $BOX-rebuild
|
||||||
$lxc publish $BOX-rebuild --alias $BOX-base
|
sudo lxc publish $BOX-rebuild --alias $BOX-base
|
||||||
set +x
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue