-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.bash
66 lines (58 loc) · 1.33 KB
/
lib.bash
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
61
62
63
64
65
66
#!/bin/bash
# Utility routines used by aosc-mklive generators.
set -e
# Once sourced the environment will restore to sanity.
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
export LC_ALL=C.UTF-8
info() {
echo -e "\033[1;37m[\033[36mINFO\033[37m]: $@\033[0m"
}
warn() {
echo -e "\033[1;37m[\033[33mWARN\033[37m]: $@\033[0m"
}
die() {
echo -e "\033[1;37m[\033[31mERROR\033[37m]: $@\033[0m"
exit 1
}
# $1: fstype
# $2: Output file
# $3: Path used as root (can not be a file)
packfs() {
local fstype outfile rootpath parent
fstype="$1"
outfile="$2"
rootpath="$3"
parent="$(realpath -m $outfile)"
parent="$(dirname $parent)"
if [ ! -e "$rootpath" ] ; then
die "Target path '$rootpath' does not exist."
fi
if [ ! -d "$rootpath" ] ; then
die "Target path '$rootpath' is not a directory."
fi
if [ ! -e "$parent" ] ; then
warn "Parent directory of '$outfile' does not exist, creating."
mkdir -pv "$parent"
fi
case "$fstype" in
squashfs)
pack_squashfs "$outfile" "$rootpath"
;;
*)
die "Unknown filesystem type '$fstype'."
;;
esac
}
# $1: Output file
# $2: Path used as root (can not be a file)
pack_squashfs() {
local rootpath outfile
outfile="$1"
rootpath="$2"
info "Packing squashfs from '$rootpath' to '$outfile' ..."
pushd "$rootpath"
mksquashfs . ${outfile} \
-noappend -comp xz -processors $(nproc)
popd
}