3 # dcf.sh - Distributed Compile Farm Mediator
5 # Copyright (c) 2007-2011, Borut Razem <borut dot razem at gmail dot com>
7 # This file is part of sdcc.
9 # This software is provided 'as-is', without any express or implied
10 # warranty. In no event will the authors be held liable for any damages
11 # arising from the use of this software.
13 # Permission is granted to anyone to use this software for any purpose,
14 # including commercial applications, and to alter it and redistribute it
15 # freely, subject to the following restrictions:
17 # 1. The origin of this software must not be misrepresented; you must not
18 # claim that you wrote the original software. If you use this software
19 # in a product, an acknowledgment in the product documentation would be
20 # appreciated but is not required.
21 # 2. Altered source versions must be plainly marked as such, and must not be
22 # misrepresented as being the original software.
23 # 3. This notice may not be removed or altered from any source distribution.
25 LOG_LINES
=1000 # max number of lines in the log file
26 BWLIMIT
=21 # bandwith limit in KiB for rsync
32 DCF_BUILDER_LIST_FILE
=$ETC_DIR/dcf_list
33 DCF_LOG
=$LOG_DIR/dcf.log
34 DCF_LOCK
=$LOCK_DIR/dcf.lock
36 TREE_FILE
=$HOME/tmp
/tree.txt
38 mkdir
-p $LOG_DIR $LOCK_DIR
40 WEBHOST
=web.sourceforge.net
42 WEBHTDOCSDIR
=/home
/project-web
/sdcc
/htdocs
44 FRSHOST
=frs.sourceforge.net
46 FRSDIR
=/home
/frs
/project
/sdcc
/snapshot_builds
53 test -n "${DEBUG}" && echo =DBG
= $
*
56 # debugging: print the command and execute it
58 # $*: command to debug & execute
72 echo "$1" |
awk "{print substr(\$0, $2)}"
74 echo "$1" |
awk "{print substr(\$0, $2, $3)}"
81 # $1: premissions string
83 expr "$1" : "^\(.\)[-rwxXst]*$"
87 # generate file tree list
94 local old_ifs files line
file type subdir
96 files
=$
(echo "ls -lt" | sftp
-b- "$1@$2:$3/$4" |
sed -e '/^sftp> /d')
102 # get file name from ls -l line
103 # NOTE: this works only for file names without spaces!
104 file=$
(expr "${line}" : ".*[ ]\([^ ][^ ]*\)$")
105 type=$
(file_type $
(substr
"${line}" 0 8))
115 tree
"$1" "$2" "$3" "${subdir}/"
126 # remove files & directories specified in arguments
127 # relays on find -depth
144 # list files & directories specified in arguments
145 # each file in a new line
157 # write the standard input to beginning of the log file
158 # and truncate it to $LOG_LINES lines
165 if test -e $DCF_LOG -a $
(echo "$LOG" |
wc -l) -lt $LOG_LINES
167 LOG
=$
(echo -e "$LOG\n" |
cat - $DCF_LOG |
head -n $LOG_LINES)
169 echo "$LOG" > $DCF_LOG
174 # remove more than 7 files in dir from fsr server
181 for j
in $
(echo "ls -1t $i" | sftp
-b- ${FRSUSER}@
${FRSHOST} |
sed -e '/^sftp> /d')
183 for k
in $
(echo "ls -1t $j" | sftp
-b- ${FRSUSER}@
${FRSHOST} |
sed -e '/^sftp> /d' |
sed -e '1,7d')
185 if [ -n "$k" ]; then echo "removing $k"; echo "rm $k" | sftp
-b- ${FRSUSER}@
${FRSHOST}; fi
190 for i
in ${WEBHTDOCSDIR}/regression_test_results
192 for j
in $
(echo "ls -1t $i" | sftp
-b- ${WEBUSER}@
${WEBHOST} |
sed -e '/^sftp> /d')
194 for k
in $
(echo "ls -1t $j" | sftp
-b- ${WEBUSER}@
${WEBHOST} |
sed -e '/^sftp> /d' |
sed -e '1,7d')
196 if [ -n "$k" ]; then echo "removing $k"; echo "rm $k" | sftp
-b- ${WEBUSER}@
${WEBHOST}; fi
201 for k
in $
(echo "ls -1t ${WEBHTDOCSDIR}/changelog_heads" | sftp -b- ${WEBUSER}@${WEBHOST} | sed -e '/^sftp> /d' | sed -e '1,7d')
203 if [ -n "$k" ]; then echo "removing
$k"; echo "rm $k" | sftp -b- ${WEBUSER}@${WEBHOST}; fi
208 # cleanup the lock file
215 # synchronise directory
217 # $1: source directory to sync
218 # $2: traget machine/directory to sync
219 # $3: exclude source directories from sync
221 local ret=1 excl file_list
223 if test -d $1 && pushd $1 > /dev/null
227 file_list=$(find * -depth -print 2>/dev/null)
229 file_list=$(find * -depth -print 2>/dev/null | grep -v -e "^
$3")
231 if test -n "${file_list}"
233 echo "+++ start
: $
(date)"
234 echo "=== files
in $1:"
235 list_files ${file_list}
238 echo "=== rsyncing...
"
243 excl=${excl}" --exclude "${dir}
246 debug_print "current directory
: $
(pwd)"
247 debug_exec rsync $RSYNC_OPTS --relative --recursive --include='*.exe' ${excl} -e ssh --size-only * $2 2>&1 | grep -v -e "skipping directory
"
249 echo "=== removing...
"
252 echo "=== removing old versions...
"
255 echo "--- end
: $
(date)"
267 trap 'echo dcf.sh caught signal ; cleanup ; exit 1' 1 2 3 13 15
269 if test -e ${DCF_BUILDER_LIST_FILE}
271 lockfile -r 0 ${DCF_LOCK} || exit 1
273 test "${BWLIMIT}" != "" && RSYNC_OPTS="${RSYNC_OPTS} --bwlimit=${BWLIMIT}"
278 while read -r builder
283 builder=$(echo ${builder} | sed -e "s
/^\
(.
*\
)#.*$/\1/" -e "s/[ \t]*$//")
284 if test ! -z "${builder}"
286 if sync_dir
"/home/${builder}/htdocs/snapshots" ${FRSUSER}@${FRSHOST}:${FRSDIR}/
288 if test ! -e ${TREE_FILE}
290 tree ${FRSUSER} ${FRSHOST} ${FRSDIR} > ${TREE_FILE}
292 sync_dir "/home
/${builder}/htdocs" ${WEBUSER}@${WEBHOST}:${WEBHTDOCSDIR}/ "snapshots"
297 } < ${DCF_BUILDER_LIST_FILE}
299 if test -e ${TREE_FILE}
301 # upload the new version of ${TREE_FILE}, needed by snap.php to create sdcc snapshots web page
302 echo "put ${TREE_FILE} ${WEBHTDOCSDIR}/$(basename ${TREE_FILE})" | sftp -b- ${WEBUSER}@${WEBHOST}