forked from jelaas/bifrost-build
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpkg_build
executable file
·108 lines (93 loc) · 2.54 KB
/
pkg_build
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# Maximum number of recursive builds
MR=15
export RECURSIVEBUILD=yes
unset CC
[ -d /proc/self/fd ] || exit 1
[ -d /dev/fd ] || exit 1
[ -c /dev/null ] || exit 1
[ -c /dev/zero ] || exit 1
if [ "$1" = '-R' ]; then
export RECURSIVEBUILD=no
shift
fi
if [ "$1" = '-r' ]; then
export RECURSIVEBUILD=yes
shift
fi
if [ -z "$1" ]; then
echo "Usage: pkg_build [-r|-R] <pkg> ..."
echo " -r enable recursive building [default]."
echo " -R disable recursive building."
exit 0
fi
if [ -f /var/lib/build/conf/tmpfs ]; then
read BUILDTMPFS < /var/lib/build/conf/tmpfs
fi
[ "$BUILDTMPFS" = yes ] || BUILDTMPFS=no
function checkpkg {
local rc
rc=0
while [ "$1" ]; do
pkg=$(basename $1)
PKGDIR=""
[ -d "/var/lib/build/staging/$pkg" ] && PKGDIR="/var/lib/build/staging/$pkg"
[ -d "/var/lib/build/all/$pkg" ] && PKGDIR="/var/lib/build/all/$pkg"
if [ -z "$PKGDIR" ]; then
echo "/var/lib/build/all/$pkg does not exist"
rc=1
fi
shift
done
return $rc
}
checkpkg $@ || exit 1
mkdir -p /var/tmp/install
mkdir -p /var/tmp/src
mkdir -p /var/spool/src
mkdir -p /var/spool/pkg
mkdir -p /var/log/build
mkdir -p /var/log/config
while [ "$1" ]; do
n=0
pkg=$(basename $1)
shift
rm -rf "/var/tmp/install/$pkg"
/var/lib/build/pkg_uninstall
[ -d "/var/lib/build/staging/$pkg" ] && export PKGDIR="/var/lib/build/staging/$pkg"
[ -d "/var/lib/build/all/$pkg" ] && export PKGDIR="/var/lib/build/all/$pkg"
DEPA=$(grep pkg_install $PKGDIR/Build.sh|wc -l)
DEPB=$(grep "untar " $PKGDIR/Build.sh|cut -d ' ' -f 1,2|sort|uniq|wc -l)
MR=$[ DEPA+DEPB+10 ]
cd $PKGDIR
while true; do
/var/lib/build/pkg_src_fetch $pkg
rm -f /var/log/build/$pkg.log
# Save current stdout to file descriptor 3, and redirect stdout to tee
exec 3>&1 > >(tee -a "/var/log/build/$pkg.log")
echo "Building $pkg from $PKGDIR"
[ "$BUILDTMPFS" = yes ] && mount -t tmpfs tmpfs /var/tmp/src
PATH="/var/lib/build:$PATH" ./Build.sh 2>&1
rc=$?
[ "$BUILDTMPFS" = yes ] && umount /var/tmp/src
if [ $rc != 0 ]; then
if [ "$RECURSIVEBUILD" = yes ]; then
if [ $rc = 2 ]; then
n=$[ n+1 ]
if [ $n -lt $MR ]; then
exec 1>&3 3>&-
continue
fi
echo "ATTN: Maximum number of recursive builds ($MR) exceeded!"
echo "ATTN: Last build was \'$pkg\'."
fi
fi
echo "ERROR: Build unsuccessful [$rc]. See /var/log/build/$pkg.log and /var/tmp/src"
else
echo "$pkg done!"
fi
break
done
# Restore stdout and close file descriptor 3
exec 1>&3 3>&-
done