blob: 4292fe8010792850dea6c31810c8cd85c1df4f41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)"
|