-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlib.sh
60 lines (49 loc) · 1.32 KB
/
lib.sh
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
58
59
60
#!/bin/sh
#
# Shared functions to be used by image creation scripts.
#
# Copyright 2022 q66 <q66@chimera-linux.org>
#
# License: BSD-2-Clause
#
umask 022
readonly PROGNAME=$(basename "$0")
mount_pseudo() {
mount -t devtmpfs none "${ROOT_DIR}/dev" || die "failed to mount devfs"
mount -t proc none "${ROOT_DIR}/proc" || die "failed to mount procfs"
mount -t sysfs none "${ROOT_DIR}/sys" || die "failed to mount sysfs"
}
mount_pseudo_host() {
mount -t devtmpfs none "${HOST_DIR}/dev" || die "failed to mount devfs"
mount -t proc none "${HOST_DIR}/proc" || die "failed to mount procfs"
mount -t sysfs none "${HOST_DIR}/sys" || die "failed to mount sysfs"
}
umount_pseudo_dir() {
[ -n "$1" -a -d "$1" ] || return 0
umount -f "${1}/dev" > /dev/null 2>&1
umount -f "${1}/proc" > /dev/null 2>&1
umount -f "${1}/sys" > /dev/null 2>&1
umount -f "${1}/mnt" > /dev/null 2>&1
mountpoint -q "${1}" > /dev/null 2>&1 && \
umount -f "${1}" > /dev/null 2>&1
}
umount_pseudo() {
sync
umount_pseudo_dir "$HOST_DIR"
umount_pseudo_dir "$ROOT_DIR"
}
error_sig() {
umount_pseudo
exit ${1:=0}
}
trap 'error_sig $? $LINENO' INT TERM 0
msg() {
printf "\033[1m$@\n\033[m"
}
die() {
msg "ERROR: $@"
error_sig 1 $LINENO
}
if [ "$(id -u)" != "0" ]; then
die "must be run as root"
fi