-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateModules
executable file
·136 lines (130 loc) · 3.88 KB
/
updateModules
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
basePath=`dirname $0`
export PATH="$basePath/utils:$PATH"
if test -s /etc/keengreeper.conf; then
. /etc/keengreeper.conf
fi
if test -z "$LOGDIR"; then
export LOGDIR=`pwd`/logs
fi
if test -z "$TMPDIR"; then
export TMPDIR=`pwd`/tmp
fi
if test -z "$WORKDIR"; then
export WORKDIR=/home/`id -un`/git
fi
if test -z "$DBDIR"; then
export DBDIR=$WORKDIR
fi
if test -z "$CACHETTL"; then
export CACHETTL=3600
fi
test -d $LOGDIR || mkdir -p $LOGDIR
test -d $TMPDIR || mkdir -p $TMPDIR
test -d $DBDIR || mkdir -p $DBDIR
if ! test -d $WORKDIR; then
echo "CRITICAL: $WORKDIR does not exist" >&2
exit 1
elif ! test -d $DBDIR; then
echo "CRITICAL: $DBDIR does not exist" >&2
exit 1
elif ! test -s $DBDIR/nodejs-update-db; then
cat <<EOF >&2
CRITICAL: nodejs-update-db absent or empty
use $basePath/configure to create an empty dataset, and configure
which repositories our job should be working with.
EOF
exit 1
elif ! checkTmpdir; then
exit 1
fi
TMPFILE=$TMPDIR/$1.$$
if listRepository >/dev/null 2>&1; then
echo "refreshing npmjs local cache"
nodeDbExpireCache >/dev/null 2>&1 || true
fi
for repository in `listRepository`
do
if test "$1"; then
if ! echo $repository | grep -E "$1" >/dev/null; then
test "$DEBUG" && echo "skipping $repository - does not match pattern"
continue
fi
fi
if test -s "$TMPDIR/$repository.lock"; then
if ls /proc/`cat "$TMPDIR/$repository.lock"` >/dev/null 2>&1; then
echo "skipping $repository - lock file exists"
continue
fi
test "$DEBUG" && echo "orphan lock file exists, discarding"
fi
echo $$ >$TMPDIR/$repository.lock
sleep 1
if ! grep $$ $TMPDIR/$repository.lock >/dev/null 2>&1; then
echo "skipping $repository - can not acquire lock"
continue
fi
echo "processing $repository"
if ! cleanRepository $repository; then
resetRepository $repository
fi
if setBranch $repository staging; then
if ! updateRepository $repository; then
echo "skipping $repositroy - failed updating local copy"
rm -f $TMPDIR/$repository.lock
continue
elif ! listDependencies $repository >/dev/null; then
echo "skipping $repository - failed listing dependencies"
rm -f $TMPDIR/$repository.lock
continue
fi
listDependencies $repository | while read dependency version
do
test "$DEBUG" && echo "checking $dependency on behalf of $repository"
skipreason=
if echo $version | grep -E '(((http(s|)|ssh|file):)|/)' >/dev/null; then
skipreason="non-npm dependency"
elif ! nodeDbGetCache $dependency >/dev/null 2>&1; then
if ! getVersionFromNpmjs $dependency >/dev/null 2>&1; then
skipreason="failed getting last revision from npmjs.com"
elif ! nodeDbAddCache $dependency >/dev/null 2>&1; then
skipreason="failed updating npmjs cache"
fi
fi
if grep "^$dependency$" $DBDIR/exclude-from-updates >/dev/null 2>&1; then
skipreason="dependency registered to exclude file"
fi
if test "$skipreason"; then
test "$DEBUG" && echo "skipping $repository::$dependency - $skipreason"
continue
fi
lastKnown=`nodeDbGetCache $dependency 2>/dev/null`
if test "$version" = latest; then
if resolveVersion $repository $dependency >/dev/null 2>/dev/null; then
localVersion=`resolveVersion $repository $dependency`
else
continue
fi
else
localVersion=$version
fi
if checkVersion "$localVersion" "$lastKnown"; then
continue
fi
echo "staging $dependency@$repository $localVersion -> $lastKnown"
echo $dependency $localVersion $lastKnown >>$TMPFILE
done
if test -s $TMPFILE; then
echo "building staged changes for $repository"
bumpVersion $repository $TMPFILE
rm -f $TMPFILE
fi
nodeDbUpdateRepository $repository >/dev/null 2>&1
rm -f $TMPDIR/$repository.lock
else
echo "skipping $repository - failed switching to main working branch"
fi
done
nodeClearLogs
echo done
exit 0