diff --git a/.gitmodules b/.gitmodules index 1164564..aa494ad 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "modules/aports"] path = modules/aports url = https://git.alpinelinux.org/aports/ +[submodule "modules/bash-util"] + path = modules/bash-util + url = https://github.com/targetdisk/bash-util diff --git a/GNUmakefile b/GNUmakefile index 68f237f..47d36bb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,5 +1,5 @@ ARCH ?= x86_64 -PLATFORM ?= UEFI +PLATFORM ?= uefi DESTROOT ?= destroot REPO ?= repo DOSU ?= sudo @@ -8,6 +8,38 @@ PKGS ?= BUSYBOX ?= busybox APORTSDIR ?= $(APORTS_MODULE) SHELL := /usr/bin/env bash +BLKDEV ?= +ROOTFS_TYPE ?= btrfs +MOUNTPOINT ?= mnt + +RUNLEVEL_SYSINIT ?= devfs dmesg mdev hwdrivers +RUNLEVEL_SHUTDOWN ?= killprocs mount-ro savecache + +ifeq ($(PLATFORM),raspi) + include mk/raspi.mk +else ifeq ($(PLATFORM),uefi) + include mk/uefi.mk +endif + +RUNLEVEL_BOOT_CMDS := $(foreach SERVICE,$(RUNLEVEL_BOOT),\ + rc-update add $(SERVICE) boot &&) +RUNLEVEL_SYSINIT_CMDS := $(foreach SERVICE,$(RUNLEVEL_SYSINIT),\ + rc-update add $(SERVICE) sysinit &&) +RUNLEVEL_DEFAULT_CMDS := $(foreach SERVICE,$(RUNLEVEL_DEFAULT),\ + rc-update add $(SERVICE) default &&) +RUNLEVEL_SHUTDOWN_CMDS := $(foreach SERVICE,$(RUNLEVEL_SHUTDOWN),\ + rc-update add $(SERVICE) shutdown &&) + +RUNLEVEL_CMDS := $(RUNLEVEL_BOOT_CMDS) $(RUNLEVEL_SYSINIT_CMDS) \ + $(RUNLEVEL_DEFAULT_CMDS) $(RUNLEVEL_SHUTDOWN_CMDS) : + +ifneq (,$(findstring /dev/mmcblk,$(BLKDEV))) + P := p +else ifneq (,$(findstring /dev/nvme,$(BLKDEV))) + P := p +else + P := +endif GIMME_MODULE := git submodule update --init --recursive @@ -15,13 +47,18 @@ ABUILD_MODULE := modules/abuild ARCH_MODULE := modules/arch-install-scripts APK_MODULE := modules/apk-tools APORTS_MODULE := modules/aports +BASH_UTIL_MODULE := modules/bash-util ABUILD_SCRIPT := $(ABUILD_MODULE)/abuild APK_BIN := $(APK_MODULE)/src/apk ABUILD := $(BUSYBOX) ash $(CURDIR)/$(ABUILD_SCRIPT) -c -P $(CURDIR)/$(REPO) rootbld ACHROOT := $(ARCH_MODULE)/arch-chroot +ACHROOT_CMD := $(DOSU) $(ACHROOT) $(DESTROOT) /bin/sh -c '. /etc/profile' APK := LD_LIBRARY_PATH=$(APK_MODULE)/src $(APK_BIN) +BUTIL := . $(BASH_UTIL_MODULE) + +default-target: install ### TOOLS ### @@ -45,6 +82,9 @@ $(ABUILD_MODULE)/Makefile: .gitmodules $(ABUILD_SCRIPT): $(ABUILD_MODULE)/Makefile $(MAKE) -j -C $(ABUILD_MODULE) all +$(BASH_UTIL_MODULE)/Makefile: .gitmodules + $(GIMME_MODULE) -- $(BASH_UTIL_MODULE) + ### PORTS TREE ### $(APORTS_MODULE)/README.md: .gitmodules @@ -56,7 +96,7 @@ aports: $(APORTS_MODULE)/README.md # Something will go here... -### INSTALLATION ### +### BOOTSTRAPPING ### $(DESTROOT): mkdir -p $(DESTROOT) || $(DOSU) mkdir -p $(DESTROOT) @@ -65,16 +105,51 @@ $(DESTROOT)/.bootstrap-done: $(DESTROOT) $(APK_BIN) $(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \ -U --allow-untrusted --initdb add alpine-keys $(PKGS) && touch $@ $(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \ - add alpine-base $(PKGS) && touch $@ + add alpine-base btrfs-progs e2fsprogs $(PKGS) && touch $@ bootstrap: $(DESTROOT)/.bootstrap-done +### PARTITIONING ### + +blkcheck: $(BASH_UTIL_MODULE)/Makefile + @[ -z "$(BLKDEV)" ] && $(BUTIL)/logging.bash \ + && die 'ERROR: Must define BLKDEV env variable!' \ + || : + +format: partition + $(DOSU) mkfs.vfat $(BLKDEV)$(P)1 + $(DOSU) mkfs.$(ROOTFS_TYPE) $(BLKDEV)$(P)2 + +$(BLKDEV)$(P)2: partition + +### INSTALLATION ### + +services: $(DESTROOT)/.bootstrap-done $(ACHROOT) + $(ACHROOT_CMD)' && $(RUNLEVEL_CMDS)' + +fastest-repo: $(DESTROOT)/.bootstrap-done $(ACHROOT) + $(ACHROOT_CMD)' && setup-apkrepos -f' + +$(MOUNTPOINT): + mkdir -p $@ || $(DOSU) mkdir -p $@ + +mount: $(BLKDEV)$(P)2 $(MOUNTPOINT) + $(DOSU) mount $(BLKDEV)$(P)2 $(MOUNTPOINT) + $(DOSU) mkdir -p $(MOUNTPOINT)/boot + $(DOSU) mount $(BLKDEV)$(P)1 $(MOUNTPOINT)/boot + +install: services fastest-repo + ### CLEANLINESS ### clean: git submodule deinit -f -- \ - $(APK_MODULE) $(ABUILD_MODULE) $(APORTS_MODULE) $(ARCH_MODULE) + $(APK_MODULE) $(ABUILD_MODULE) $(APORTS_MODULE) $(ARCH_MODULE) \ + $(BASH_UTIL_MODULE) + $(DOSU) umount mnt/boot || : + $(DOSU) umount mnt || : $(DOSU) rm -rf destroot/* repo/* ### MAKEY-MAKEY ### -.PHONY: tools bootstrap aports +.PHONY: default-target tools bootstrap aports blkcheck format install \ + $(PLATFORM_PHONYS) diff --git a/mk/raspi.mk b/mk/raspi.mk new file mode 100644 index 0000000..f7d6a6b --- /dev/null +++ b/mk/raspi.mk @@ -0,0 +1,15 @@ +ifeq ($(ARCH),aarch64) +else ifeq ($(ARCH),armhf) +else ifeq ($(ARCH),armv7) +else + $(error $(ARCH) is unsupported on the raspi platform) +endif + +PLATFORM_PHONYS := partition kernel + +RUNLEVEL_BOOT ?= modules bootmisc hostname networking seedrng swap +RUNLEVEL_DEFAULT ?= crond + +partition: blkcheck + $(DOSU) fdisk $(BLKDEV) <<<$$'o\nw\n' + $(DOSU) sfdisk $(BLKDEV) <<<$$',1G,c,*\n,,83,\n' diff --git a/mk/uefi.mk b/mk/uefi.mk new file mode 100644 index 0000000..f00bf02 --- /dev/null +++ b/mk/uefi.mk @@ -0,0 +1,8 @@ +PLATFORM_PHONYS := partition kernel + +RUNLEVEL_BOOT ?= hwclock modules bootmisc hostname networking seedrng swap +RUNLEVEL_DEFAULT ?= acpid crond + +partition: blkcheck + $(DOSU) fdisk $(BLKDEV) <<<$$'g\nw\n' + $(DOSU) sfdisk $(BLKDEV) <<<$$',1G,C12A7328-F81F-11D2-BA4B-00A0C93EC93B,*\n,,0FC63DAF-8483-4772-8E79-3D69D8477DE4,\n' diff --git a/modules/bash-util b/modules/bash-util new file mode 160000 index 0000000..bd3ddab --- /dev/null +++ b/modules/bash-util @@ -0,0 +1 @@ +Subproject commit bd3ddab28f6a754e7ffc15e88257614aff0892ff