-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
60 lines (54 loc) · 1.18 KB
/
functions.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
CRESET="\\e[0m"
CERROR="\\e[31m"
CINFO="\\e[34m"
CWARN="\\e[33m"
log () {
echo "$*"
}
log_info () {
echo "${CINFO}INFO: $*${CRESET}"
}
log_error () {
echo "${CERROR}ERROR: $*${CRESET}"
}
log_warn () {
echo "${CWARN}WARN: $*${CRESET}"
}
get_loop_device () {
local LOOP_DEVICE=""
if [ -f "${1}" ]; then
LOOP_DEVICE=$(losetup -j "${1}" | awk -F : -- '{ print $1 }')
fi
echo "${LOOP_DEVICE}"
return 0
}
wait_for_part () {
set +e
local trial=5;
while test ${trial} -gt 0;do
if test -e "$1" -a -b "$1";then
return 0
fi
log_info "Waiting for $1 block device..."
sleep 0.01
trial=$(("${trial}" - 1))
done
set -e
return 1
}
mount_or_remount () {
local source="${1}"; local target="${2}"
if [ -z "${source}" ] || [ -z "${target}" ]
then
log_error "Remount failed missing argument: source='${source}' target='${target}'"
return 1
fi
log_info "Mounting ${source} on ${target}"
mkdir -vp "${target}"
if findmnt -P "${target}"
then
umount "${target}"
fi
mount "${source}" "${target}"
log_info "${source} mounted on ${target} 🙌"
}