-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinitool-overwrite.sh
More file actions
executable file
·52 lines (42 loc) · 882 Bytes
/
initool-overwrite.sh
File metadata and controls
executable file
·52 lines (42 loc) · 882 Bytes
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
#! /bin/sh
set -eu
usage() {
echo "usage: $(basename "$0") command file [arg ...]"
}
help() {
printf 'Modify the input file with initool.\n\n'
usage
printf '\nYou can give the path to initool in the environment variable "INITOOL".\n'
}
for arg in "$@"; do
if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then
help
exit 0
fi
done
if [ $# -lt 2 ]; then
usage >&2
exit 2
fi
command=$1
file=$2
replace_original=1
if [ "$command" = e ] || [ "$command" = exists ]; then
replace_original=0
fi
if [ "$file" = - ]; then
echo 'file must not be "-"' >&2
exit 2
fi
temp=$(mktemp)
clean_up() {
rm "$temp" 2>/dev/null || true
}
trap clean_up EXIT HUP INT QUIT TERM
"${INITOOL:-initool}" "$@" >"$temp"
status=$?
if [ "$status" -eq 0 ] && [ "$replace_original" -eq 1 ]; then
mv "$temp" "$file"
else
exit "$status"
fi