diff --git a/.gitignore b/.gitignore index 2c1b1b4..0c5d44e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ destroot repo +mnt +README.html +pandoc.css 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..722c3f9 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,52 @@ 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 + +ifeq ($(ROOTFS_TYPE),btrfs) + include mk/btrfs.mk +else + include mk/simplefs.mk +endif + +ifneq (,$(WAYLAND_DISPLAY)) + XDG_BASEDIR := $(shell dirname $(XDG_RUNTIME_DIR)) + WAYLAND_ASSIST := env WAYLAND_DISPLAY="$(XDG_RUNTIME_DIR)/$(WAYLAND_DISPLAY)" \ + XDG_BASEDIR="$(XDG_BASEDIR)/0" +else + WAYLAND_ASSIST := +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 +61,20 @@ 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 +GENFSTAB := $(ARCH_MODULE)/genfstab +ACHROOT_CMD := $(DOSU) $(ACHROOT) $(DESTROOT) /bin/sh -c '. /etc/profile' +ACHROOTI_CMD := $(DOSU) $(ACHROOT) $(MOUNTPOINT) /bin/sh -c '. /etc/profile' APK := LD_LIBRARY_PATH=$(APK_MODULE)/src $(APK_BIN) +BUTIL := . $(BASH_UTIL_MODULE) + +default-target: install ### TOOLS ### @@ -33,6 +86,9 @@ $(ARCH_MODULE)/Makefile: .gitmodules $(ACHROOT): $(ARCH_MODULE)/Makefile $(MAKE) -j -C $(ARCH_MODULE) arch-chroot +$(GENFSTAB): $(ARCH_MODULE)/Makefile + $(MAKE) -j -C $(ARCH_MODULE) genfstab + $(APK_MODULE)/Makefile: .gitmodules $(GIMME_MODULE) -- $(APK_MODULE) @@ -45,6 +101,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,25 +115,107 @@ aports: $(APORTS_MODULE)/README.md # Something will go here... -### INSTALLATION ### +### BOOTSTRAPPING ### $(DESTROOT): mkdir -p $(DESTROOT) || $(DOSU) mkdir -p $(DESTROOT) $(DESTROOT)/.bootstrap-done: $(DESTROOT) $(APK_BIN) $(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \ - -U --allow-untrusted --initdb add alpine-keys $(PKGS) && touch $@ + -U --allow-untrusted --initdb add alpine-keys && touch $@ $(DOSU) $(APK) --arch $(ARCH) -X $(ALPINE_REPO) --root $(DESTROOT) \ - add alpine-base $(PKGS) && touch $@ + add alpine-base btrfs-progs e2fsprogs $(PLATFORM_PKGS) $(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) -f $(BLKDEV)$(P)2 + +$(BLKDEV)$(P)2: partition + +### INSTALLATION ### + +$(DESTROOT)/.services-done: $(DESTROOT)/.bootstrap-done $(ACHROOT) + $(ACHROOT_CMD)' && $(RUNLEVEL_CMDS)' + $(DOSU) touch $@ + +services: $(DESTROOT)/.services-done + +$(DESTROOT)/.fastrepo-done: $(DESTROOT)/.bootstrap-done $(ACHROOT) + $(ACHROOT_CMD)' && setup-apkrepos -f' + $(DOSU) touch $@ + +fastest-repo: $(DESTROOT)/.fastrepo-done + +$(MOUNTPOINT): + mkdir -p $@ || $(DOSU) mkdir -p $@ + +$(MOUNTPOINT)/etc/fstab: $(GENFSTAB) mount + $(GENFSTAB) -U $(MOUNTPOINT) | $(DOSU) tee $@ + +fstab: $(MOUNTPOINT)/etc/fstab + +mount: $(MOUNTPOINT)/.mount-done + +$(MOUNTPOINT)/.install-done: fstab services fastest-repo + @[ -z "$(MOUNTPOINT)" ] && $(BUTIL)/logging.bash \ + && die 'ERROR: Must define MOUNTPOINT env variable!' \ + || : + $(DOSU) rsync -aAXHv \ + --exclude=$(DESTROOT)'/dev/*' \ + --exclude=$(DESTROOT)'/proc/*' \ + --exclude=$(DESTROOT)'/sys/*' \ + --exclude=$(DESTROOT)'/tmp/*' \ + --exclude=$(DESTROOT)'/run/*' \ + --exclude=$(DESTROOT)'/mnt/*' \ + --exclude=$(DESTROOT)'/media/*' \ + --exclude=$(DESTROOT)'/lost+found/' \ + $(DESTROOT)/ $(MOUNTPOINT) + $(DOSU) touch $@ + +install: $(MOUNTPOINT)/.install-done + +bootloader: $(MOUNTPOINT)/.bootloader-done + +### POST-INSTALL TOOLS ### + +# Launch a shell into the installed volume +install-chroot: $(MOUNTPOINT)/.install-done $(ACHROOT) + $(ACHROOTI_CMD)' && sh' + +# Launch a shell into the local bootstrapped root +chroot: $(DESTROOT)/.bootstrap-done $(ACHROOT) + $(ACHROOT_CMD)' && sh' + ### CLEANLINESS ### -clean: +clean: umount git submodule deinit -f -- \ - $(APK_MODULE) $(ABUILD_MODULE) $(APORTS_MODULE) $(ARCH_MODULE) + $(APK_MODULE) $(ABUILD_MODULE) $(APORTS_MODULE) $(ARCH_MODULE) \ + $(BASH_UTIL_MODULE) $(DOSU) rm -rf destroot/* repo/* ### MAKEY-MAKEY ### -.PHONY: tools bootstrap aports +.PHONY: default-target tools bootstrap aports blkcheck format install \ + $(PLATFORM_PHONYS) mount fstab chroot + +### DOCS ################ Require Pandoc to be installed ############## DOCS ### + +pandoc.css: + wget https://sqt.wtf/~targetdisk/pandoc.css + +# Requires Pandoc to be installed +README.html: README.md pandoc.css + pandoc $< -s -c pandoc.css -o $@ + +README: README.html + xdg-open $< diff --git a/README.md b/README.md index 14fc2d4..9e4e6dc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Alpstrap -These are my scripts for brining up an Alpine system! +These are my scripts for bringing up an Alpine system! ## DEPENDENCIES - A sane shell like GNU Bash @@ -8,10 +8,67 @@ These are my scripts for brining up an Alpine system! - GNU `install` (from coreutils) - M4 - GNU Autoconf +- `qemu-user-static` and its `binfmt` rules (for cross-chrooting) You may need to install some Lua dependencies for building `apk`. If you feel you've already installed them and it's still failing, double-check the Lua version that `apk`'s build requires! +## USING + +### TL;DR, where's the cheat sheet? +Set your `PLATFORM`, `ARCH`, and `BLKDEV` to bootstrap to: +```bash +export PLATFORM=raspi ARCH=aarch64 BLKDEV=/dev/sdb +``` + +>