You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.4 KiB
Makefile

6 years ago
MAINTAINER?==@eater.me
# Docker executable to use (default: docker, but img may be used)
DOCKER_EXEC?=docker
6 years ago
# Name of image
IMAGE?=d.xr.to/base
6 years ago
# Arch to be used
ARCH?=x86_64-musl
6 years ago
# Repo root url to be used (/musl will be appended in case of musl based arch)
REPO_ROOT?=https://repo-default.voidlinux.org/current
6 years ago
# Absolute repo url
REPO?=$(REPO_ROOT)$(if $(findstring musl, $(ARCH)),/musl)
# Toolbox to be used (toybox, busybox, none or default)
TOOLBOX?=toybox
6 years ago
# Packages to install
6 years ago
PACKAGES?=xbps bash ncurses-base shadow
6 years ago
# Directory where chroot should be build
BUILDDIR?=$(PWD)/build
5 years ago
ifeq ($(TOOLBOX),none)
VALID_TOOLBOX?=1
endif
ifeq ($(TOOLBOX),)
override TOOLBOX=none
VALID_TOOLBOX?=1
endif
ifeq ($(TOOLBOX),toybox)
override PACKAGES += toybox
VALID_TOOLBOX?=1
endif
ifeq ($(TOOLBOX),busybox)
override PACKAGES += busybox
VALID_TOOLBOX?=1
endif
ifeq ($(TOOLBOX),default)
override PACKAGES += findutils coreutils diffutils gawk which sed gzip file grep
VALID_TOOLBOX?=1
endif
6 years ago
default: all
vars:
6 years ago
@echo MAINTAINER=$(MAINTAINER)
5 years ago
@echo DOCKER_EXEC=$(DOCKER_EXEC)
6 years ago
@echo IMAGE=$(IMAGE)
@echo ARCH=$(ARCH)
@echo REPO_ROOT=$(REPO_ROOT)
@echo REPO=$(REPO)
@echo TOOLBOX=$(TOOLBOX)
@echo VALID_TOOLBOX=$(VALID_TOOLBOX)
6 years ago
@echo PACKAGES=$(PACKAGES)
@echo BUILDDIR=$(BUILDDIR)
ensure-toolbox:
ifneq ($(VALID_TOOLBOX),1)
@echo "Please make sure TOOLBOX is none, toybox (default option), busybox or default"
exit 1
endif
build: ensure-toolbox
6 years ago
# Create build directory
mkdir $(BUILDDIR)
# Create keys database directory
mkdir -p $(BUILDDIR)/var/db/xbps $(BUILDDIR)/etc
6 years ago
# Import known keys
cp -r keys $(BUILDDIR)/var/db/xbps
# Create passwd, shadow and group file
cp files/passwd $(BUILDDIR)/etc/passwd
cp files/group $(BUILDDIR)/etc/group
cp files/shadow $(BUILDDIR)/etc/shadow
6 years ago
# Install packages into build directory
XBPS_ARCH="$(ARCH)" xbps-install -y -r $(BUILDDIR) --repository=$(REPO) -S $(PACKAGES)
# Create symlinks expected by void
for dir in lib lib32 sbin bin; do [ -e $(BUILDDIR)/$$dir ] || ln -s usr/$$dir $(BUILDDIR)/$$dir; done
ln -s usr/lib $(BUILDDIR)/lib64
# Create default directories expected by void
6 years ago
for dir in proc sys dev tmp run; do [ -d $(BUILDDIR)/$$dir ] || mkdir $(BUILDDIR)/$$dir; done
ifeq ($(TOOLBOX),toybox)
6 years ago
# Create toybox symlinks
xbps-uchroot $(BUILDDIR) /bin/toybox | sed 's:\s:\n:g' | grep -v '^$$' | while read i; do [ -e $(BUILDDIR)/usr/bin/$$i ] || ln -s /bin/toybox $(BUILDDIR)/usr/bin/$$i; done
endif
ifeq ($(TOOLBOX),busybox)
# Create busybox symlinks
xbps-uchroot $(BUILDDIR) /bin/busybox -- --list | while read i; do [ -e $(BUILDDIR)/usr/bin/$$i ] || ln -s /bin/busybox $(BUILDDIR)/usr/bin/$$i; done
endif
6 years ago
# Remove xbps cache dir
6 years ago
rm -rf $(BUILDDIR)/var/cache/xbps
# Import custom bashrc
cp files/bashrc.bash $(BUILDDIR)/etc/bash/bashrc.d/docker.sh
# Create os-release file
cp files/os-release $(BUILDDIR)/etc/os-release
# Create lsb_release file
cp files/lsb_release $(BUILDDIR)/bin/lsb_release
chmod +x $(BUILDDIR)/bin/lsb_release
# Create xbps helpers
cp files/xbps-remote $(BUILDDIR)/bin/xbps-remote
chmod +x $(BUILDDIR)/bin/xbps-remote
cp files/xbps-local $(BUILDDIR)/bin/xbps-local
chmod +x $(BUILDDIR)/bin/xbps-local
6 years ago
install: build
# Import directory as tar (owned by root) into docker
tar --owner 0 --group 0 -pC $(BUILDDIR) -c . | $(DOCKER_EXEC) import -m '$(IMAGE) initialization from chroot' -c 'LABEL maintainer="$(MAINTAINER)"' - $(IMAGE)
6 years ago
clean:
# Remove build directory
rm -rf $(BUILDDIR)
all: install clean