forked from davidmroth/Extract-Kernel-Initramfs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.sh
68 lines (57 loc) · 1.46 KB
/
helper.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
61
62
63
64
65
66
67
68
####
# outputs help
####
function show_help()
{
cat <<EOF
Available options:
-q -- query archive (cpio -t)
-x -- extract archive (cpio)
-d -- extract archive (directory root)
-o <path> -- output filename / directory
-h -- this output
Example usage:
eki -d -o /tmp/initramfs /boot/vmlinuz.bin
EOF
exit 0
}
####
# Helper functions
####
# echo only on debug
function echo_debug() { [ -z $DEBUG ] || builtin echo "-D- $@" >&2; }
# echo an error
function echo_error() { builtin echo "-E- $@" >&2; }
# overlay standard echo
function echo() { builtin echo "-I- $@" >&2; }
# use grep to search for compression signature
# use "C" locale to avoid interpreting as UTF-8 sequences
function find_position() { LC_ALL=C grep -Pabo $1 "$2" 2>/dev/null; }
# temp file
function xmktemp()
{
local tmpfile=
echo_debug "Creating tempfile ($1)"
tmpfile=$(mktemp -q --tmpdir eki-$1-XXXXX)
if [ ! -e "$tmpfile" ]; then
echo_debug "Failed to create '$tmpfile'"
echo "Bootstrap failed"
return 1
fi
echo_debug "Successfully created '$tmpfile'"
builtin echo -n "$tmpfile"
}
# clean tempfile
function cleantemp()
{
if [ -z "$KEEP_FILES" ]; then
echo_debug "Removing '$1' and '$2'"
rm -rf -- "$1" "$2"
else
echo "You have enabled KEEP_FILES"
echo "Left over files available at:"
echo " > $1"
echo " > $2"
fi
exit ${3:-1}
}