summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile21
-rw-r--r--user.mk32
2 files changed, 50 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 22993e0..8377a69 100644
--- a/Makefile
+++ b/Makefile
@@ -48,16 +48,31 @@ else
48 ln -sf /var/cache/kiki/config/tor/hostname ${instdir}/etc/hostname 48 ln -sf /var/cache/kiki/config/tor/hostname ${instdir}/etc/hostname
49endif 49endif
50 50
51include user.mk
52
51.PHONY: rootfs 53.PHONY: rootfs
52rootfs: 54rootfs:
53 make -C fsmgr 55 : git submodule update
54 make -C fsmgr install 56 $(MAKE) -C fsmgr
55 make -C rootfs 57 $(MAKE) -C fsmgr install
58 $(MAKE) -C rootfs
56 sudo ln -sf "$$PWD"/rootfs/samizdat.btrfs /srv/nbd/samizdat.btrfs 59 sudo ln -sf "$$PWD"/rootfs/samizdat.btrfs /srv/nbd/samizdat.btrfs
57 60
58boot: rootfs 61boot: rootfs
59 sudo qemu.sh 62 sudo qemu.sh
60 63
64reuse_child := $(shell 2>/dev/null read child < reused-child && echo --reuse_child=$$child; true)
65
66isotest: install
67 initrd.sh
68 xorriso-usb.sh $(reuse_child) --bootloader --out samizdat.iso
69 USE_ISO=y SLOW_BOOT=y qemu.sh
70
71isotest-nonet: install
72 initrd.sh
73 xorriso-usb.sh $(reuse_child) --out samizdat-nonet.iso
74 USE_ISO=y SLOW_BOOT=y NO_NET=y qemu.sh samizdat-nonet.iso
75
61install: ${bin_programs} samizdat-paths.sh ${compiled_programs} 76install: ${bin_programs} samizdat-paths.sh ${compiled_programs}
62 install -p ${bin_programs} ${instdir}${samizdat_bindir} 77 install -p ${bin_programs} ${instdir}${samizdat_bindir}
63 mkdir -p ${instdir}${samizdat_initrd_files_dir} 78 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 @@
1user_username = u
2user_home_path := $(shell getent passwd "$(user_username)" | (IFS=: read _ _ _ _ _ homedir _; echo $$homedir))
3user_home_btrfs = $(user_home_path).btrfs
4user_home_bytes = 10GiB
5user_home_force_replace =
6
7user_exists = getent passwd "$(user_username)" >/dev/null
8
9is_btrfs = df ~$(user_username) -t btrfs >/dev/null
10
11user-account:
12 [ "$(user_username)" ]
13 $(user_exists) || sudo useradd "$(user_username)" -G sudo -m -p '' -s /bin/bash
14 $(is_btrfs) || $(MAKE) mount-user-btrfs-home >/dev/null 2>&1 || $(MAKE) user-btrfs-home
15
16remove_user_home_btrfs = sudo mv -b "$(user_home_btrfs)" "$(user_home_btrfs)"~"$$(date -Is)"
17
18user-btrfs-home:
19 [ "$(user_home_path)" ]
20 [ ! -e "$(user_home_btrfs)" ] || $(if $(user_home_force_replace),$(remove_user_home_btrfs),false)
21 [ ! -e "$(user_home_btrfs)" ]
22 ! mountpoint -q "$(user_home_path)" || sudo umount "$(user_home_path)"
23 [ ! -e "$(user_home_path)" ] || sudo rmdir "$(user_home_path)" || sudo mv -b "$(user_home_path)" "$(user_home_path)"~"$$(date -Is)"
24 [ -e "$(user_home_btrfs)" ] || sudo fallocate -l "$(user_home_bytes)" "$(user_home_btrfs)"
25 sudo mkdir "$(user_home_path)"
26 sudo mkfs.btrfs "$(user_home_btrfs)"
27 sudo mount -t btrfs "$(user_home_btrfs)" "$(user_home_path)"
28 sudo rsync -a /etc/skel/ "$(user_home_path)"/
29 sudo chown -R "$(user_username):" "$(user_home_path)"
30
31mount-user-btrfs-home:
32 mountpoint -q "$(user_home_path)" || sudo mount -t btrfs "$(user_home_btrfs)" "$(user_home_path)"