-
Notifications
You must be signed in to change notification settings - Fork 0
/
.v-common.rc
64 lines (54 loc) · 1.75 KB
/
.v-common.rc
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
#!/bin/sh
# shellcheck disable=2154,1090,2034
_VDISK_COMMON_DIR=$(dirname "$(readlink -f "$0")")
# Sources
# ------------------
# Don't change the order. Some depend on the previous ones.
[ "${_COLOR_Off}" ] || . "${_VDISK_COMMON_DIR}/.color.rc"
[ "${_LOG_DIR}" ] || . "${_VDISK_COMMON_DIR}/.log.rc"
[ "${_CHECKS_DIR}" ] || . "${_VDISK_COMMON_DIR}/.checks.rc"
## @fn: A drop-in replacement of busybox's `realpath`.
# Busybox's `realpath` fails in some cases, such as ImDisk's mount.
realpath() {
if cd "$(dirname "$1")" 2>/dev/null; then
echo "$(pwd -P)/$(basename "$1")"
fi
}
## @fn toWindowsPath()
## @brief Convert path to Windows style (slash to backslash)
## @param STRING a path string
## @return STRING with all slashes replaced by backslashes
toWindowsPath() {
printf '%s' "$1" | tr "/" "\\"
}
## @fn str_sub()
## @brief Returns a substring of a string.
## @param STRING a string
## @param OFFSET 0-based offset
## @param LENGTH length
## @return the substring of STRING starting at OFFSET of length LENGTH
str_sub() {
awk -v str="$1" -v offset="$2" -v len="$3" 'BEGIN{ string=substr(str, offset+1, len); print string; }'
}
## @fn str_right()
## @brief Returns a right-most substring of a string.
## @param STRING a string
## @param LENGTH length
## @return the right-most substring of STRING of length LENGTH
str_right() {
awk -v str="$1" -v len="$2" 'BEGIN{ string=substr(str, length(str)-len+1, len); print string; }'
}
# Setup Help
# ------------------
_HELP_VARIABLES=$(cat << _EOF_
VARIABLES:
${_LOG_HELP}
_EOF_
)
# Setup DiskPart
# ------------------
_DISKPART="${_VDISK_COMMON_DIR}/.diskpart.sh"
if ! diskpart /? | grep -q 'DiskPart'; then
_log_error "'diskpart' is not runnable. Maybe you are not running as admin?"
exit 1
fi