forked from barebox/barebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenenv
executable file
·58 lines (48 loc) · 1.07 KB
/
genenv
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
#!/usr/bin/env bash
# Generate the default environment file from a list of directories
# usage: genenv <basedir> <objdir> <target> <dir>...
# where <basedir> is the base directory for relative paths in <dir>
# where <objdir> is the base directory for relative paths for result
# and <target> is the resulting binary environment
objtree=$2
basedir=$1
target=$3
shift 3
abspath() {
local fn dn
if [ $# -ne 1 ]; then
echo "usage: ptxd_abspath <path>"
exit 1
fi
if [ -d "${1}" ]; then
fn=""
dn="${1}"
else
fn="/$(basename "${1}")"
dn="$(dirname "${1}")"
fi
[ ! -d "${dn}" ] && exit 1
echo "$(cd "${dn}" && pwd)${fn}"
}
export -f abspath
tempdir=$(abspath "${target}.genenv.tmp")
tmpfile="$(mktemp)"
mkdir -p "$tempdir"
(cd $basedir
for i in $*; do
if [ -d $i ]; then
cp -r $i/* $tempdir
else
cp -a $i $tempdir
fi
done
)
find $tempdir -name '.svn' -o -name '*~' -delete
$objtree/scripts/bareboxenv -s $tempdir ${tmpfile}
diff "${tmpfile}" "${target}" >/dev/null 2>/dev/null
if [ $? != 0 ]; then
mv "${tmpfile}" "${target}"
else
rm ${tmpfile}
fi
rm -r $tempdir