summaryrefslogtreecommitdiff
path: root/mount-data/files/init
blob: 700ea408e402ccfbfd403b35ecf2d1d90dc3cf58 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh /etc/rc.common

START=36
STOP=90

UUID="f71f2b6c-fc49-4a9b-91b3-7eaab853a02d"

is_open() {
	[ -b "/dev/mapper/data_$1" ]
}

open() {
	cryptsetup open --key-file /etc/keys/sd "$2" "data_$1"
}

close() {
	cryptsetup close "data_$1"
}

is_mounted() {
	findmnt >/dev/null "$1"
}

mount_btrfs() {
	mount -o subvol="$1" "UUID=$UUID" "$2"
}

umount_drive() {
	umount -lf "UUID=$UUID"
}


status() {
	is_mounted "/data" && is_mounted "/srv"
}

start() {
	is_open a || open a /dev/sda
	is_open b || open b /dev/sdb
	btrfs device scan /dev/mapper/data_a /dev/mapper/data_b
	is_mounted "/data" || mount_btrfs @data /data
	is_mounted "/srv" || mount_btrfs @srv /srv
}

stop() {
	unmount_drive
	close a
	close b
}

restart() {
	:
}

reload() {
	:
}