]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/make-buildspy
Improved detection if buildspy is already running.
[ipfire-3.x.git] / tools / make-buildspy
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 BUILD_SPY_FILENAME=$BASEDIR/.build_spy
23 BUILD_SPY_PID=$BUILD_SPY_FILENAME.pid
24
25 build_spy() {
26 local COMMAND
27 COMMAND=$1
28 shift 1
29 if [ "$COMMAND" = "start" ]; then
30 BASEDIR=$BASEDIR UUID=$UUID NAME=$NAME VERSION=$VERSION \
31 LOGFILE="$BASEDIR/log_${TARGET}/_build.00-buildspy.log" \
32 $BASEDIR/tools/make-buildspy &
33 elif [ "$COMMAND" = "exit" ]; then
34 echo -n "BUILDSPY_EXIT " >> $BUILD_SPY_FILENAME
35 else
36 echo -n "${COMMAND}=$* " >> $BUILD_SPY_FILENAME
37 fi
38 }
39
40 build_spy_send_profile() {
41 build_spy target ${TARGET}
42 build_spy hostname ${HOSTNAME}
43 build_spy distcc ${DISTCC_PORT-3632}
44 build_spy jobs ${DISTCC_JOBS}
45 build_spy cpu $(grep ^model\ name /proc/cpuinfo | head -n1 | \
46 awk -F: '{ print $2 }' | $BASEDIR/tools/base64)
47 build_spy machine $(uname -m)
48 build_spy toolchain "${NAME}-${TOOLCHAINVERSION}"
49 }
50
51 if [ "$(basename $0)" == "make-buildspy" ]; then
52 if [ -f "$BUILD_SPY_PID" ]; then
53 exit 0
54 fi
55 echo $$ > $BUILD_SPY_PID
56
57 while true; do
58 DATA+=$(cat $BUILD_SPY_FILENAME 2>/dev/null || true)
59 > $BUILD_SPY_FILENAME
60
61 for command in $DATA; do
62 if [ "$command" = "BUILDSPY_EXIT" ]; then
63 BUILDSPY_EXIT=1
64 break
65 fi
66 done
67
68 if [ -n "$DATA" ] && \
69 $BASEDIR/tools/buildspy \
70 action=set uuid=$UUID $DATA >> $LOGFILE 2>&1; then
71 DATA=""
72 else
73 continue
74 fi
75
76 if [ "$BUILDSPY_EXIT" = "1" ]; then
77 break
78 fi
79
80 sleep 10
81 done
82 rm -f $BUILD_SPY_FILENAME $BUILD_SPY_PID
83 fi