forked from blaider/fsck.auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsck.auto
47 lines (41 loc) · 1.24 KB
/
fsck.auto
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
#!/bin/bash
#
# Copyright (c) 2020, Suchao Wang aka blaider@github
# Copyright (c) 2023, Roberto A. Foglietta <roberto.foglietta@gmail.com>
# Released under MIT license terms
#
#i#############################################################################
#echo "params: '$*'" #debug
export PATH=${PATH:-/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin}
if ! which which >/dev/null; then
which() {
for i in $(echo "$PATH" | tr : ' '); do
if [ -x "$i/$1" ]; then echo "$i/$1"; return 0; fi;
done
return 1
}
fi
for idx in 0 $(seq $#); do
name=$(eval echo -n "\$$idx")
if [ -b "$name" ]; then
DEVNODE="$name"
fi
done
#echo "devnode: '$DEVNODE'" #debug
if [ "x$DEVNODE" = "x" ]; then
echo "device find error"
exit 1
fi
if which lsblk >/dev/null; then
FSTYPE=$(command lsblk -f "$DEVNODE" -ro FSTYPE | grep -v FSTYPE)
elif which blkid >/dev/null; then
FSTYPE=$(command blkid -p "$DEVNODE" -o full | sed -ne 's/.* TYPE="\([^"]*\)" .*/\1/p')
else
echo "ERROR: lsblk and blkid missing but one of them is required, abort"
exit 1
fi
#echo "devnode: '$DEVNODE', fstype: '$FSTYPE'" #debug
CMD="fsck.${FSTYPE}"
echo "executing: '$CMD $*'"
eval $CMD $*
exit $?