]> git.ozlabs.org Git - next-scripts/blob - fetch_trees
74c75848344269c18f4dfcd2637d0bdf32ab8613
[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         if ! cd ../mmotm; then
42                 printf 'Cannot chdir to ../mmotm\n' 1>&2
43                 return
44         fi
45         if ! rsync -az --partial --exclude '.git*' \
46                         --exclude broken-out.tar.gz --delete \
47                         ozlabs.org::akpm/mmotm/. .; then
48                 git reset --hard
49                 printf 'Fetcing mmotm failed\n' 1>&2
50                 return
51         fi
52         git add -A .
53         if [ "$(git status --porcelain)" ]; then
54                 git commit -m "$(head -n 1 .DATE)"
55         fi
56 )
57
58 fetch_quilt()
59 (
60         url=$(get_field "$1" 4)
61         url=${url%/}    # strip trailing / if necessary
62
63         if ! cd ../quilt; then
64                 printf 'Cannot chdir to ../quilt\n' 1>&2
65                 return
66         fi
67         if ! [ -d "$1" ] && ! mkdir "$1"; then
68                 printf 'Cannot create quilt directory for %s\n' "$1" 1>&2
69                 return
70         fi
71         if ! cd "$1"; then
72                 printf 'Cannot chdir to quilt directory for %s\n' "$1" 1>&2
73                 return
74         fi
75         if ! wget -N -nv --no-cache --no-xattr "$url/series"; then
76                 printf 'Wget of %s series file failed\n' "$1" 1>&2
77                 cd ..
78                 rm -rf "$1"
79                 git checkout "$1"
80                 return
81         fi
82         find . -type f | sed 's,^./,,;/^series$/d' | sort >.series.old
83         if grep -q NEXT_PATCHES series; then
84                 sed -n '/NEXT_PATCHES_START/,/NEXT_PATCHES_END/p' series
85         else
86                 cat series
87         fi |
88                 sed -e 's/[ \t]*#.*$//' -e '/^[ \t]*$/d' |
89                 sort >.series.next
90         if [ -s .series.next ]; then
91                 if ! wget -N -nv --no-cache --no-xattr -B "$url/" -i .series.next; then
92                         printf 'Wget of series %s failed\n' "$1" 1>&2
93                         cd ..
94                         rm -rf "$1"
95                         git checkout "$1"
96                         return
97                 fi
98         fi
99         comm -23 .series.old .series.next | xargs -r rm -f
100         rm -f .series.old .series.next
101 )
102
103 trees="$*"
104 if ! [ "$trees" ]; then
105         trees=$(awk -F '\t' '/^[^#]/ && $2 != "branch" { print $3 }' "$CTRL_FILE")
106 fi
107
108 for name in $trees; do
109         if [ -n "$start_from" ]; then
110                 if [ "$name" = "$start_from" ]; then
111                         start_from=''
112                 else
113                         continue
114                 fi
115         fi
116
117         type=$(get_field "$name" 2)
118         if ! [ "$type" ]; then
119                 printf '%s: unknown tree\n' "$name" 1>&2
120                 continue
121         fi
122
123         printf '%s: %s\n' "$name" "$type"
124         fun="fetch_$type"
125         tfun=$(type -t "$fun")
126         if [ "$tfun" = 'function' ]; then
127                 "$fun" "$name"
128         fi
129 done
130
131 if ! cd ../quilt; then
132         printf 'hmmm, what happened to the quilt directory?\n' 1>&2
133         exit 1
134 fi
135 git add -A .
136 if [ "$(git status --porcelain)" ]; then
137         git commit -v -a -m "$(date '+%F-%H:%M')" -e
138 fi
139
140 exit 0