69 lines
2.4 KiB
Makefile
69 lines
2.4 KiB
Makefile
BASE_PKGS := alpine-keys alpine-baselayout
|
|
BOOT_HOST := 203.0.113.1
|
|
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
|
PROTO := http
|
|
MIRROR := $(PROTO)://$(BOOT_HOST)/alpine/extended
|
|
|
|
all: base packages files commands build-overlay
|
|
|
|
base:
|
|
@echo " * Building Base Image..."
|
|
@ping -qW 1 -c 1 $(BOOT_HOST) >/dev/null || ( echo " -- Unable to reach $(BOOT_HOST)" && exit 1 )
|
|
@mkdir -p tmp base
|
|
@echo " -- Gathering base package info"
|
|
@wget -q $(MIRROR)/x86_64/ -O tmp/alpine-packages.html
|
|
@for pkg in $(BASE_PKGS); do \
|
|
pkgver=$$(grep \"$$pkg tmp/alpine-packages.html | egrep -o [0-9]+\.[0-9]+[0-9.]*-r[0-9]+ | uniq); \
|
|
wget -q $(MIRROR)/x86_64/$${pkg}-$${pkgver}.apk -O tmp/$${pkg}-$${pkgver}.apk; \
|
|
done
|
|
@echo " -- Create Base Layout"
|
|
@tar xzf tmp/alpine-keys-*.apk -C base 2>/dev/null
|
|
@tar xzf tmp/alpine-baselayout-*.apk -C base etc/shadow etc/hosts etc/group etc/passwd 2>/dev/null
|
|
@echo " -- Setup Init"
|
|
@for runlevel in boot default shutdown sysinit; do \
|
|
mkdir -p base/etc/runlevels/$$runlevel; done
|
|
@for initd in bootmisc hostname hwclock modules sysctl syslog networking; do \
|
|
ln -s /etc/init.d/$$initd base/etc/runlevels/boot/$$initd; done
|
|
@for initd in devfs dmesg hwdrivers mdev modloop; do \
|
|
ln -s /etc/init.d/$$initd base/etc/runlevels/sysinit/$$initd; done
|
|
@for initd in killprocs mount-ro savecache; do \
|
|
ln -s /etc/init.d/$$initd base/etc/runlevels/shutdown/$$initd; done
|
|
@sudo rm -rf tmp
|
|
|
|
.PHONY: packages
|
|
packages: base
|
|
@test \! -d target && echo " * Cloning base to target..." \
|
|
&& sudo rsync -raH base/ target || true
|
|
@if [ \! -f packages ]; then \
|
|
echo " * No packages to Install"; \
|
|
elif diff -q packages target/etc/apk/world 2>/dev/null >/dev/null; then true; \
|
|
else \
|
|
echo " * Updating apk/world file..."; \
|
|
cp packages target/etc/apk/world; \
|
|
fi
|
|
|
|
.PHONY: files
|
|
files: packages
|
|
@echo " * Copying Files..."
|
|
@sudo cp -rv files/* target
|
|
|
|
.PHONY: commands
|
|
commands: files
|
|
@echo " * Running Commands..."
|
|
@echo " -- Setup local start"
|
|
@ln -s /etc/init.d/local target/etc/runlevels/default/local 2>/dev/null || true
|
|
|
|
.PHONY: build-overlay
|
|
build-overlay: commands
|
|
@echo " * Building Overlay..."
|
|
@mkdir -p tmp output
|
|
@sudo rsync -raH target/ tmp/overlay
|
|
@sudo chown -R root:root tmp/overlay
|
|
@cd tmp/overlay; sudo tar czf $(ROOT_DIR)/output/apkovl.tar.gz .
|
|
@sudo rm -rf tmp
|
|
|
|
clean:
|
|
@echo " * Cleaning Up"
|
|
@sudo rm -rf base tmp output target
|
|
|