diff --git a/README.md b/README.md index 0d78196..bb6241c 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Then test your packages : ## You can start a container on a different architecture with some hacks -Install the package `binfmt-support`, then list of all available images : +Install the package `qemu-user-static` and `binfmt-support`, then list of all available images : ``` lxc image list images:debian/buster @@ -131,7 +131,7 @@ lxc launch test-arm lxc exec inspired-lamprey -- dpkg --print-architecture ``` -We must add this feature to the package_check in the future +If the `build_base_lxc.sh` script detects that you are trying a cross container architecture, it will try to perform this hack ## Syntax of `check_process` > Except spaces, the syntax of this file must be respected. diff --git a/build_base_lxc.sh b/build_base_lxc.sh index 876a9b4..0d2a2a3 100755 --- a/build_base_lxc.sh +++ b/build_base_lxc.sh @@ -3,13 +3,39 @@ cd $(dirname $(realpath $0)) source "./lib/common.sh" +function launch_new_lxc() +{ + lxc info $LXC_BASE >/dev/null && lxc delete $LXC_BASE --force + + if [ $(get_arch) = $ARCH ]; + then + lxc launch images:debian/$DIST/$ARCH $LXC_BASE -c security.privileged=true -c security.nesting=true + else + lxc image info $LXC_BASE >/dev/null && lxc image delete $LXC_BASE + + tmp_dir=$(mktemp -d) + pushd $tmp_dir + + lxc image export images:debian/$DIST/$ARCH + + tar xJf lxd.tar.xz + local current_arch=$(get_arch) + sed -i "0,/architecture: $ARCH/s//architecture: $current_arch/" metadata.yaml + tar cJf lxd.tar.xz metadata.yaml templates + lxc image import lxd.tar.xz rootfs.squashfs --alias $LXC_BASE + popd + rm -rf "$tmp_dir" + + lxc launch $LXC_BASE $LXC_BASE -c security.privileged=true -c security.nesting=true + fi +} + function rebuild_base_lxc() { check_lxd_setup set -x - lxc info $LXC_BASE >/dev/null && lxc delete $LXC_BASE --force - lxc launch images:debian/$DIST/$ARCH $LXC_BASE -c security.privileged=true -c security.nesting=true + launch_new_lxc sleep 5 IN_LXC="lxc exec $LXC_BASE --" @@ -44,6 +70,7 @@ function rebuild_base_lxc() lxc stop $LXC_BASE lxc image delete $LXC_BASE lxc publish $LXC_BASE --alias $LXC_BASE + lxc delete $LXC_BASE set +x } diff --git a/lib/common.sh b/lib/common.sh index c53330c..1bed34b 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -3,8 +3,8 @@ ARCH="amd64" DIST="buster" -# By default we'll install Yunohost with the default branch -YNH_INSTALL_SCRIPT_BRANCH="" +# Yunohost version: stable, testing or unstable +YNH_BRANCH="stable" # Admin password YUNO_PWD="admin" @@ -16,11 +16,11 @@ SUBDOMAIN="sub.$DOMAIN" # User de test TEST_USER="package_checker" -LXC_BASE="ynh-appci-$DIST-$ARCH-base" -LXC_NAME="ynh-appci-test" - [[ -e "./config" ]] && source "./config" +LXC_BASE="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-base" +LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test" + readonly lock_file="./pcheck.lock" clean_exit () { @@ -277,3 +277,23 @@ function fetch_or_upgrade_package_linter() echo "$check_version" > "$version_file" } +#================================================= +# GET HOST ARCHITECTURE +#================================================= + +function get_arch() +{ + local architecture + if uname -m | grep -q "arm64" || uname -m | grep -q "aarch64"; then + architecture="aarch64" + elif uname -m | grep -q "64"; then + architecture="amd64" + elif uname -m | grep -q "86"; then + architecture="i386" + elif uname -m | grep -q "arm"; then + architecture="armhf" + else + architecture="unknown" + fi + echo $architecture +}