Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ tmp
*.pyo
*.tar.bz2
.mypy_cache
.ruff_cache
__pycache__
tags
fab.egg-info/
2 changes: 1 addition & 1 deletion contrib/fab-rewind
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ undeck() {
stop_services "$targ"
if [[ "$targ" == "cdroot" ]]; then
rm -rf build/product.iso
rm -rf "build/$targ"
else
deck -D "build/$targ"
fi
Expand All @@ -93,6 +92,7 @@ mount_if_not_mounted() {
fi
}

# cdroot is not a deck - but 'undeck' handles it anyway
undeck cdroot
undeck root.sandbox

Expand Down
6 changes: 3 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Depends:
${shlibs:Depends},
turnkey-chroot,
python3-debian,
pool
Recommends:
xorriso,
squashfs-tools
squashfs-tools,
Recommends:
pool,
Suggests:
dd,
wodim,
Expand Down
13 changes: 13 additions & 0 deletions fab
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ def cmd_chroot(
environ["USER"] = "root"
environ["UID"] = "0"
environ["EUID"] = "0"

os_environ_debug = "\n".join(
sorted([f" {k}: {v}" for k, v in os.environ.items()])
)
chr_environ_debug = "\n".join(
sorted([f" {k}: {v}" for k, v in environ.items()])
)
logger.debug(
"cmd_chroot()"
f"\nchroot = Chroot({chroot_path}, {environ=})"
f"\n\nfull env:\n---------\n{os_environ_debug}"
f"\n\nchroot env:\n-----------\n{chr_environ_debug}"
)
chroot = Chroot(chroot_path, environ=environ)

if not script_args and not script_path_raw:
Expand Down
2 changes: 1 addition & 1 deletion fablib/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from re import Match
from tempfile import TemporaryDirectory

from debian import debfile
from debian import deb822


def parse_plan(plan: str) -> set[str]:
Expand Down
2 changes: 1 addition & 1 deletion fablib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import TextIO, cast

from chroot import Chroot
from debian import debfile
from debian import deb822, debfile

from fablib import common

Expand Down
103 changes: 103 additions & 0 deletions share/load_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
# This script is called by /usr/share/fab/product.mk.
# It sets the needed environment variables once, so make doesn't need to keep
# recalculating them


_echo() {
# Because we call this script directly from the top of the make file/s,
# make will expect anything sent to stdout to be valid make commands.
# However stderr is ignored by make, so ALL output to users needs to be
# sent to stderr.
echo "$*" >&2
}
fatal() { _echo "Fatal: $*"; exit 1; }

[[ -n "$FAB_PATH" ]] || fatal "FAB_PATH not set - required for default paths"

if [[ -z "$RELEASE" ]]; then
_distro="$(lsb_release -si)"
DISTRO="${_distro,,}"
CODENAME="$(lsb_release -sc)"
RELEASE="$DISTRO/$CODENAME"
_echo "RELEASE not set - falling back to system: $RELEASE"
else
DISTRO="$(dirname "$RELEASE")"
CODENAME="$(basename "$RELEASE")"
fi

DEBIAN=
UBUNTU=
case $DISTRO in
debian)
DEBIAN=y;;
ubuntu)
UBUNTU=y;;
*)
fatal "Distro '$DISTRO' not supported"
esac

AMD64=
ARM64=
FAB_ARCH_FAMILY=
if [[ -z "$FAB_ARCH" ]]; then
FAB_ARCH="$(dpkg --print-architecture)"
_echo "FAB_ARCH not set - falling back to system: $FAB_ARCH"
fi
case $FAB_ARCH in
amd64)
AMD64=y
FAB_ARCH_FAMILY=x86
;;
arm64)
ARM64=y
FAB_ARCH_FAMILY=arm
;;
*)
fatal "Architecture '$FAB_ARCH' not supported"
;;
esac

if [[ -n "$FAB_POOL" ]]; then
FAB_POOL_PATH="$FAB_PATH/pools/$CODENAME"
FAB_INSTALL_OPTS="$FAB_INSTALL_OPTS --no-deps"
fi

if [[ "${NO_PROXY,,}" == "true" ]]; then
_echo "NO_PROXY set - disabling caching proxies"
FAB_HTTP_PROXY=
FAB_HTTPS_PROXY=
else
[[ -n "$FAB_HTTP_PROXY" ]] || _echo "Warning - FAB_HTTP_PROXY not set"
[[ -n "$FAB_HTTPS_PROXY" ]] || _echo "Warning - FAB_HTTPS_PROXY not set"
fi

cat > /tmp/.build_env <<EOF
FAB_PATH=$FAB_PATH
DISTRO=$DISTRO
CODENAME=$CODENAME
RELEASE=$RELEASE

DEBIAN=$DEBIAN
UBUNTU=$UBUNTU

FAB_ARCH=$FAB_ARCH
AMD64=$AMD64
ARM64=$ARM64
FAB_ARCH_FAMILY=$FAB_ARCH_FAMILY
FAB_INSTALL_OPTS="--arch $FAB_ARCH"

FAB_POOL=$FAB_POOL
FAB_POOL_PATH=${FAB_POOL_PATH:-$FAB_PATH/pools/$CODENAME}

BOOTSTRAP=${BOOTSTRAP:-$FAB_PATH/bootstraps/$CODENAME-$FAB_ARCH}
CDROOT=${CDROOT:-generic}
MKSQUASHFS=${MKSQUASHFS:-/usr/bin/mksquashfs}
PLAN=${PLAN:-plan/main}
REMOVELIST=${REMOVELIST:-removelist}
O=${O:-build}
ISOLABEL=${ISOLABEL:-$(basename "$PWD")}
STAMPS_DIR=${STAMPS_DIR:-$O/stamps}
DEBIAN=$DEBIAN
UBUNTU=$UBUNTU
EOF
73 changes: 11 additions & 62 deletions share/product.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,10 @@
# 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

ifndef RELEASE
$(error RELEASE not defined)
endif

ifndef FAB_ARCH
$(info FAB_ARCH not set, falling back to system arch $(HOST_ARCH))
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')


AMD64 = $(shell [ $(FAB_ARCH) = 'amd64' ] && echo 'y')
ARM64 = $(shell [ $(FAB_ARCH) = 'arm64' ] && echo 'y')

ifndef FAB_ARCH_FAMILY
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

ifndef FAB_ARCH_FAMILY
$(error unsupported architecture family)
endif
endif

ifdef FAB_POOL
FAB_POOL_PATH=$(FAB_PATH)/pools/$(CODENAME)
#export FAB_POOL_PATH
endif

ifdef FAB_POOL_PATH
FAB_INSTALL_OPTS += '--no-deps'
endif

ifndef FAB_HTTP_PROXY
$(warning FAB_HTTP_PROXY is not defined)
endif

ifndef FAB_HTTPS_PROXY
$(warning FAB_HTTPS_PROXY is not defined)
endif
# execute script to load/calculate env vars and write to tmp file, then load
# them from the tmp file - not ideal but no secrets/sensitive info saved
$(shell /usr/share/fab/load_env)
include /tmp/.build_env

COMMON_PATCHES := turnkey.d $(COMMON_PATCHES)

Expand All @@ -78,9 +24,9 @@ endef
_CONF_VARS_BUILTIN = $(call filter-undefined-vars,$(CONF_VARS_BUILTIN))
_CONF_VARS = $(_CONF_VARS_BUILTIN) $(call filter-undefined-vars,$(CONF_VARS))

#export $(_CONF_VARS)
#export FAB_CHROOT_ENV = $(shell echo $(_CONF_VARS) | sed 's/ \+/:/g')
#export FAB_INSTALL_ENV = $(FAB_CHROOT_ENV)
export $(_CONF_VARS)
export FAB_CHROOT_ENV = $(shell echo $(_CONF_VARS) | sed 's/ \+/:/g')
export FAB_INSTALL_ENV = $(FAB_CHROOT_ENV)
FAB_CHROOT_ENV = $(shell echo $(_CONF_VARS) | sed 's/ \+/:/g')
FAB_INSTALL_ENV = $(FAB_CHROOT_ENV)

Expand Down Expand Up @@ -125,7 +71,7 @@ _COMMON_REMOVELISTS = $(call prefix-relative-paths,$(COMMON_REMOVELISTS),$(COMMO
_COMMON_REMOVELISTS_FINAL = $(call prefix-relative-paths,$(COMMON_REMOVELISTS_FINAL),$(COMMON_REMOVELISTS_FINAL_PATH))

FAB_PLAN_INCLUDE_PATH ?= $(FAB_PATH)/common/plans
#export FAB_PLAN_INCLUDE_PATH
export FAB_PLAN_INCLUDE_PATH

# default locations of product build inputs
PLAN ?= plan/main
Expand Down Expand Up @@ -251,6 +197,9 @@ define help/body
@echo ' KERNEL Override default kernel package'
@echo ' EXTRA_PLAN Extra packages to include in the plan'
@echo ' CHROOT_ONLY Build a chroot-only product'
@echo ' TKL_TESTING=y Enable TurnKey testing apt repo'
@echo ' NO_PROXY=true Disable local squid proxy'


@echo
@echo '=== Usage'
Expand Down