diff --git a/contrib/install-arm-on-amd-deps b/contrib/install-arm-on-amd-deps new file mode 100755 index 0000000..2a43f7f --- /dev/null +++ b/contrib/install-arm-on-amd-deps @@ -0,0 +1,65 @@ +#!/bin/bash -eu + +DEBUG=${DEBUG:-} +[[ -z "$DEBUG" ]] || set -x + +QUIET= +pkgs=(binfmt-support qemu-system-arm qemu-user-static) +bins=(/usr/sbin/update-binfmts /usr/bin/qemu-system-arm /usr/bin/qemu-arm-static) +pkgs_to_install=() + +usage() { + cat <&2 + exit 1;; + esac + shift +done + +for i in "${!pkgs[@]}"; do + if ! which "${bins[$i]}" >/dev/null 2>&1; then + pkgs_to_install+=("${pkgs[$i]}") + fi +done + +set +u # unset u - otherwise the test will give an "unbound variable" error +# shellcheck disable=SC2128 +# even if there are no elements in a array; ${foo[@]} still isn't "empty" +if [[ -n "$pkgs_to_install" ]]; then + if [[ -n "$QUIET" ]]; then + echo "Installing: ${pkgs_to_install[*]}" + apt-get update + apt-get install -y "${pkgs_to_install[@]}" + echo "" + else + apt-get update >/dev/null 2>&1 + apt-get install -y "${pkgs_to_install[@]}" >/dev/null 2>&1 + fi +fi + +update-binfmts --display | grep -i"$QUIET" aarch diff --git a/debian/control b/debian/control index 25646bf..e258586 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Build-Depends: Standards-Version: 4.0.0 Package: fab -Architecture: any +Architecture: all Depends: cpp, ${misc:Depends}, @@ -25,4 +25,7 @@ Recommends: Suggests: dd, wodim, + binfmt-support, + qemu-system-arm, + qemu-user-static Description: TurnKey GNU/Linux product fabrication framework diff --git a/debian/install b/debian/install index 94dbb94..d7d6198 100644 --- a/debian/install +++ b/debian/install @@ -1,2 +1,3 @@ share/* usr/share/fab contrib/fab-* usr/bin +contrib/install-arm-on-amd-deps usr/bin diff --git a/fab b/fab index 2958a9b..4159609 100755 --- a/fab +++ b/fab @@ -25,7 +25,7 @@ import sys import os from os.path import isdir, join, basename, relpath -from debian import debfile +from debian import debfile, deb822 from fablib.installer import (PoolInstaller, LiveInstaller, Installer) @@ -96,7 +96,7 @@ class AssociatedAppendAction(argparse.Action): setattr(namespace, self.dest, [(option_string, values)]) -def generate_index(dctrls: Dict[Dependency, debfile.Deb822]) -> str: +def generate_index(dctrls: Dict[Dependency, deb822.Deb822]) -> str: fields = ( "Package", "Essential", diff --git a/share/product.mk b/share/product.mk index 190cb28..c44abd5 100755 --- a/share/product.mk +++ b/share/product.mk @@ -8,6 +8,8 @@ # Free Software Foundation; either version 3 of the License, or (at your # option) any later version. +HOST_ARCH := $(shell dpkg --print-architecture) + ifndef FAB_PATH $(error FAB_PATH not defined - needed for default paths) endif @@ -16,27 +18,38 @@ ifndef RELEASE $(error RELEASE not defined) endif +ifdef FAB_ARCH +ifneq ($(FAB_ARCH),$(HOST_ARCH)) +$(info building $(FAB_ARCH) on $(HOST_ARCH)) +ifeq ($(HOST_ARCH),arm64) +$(error amd64 product can not be built on arm64) +endif +endif +else +FAB_ARCH := $(HOST_ARCH) +endif + DISTRO ?= $(shell dirname $(RELEASE)) CODENAME ?= $(shell basename $(RELEASE)) UBUNTU = $(shell [ $(DISTRO) = 'ubuntu' ] && echo 'y') DEBIAN = $(shell [ $(DISTRO) = 'debian' ] && echo 'y') -FAB_ARCH ?= $(shell dpkg --print-architecture) - -I386 = $(shell [ $(FAB_ARCH) = 'i386' ] && echo 'y') AMD64 = $(shell [ $(FAB_ARCH) = 'amd64' ] && echo 'y') ARM64 = $(shell [ $(FAB_ARCH) = 'arm64' ] && echo 'y') ifndef FAB_ARCH_FAMILY ifeq ($(I386),y) FAB_ARCH_FAMILY=x86 +FAB_INSTALL_OPTS := '--arch i386' endif ifeq ($(AMD64),y) FAB_ARCH_FAMILY=x86 +FAB_INSTALL_OPTS := '--arch amd64' endif ifeq ($(ARM64),y) FAB_ARCH_FAMILY=arm +FAB_INSTALL_OPTS := '--arch arm64' # NONFREE is used to get raspi-firmware and firmware-brcm80211 # NONFREE=1 endif @@ -52,7 +65,7 @@ export FAB_POOL_PATH endif ifdef FAB_POOL_PATH -FAB_INSTALL_OPTS = '--no-deps' +FAB_INSTALL_OPTS += '--no-deps' endif ifndef FAB_HTTP_PROXY @@ -65,7 +78,7 @@ endif COMMON_PATCHES := turnkey.d $(COMMON_PATCHES) -CONF_VARS_BUILTIN ?= FAB_ARCH FAB_HTTP_PROXY I386 AMD64 ARM64 RELEASE DISTRO CODENAME DEBIAN UBUNTU KERNEL DEBUG CHROOT_ONLY +CONF_VARS_BUILTIN ?= FAB_ARCH HOST_ARCH FAB_HTTP_PROXY AMD64 ARM64 RELEASE DISTRO CODENAME DEBIAN UBUNTU KERNEL DEBUG CHROOT_ONLY define filter-undefined-vars $(foreach var,$1,$(if $($(var)), $(var))) @@ -80,9 +93,12 @@ export FAB_INSTALL_ENV = $(FAB_CHROOT_ENV) # FAB_PATH dependent infrastructural components FAB_SHARE_PATH ?= /usr/share/fab -BOOTSTRAP ?= $(FAB_PATH)/bootstraps/$(CODENAME) -ifneq ("$(wildcard $(FAB_PATH)/altstraps/$(CODENAME).core)", "") - BOOTSTRAP := $(FAB_PATH)/altstraps/$(CODENAME).core +BOOTSTRAP ?= $(FAB_PATH)/bootstraps/$(CODENAME)-$(FAB_ARCH) +ifneq ("$(wildcard $(FAB_PATH)/altstraps/$(CODENAME)-$(FAB_ARCH).core)", "") +BOOTSTRAP := $(FAB_PATH)/altstraps/$(CODENAME)-$(FAB_ARCH).core +endif +ifeq (,"$(wildcard $(BOOTSTRAP)")) +$(error bootstrap $(BOOTSTRAP) not found - download or build it first) endif CDROOTS_PATH ?= $(FAB_PATH)/cdroots @@ -123,7 +139,7 @@ PLAN ?= plan/main ROOT_OVERLAY ?= overlay CDROOT_OVERLAY ?= cdroot.overlay REMOVELIST ?= removelist -# undefine REMOVELIST if the file doesn't exist +# unset REMOVELIST if the file doesn't exist ifeq ($(wildcard $(REMOVELIST)),) REMOVELIST = endif