From 07accc3f94e74361f884f2c29556c9104f9da332 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 26 Jun 2019 15:47:04 -0400 Subject: Add makefile target "user-account" The target creates a user account and ensures its home directory is on a btrfs filesystem (creating one if necessary). Btrfs is necessary for fsmgr; it relies on "cp --reflink" --- Makefile | 21 ++++++++++++++++++--- user.mk | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 user.mk diff --git a/Makefile b/Makefile index 22993e0..8377a69 100644 --- a/Makefile +++ b/Makefile @@ -48,16 +48,31 @@ else ln -sf /var/cache/kiki/config/tor/hostname ${instdir}/etc/hostname endif +include user.mk + .PHONY: rootfs rootfs: - make -C fsmgr - make -C fsmgr install - make -C rootfs + : git submodule update + $(MAKE) -C fsmgr + $(MAKE) -C fsmgr install + $(MAKE) -C rootfs sudo ln -sf "$$PWD"/rootfs/samizdat.btrfs /srv/nbd/samizdat.btrfs boot: rootfs sudo qemu.sh +reuse_child := $(shell 2>/dev/null read child < reused-child && echo --reuse_child=$$child; true) + +isotest: install + initrd.sh + xorriso-usb.sh $(reuse_child) --bootloader --out samizdat.iso + USE_ISO=y SLOW_BOOT=y qemu.sh + +isotest-nonet: install + initrd.sh + xorriso-usb.sh $(reuse_child) --out samizdat-nonet.iso + USE_ISO=y SLOW_BOOT=y NO_NET=y qemu.sh samizdat-nonet.iso + install: ${bin_programs} samizdat-paths.sh ${compiled_programs} install -p ${bin_programs} ${instdir}${samizdat_bindir} mkdir -p ${instdir}${samizdat_initrd_files_dir} diff --git a/user.mk b/user.mk new file mode 100644 index 0000000..4292fe8 --- /dev/null +++ b/user.mk @@ -0,0 +1,32 @@ +user_username = u +user_home_path := $(shell getent passwd "$(user_username)" | (IFS=: read _ _ _ _ _ homedir _; echo $$homedir)) +user_home_btrfs = $(user_home_path).btrfs +user_home_bytes = 10GiB +user_home_force_replace = + +user_exists = getent passwd "$(user_username)" >/dev/null + +is_btrfs = df ~$(user_username) -t btrfs >/dev/null + +user-account: + [ "$(user_username)" ] + $(user_exists) || sudo useradd "$(user_username)" -G sudo -m -p '' -s /bin/bash + $(is_btrfs) || $(MAKE) mount-user-btrfs-home >/dev/null 2>&1 || $(MAKE) user-btrfs-home + +remove_user_home_btrfs = sudo mv -b "$(user_home_btrfs)" "$(user_home_btrfs)"~"$$(date -Is)" + +user-btrfs-home: + [ "$(user_home_path)" ] + [ ! -e "$(user_home_btrfs)" ] || $(if $(user_home_force_replace),$(remove_user_home_btrfs),false) + [ ! -e "$(user_home_btrfs)" ] + ! mountpoint -q "$(user_home_path)" || sudo umount "$(user_home_path)" + [ ! -e "$(user_home_path)" ] || sudo rmdir "$(user_home_path)" || sudo mv -b "$(user_home_path)" "$(user_home_path)"~"$$(date -Is)" + [ -e "$(user_home_btrfs)" ] || sudo fallocate -l "$(user_home_bytes)" "$(user_home_btrfs)" + sudo mkdir "$(user_home_path)" + sudo mkfs.btrfs "$(user_home_btrfs)" + sudo mount -t btrfs "$(user_home_btrfs)" "$(user_home_path)" + sudo rsync -a /etc/skel/ "$(user_home_path)"/ + sudo chown -R "$(user_username):" "$(user_home_path)" + +mount-user-btrfs-home: + mountpoint -q "$(user_home_path)" || sudo mount -t btrfs "$(user_home_btrfs)" "$(user_home_path)" -- cgit v1.2.3