Skip to content

Commit 0c848b8

Browse files
committed
common: split genfstab only helpers
v2: drop warning and msg from fstab-helpers v3: drop m4 -> sed conversion Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
1 parent 9f5888d commit 0c848b8

7 files changed

+244
-234
lines changed

Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ _v_GEN_0 = @echo " GEN " $@;
2525

2626
edit = $(V_GEN) m4 -P $@.in >$@ && chmod go-w,+x $@
2727

28-
%: %.in common
28+
arch-chroot: arch-chroot.in common
29+
$(edit)
30+
31+
genfstab: genfstab.in fstab-helpers
32+
$(edit)
33+
34+
pacstrap: pacstrap.in common
2935
$(edit)
3036

3137
doc/%: doc/%.asciidoc doc/asciidoc.conf doc/footer.asciidoc

common

-229
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,3 @@
1-
# generated from util-linux source: libmount/src/utils.c
2-
declare -A pseudofs_types=([anon_inodefs]=1
3-
[apparmorfs]=1
4-
[autofs]=1
5-
[bdev]=1
6-
[binder]=1
7-
[binfmt_misc]=1
8-
[bpf]=1
9-
[cgroup]=1
10-
[cgroup2]=1
11-
[configfs]=1
12-
[cpuset]=1
13-
[debugfs]=1
14-
[devfs]=1
15-
[devpts]=1
16-
[devtmpfs]=1
17-
[dlmfs]=1
18-
[dmabuf]=1
19-
[drm]=1
20-
[efivarfs]=1
21-
[fuse]=1
22-
[fuse.archivemount]=1
23-
[fuse.avfsd]=1
24-
[fuse.dumpfs]=1
25-
[fuse.encfs]=1
26-
[fuse.gvfs-fuse-daemon]=1
27-
[fuse.gvfsd-fuse]=1
28-
[fuse.lxcfs]=1
29-
[fuse.rofiles-fuse]=1
30-
[fuse.vmware-vmblock]=1
31-
[fuse.xwmfs]=1
32-
[fusectl]=1
33-
[hugetlbfs]=1
34-
[ipathfs]=1
35-
[mqueue]=1
36-
[nfsd]=1
37-
[none]=1
38-
[nsfs]=1
39-
[overlay]=1
40-
[pipefs]=1
41-
[proc]=1
42-
[pstore]=1
43-
[ramfs]=1
44-
[resctrl]=1
45-
[rootfs]=1
46-
[rpc_pipefs]=1
47-
[securityfs]=1
48-
[selinuxfs]=1
49-
[smackfs]=1
50-
[sockfs]=1
51-
[spufs]=1
52-
[sysfs]=1
53-
[tmpfs]=1
54-
[tracefs]=1
55-
[vboxsf]=1
56-
[virtiofs]=1)
57-
58-
# generated from: pkgfile -vbr '/fsck\..+' | awk -F. '{ print $NF }' | sort
59-
declare -A fsck_types=([btrfs]=0 # btrfs doesn't need a regular fsck utility
60-
[cramfs]=1
61-
[erofs]=1
62-
[exfat]=1
63-
[ext2]=1
64-
[ext3]=1
65-
[ext4]=1
66-
[f2fs]=1
67-
[fat]=1
68-
[jfs]=1
69-
[minix]=1
70-
[msdos]=1
71-
[reiserfs]=1
72-
[vfat]=1
73-
[xfs]=1)
74-
751
# shellcheck disable=SC2059 # $1 and $2 can contain the printf modifiers
762
out() { printf "$1 $2\n" "${@:3}"; }
773
error() { out "==> ERROR:" "$@"; } >&2
@@ -188,158 +114,3 @@ declare_all() {
188114
# Then declare functions
189115
declare -pf
190116
}
191-
192-
try_cast() (
193-
_=$(( $1#$2 ))
194-
) 2>/dev/null
195-
196-
valid_number_of_base() {
197-
local base=$1 len=${#2} i=
198-
199-
for (( i = 0; i < len; i++ )); do
200-
try_cast "$base" "${2:i:1}" || return 1
201-
done
202-
203-
return 0
204-
}
205-
206-
mangle() {
207-
local i= chr= out=
208-
local {a..f}= {A..F}=
209-
210-
for (( i = 0; i < ${#1}; i++ )); do
211-
chr=${1:i:1}
212-
case $chr in
213-
[[:space:]\\])
214-
printf -v chr '%03o' "'$chr"
215-
out+=\\
216-
;;
217-
esac
218-
out+=$chr
219-
done
220-
221-
printf '%s' "$out"
222-
}
223-
224-
unmangle() {
225-
local i= chr= out= len=$(( ${#1} - 4 ))
226-
local {a..f}= {A..F}=
227-
228-
for (( i = 0; i < len; i++ )); do
229-
chr=${1:i:1}
230-
case $chr in
231-
\\)
232-
if valid_number_of_base 8 "${1:i+1:3}" ||
233-
valid_number_of_base 16 "${1:i+1:3}"; then
234-
printf -v chr '%b' "${1:i:4}"
235-
(( i += 3 ))
236-
fi
237-
;;
238-
esac
239-
out+=$chr
240-
done
241-
242-
printf '%s' "$out${1:i}"
243-
}
244-
245-
optstring_match_option() {
246-
local candidate pat patterns
247-
248-
IFS=, read -ra patterns <<<"$1"
249-
for pat in "${patterns[@]}"; do
250-
if [[ $pat = *=* ]]; then
251-
# "key=val" will only ever match "key=val"
252-
candidate=$2
253-
else
254-
# "key" will match "key", but also "key=anyval"
255-
candidate=${2%%=*}
256-
fi
257-
258-
[[ $pat = "$candidate" ]] && return 0
259-
done
260-
261-
return 1
262-
}
263-
264-
optstring_remove_option() {
265-
local o options_ remove=$2 IFS=,
266-
267-
read -ra options_ <<<"${!1}"
268-
269-
for o in "${!options_[@]}"; do
270-
optstring_match_option "$remove" "${options_[o]}" && unset 'options_[o]'
271-
done
272-
273-
declare -g "$1=${options_[*]}"
274-
}
275-
276-
optstring_normalize() {
277-
local o options_ norm IFS=,
278-
279-
read -ra options_ <<<"${!1}"
280-
281-
# remove empty fields
282-
for o in "${options_[@]}"; do
283-
[[ $o ]] && norm+=("$o")
284-
done
285-
286-
# avoid empty strings, reset to "defaults"
287-
declare -g "$1=${norm[*]:-defaults}"
288-
}
289-
290-
optstring_append_option() {
291-
if ! optstring_has_option "$1" "$2"; then
292-
declare -g "$1=${!1},$2"
293-
fi
294-
295-
optstring_normalize "$1"
296-
}
297-
298-
optstring_prepend_option() {
299-
local options_=$1
300-
301-
if ! optstring_has_option "$1" "$2"; then
302-
declare -g "$1=$2,${!1}"
303-
fi
304-
305-
optstring_normalize "$1"
306-
}
307-
308-
optstring_get_option() {
309-
local _opts o
310-
311-
IFS=, read -ra _opts <<<"${!1}"
312-
for o in "${_opts[@]}"; do
313-
if optstring_match_option "$2" "$o"; then
314-
declare -g "$o"
315-
return 0
316-
fi
317-
done
318-
319-
return 1
320-
}
321-
322-
optstring_has_option() {
323-
local "${2%%=*}"
324-
325-
optstring_get_option "$1" "$2"
326-
}
327-
328-
dm_name_for_devnode() {
329-
read dm_name <"/sys/class/block/${1#/dev/}/dm/name"
330-
if [[ $dm_name ]]; then
331-
printf '/dev/mapper/%s' "$dm_name"
332-
else
333-
# don't leave the caller hanging, just print the original name
334-
# along with the failure.
335-
error 'Failed to resolve device mapper name for: %s' "$1"
336-
fi
337-
}
338-
339-
fstype_is_pseudofs() {
340-
(( pseudofs_types["$1"] ))
341-
}
342-
343-
fstype_has_fsck() {
344-
(( fsck_types["$1"] ))
345-
}

0 commit comments

Comments
 (0)