]> git.ozlabs.org Git - next-scripts/blob - fetch_trees
do_last_build: use the Debian cross compiler for i386 as well
[next-scripts] / fetch_trees
1 #!/bin/bash
2
3 tools_dir=$(dirname "$0")
4 # shellcheck source=/dev/null
5 . "$tools_dir/common.sh" ''
6
7 if [ "$1" = '-n' ]; then
8         shift
9         last=$(tail -n1 "$SHA1_FILE" | cut -f1 -d$'\t')
10         start_from=$(awk -F '\t' '/^[^#]/ && $3 == "'"$last"'" {
11                 do
12                         getline;
13                 while (/^#/ || $2 == "branch");
14                 print $3;
15                 exit 0;
16         }' "$CTRL_FILE")
17 fi
18
19 if [ "$1" = '-s' ]; then
20         shift
21         start_from="$1"
22         if [ -z "$start_from" ]; then
23                 printf '-s requires a start tree\n' 1>&2
24                 exit 1
25         fi
26         shift
27 fi
28
29 get_field()
30 {
31         awk -F '\t' '/^[^#]/ && $3 == "'"$1"'" { print $'"$2"'; }' "$CTRL_FILE"
32 }
33
34 fetch_git()
35 {
36         git fetch "$1"
37 }
38
39 fetch_mmotm()
40 {
41         (
42                 if ! cd ../mmotm; then
43                         printf 'Cannot chdir to ../mmotm\n' 1>&2
44                         return
45                 fi
46                 if ! rsync -az --partial --exclude '.git*' \
47                                 --exclude broken-out.tar.gz --delete \
48                                 ozlabs.org::akpm/mmotm/. .; then
49                         git reset --hard
50                         printf 'Fetcing mmotm failed\n' 1>&2
51                         return
52                 fi
53                 git add -A .
54                 if [ "$(git status --porcelain)" ]; then
55                         git commit -m "$(head -n 1 .DATE)"
56                 fi
57         )
58 }
59
60 fetch_quilt()
61 {
62         (
63                 url=$(get_field "$1" 4)
64                 url=${url%/}    # strip trailing / if necessary
65
66                 if ! cd ../quilt; then
67                         printf 'Cannot chdir to ../quilt\n' 1>&2
68                         return
69                 fi
70                 if ! [ -d "$1" ] && ! mkdir "$1"; then
71                         printf 'Cannot create quilt directory for %s\n' "$1" 1>&2
72                         return
73                 fi
74                 if ! cd "$1"; then
75                         printf 'Cannot chdir to quilt directory for %s\n' "$1" 1>&2
76                         return
77                 fi
78                 if ! wget -N -nv --no-cache --no-xattr "$url/series"; then
79                         printf 'Wget of %s series file failed\n' "$1" 1>&2
80                         cd ..
81                         rm -rf "$1"
82                         git checkout "$1"
83                         return
84                 fi
85                 find . -type f | sed 's,^./,,;/^series$/d' | sort >.series.old
86                 if grep -q NEXT_PATCHES series; then
87                         sed -n '/NEXT_PATCHES_START/,/NEXT_PATCHES_END/p' series
88                 else
89                         cat series
90                 fi |
91                         sed -e 's/[ \t]*#.*$//' -e '/^[ \t]*$/d' |
92                         sort >.series.next
93                 if [ -s .series.next ]; then
94                         if ! wget -N -nv --no-cache --no-xattr -B "$url/" -i .series.next; then
95                                 printf 'Wget of series %s failed\n' "$1" 1>&2
96                                 cd ..
97                                 rm -rf "$1"
98                                 git checkout "$1"
99                                 return
100                         fi
101                 fi
102                 comm -23 .series.old .series.next | xargs -r rm -f
103                 rm -f .series.old .series.next
104         )
105 }
106
107 trees="$*"
108 if ! [ "$trees" ]; then
109         trees=$(awk -F '\t' '/^[^#]/ && $2 != "branch" { print $3 }' "$CTRL_FILE")
110 fi
111
112 for name in $trees; do
113         if [ -n "$start_from" ]; then
114                 if [ "$name" = "$start_from" ]; then
115                         start_from=''
116                 else
117                         continue
118                 fi
119         fi
120
121         type=$(get_field "$name" 2)
122         if ! [ "$type" ]; then
123                 printf '%s: unknown tree\n' "$name" 1>&2
124                 continue
125         fi
126
127         printf '%s: %s\n' "$name" "$type"
128         fun="fetch_$type"
129         tfun=$(type -t "$fun")
130         if [ "$tfun" = 'function' ]; then
131                 "$fun" "$name"
132         fi
133 done
134
135 if ! cd ../quilt; then
136         printf 'hmmm, what happened to the quilt directory?\n' 1>&2
137         exit 1
138 fi
139 git add -A .
140 if [ "$(git status --porcelain)" ]; then
141         git commit -v -a -m "$(date '+%F-%H:%M')" -e
142 fi
143
144 exit 0