/[gentoo-alt]/trunk/prefix/scripts/eupdate.in
Gentoo

Contents of /trunk/prefix/scripts/eupdate.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1583 - (show annotations) (download)
Fri Sep 22 15:46:04 2006 UTC (8 years, 7 months ago) by grobian
File MIME type: text/plain
File size: 7064 byte(s)
eupdate.in: magic differy to update ebuilds from the main tree to the
prefix tree


1 #!/usr/bin/env bash
2
3 # <grobian@gentoo.org> -- 2006-09-22
4 # eupdate: a not yet fully complete bucket of voodoo to sync a the
5 # prefix tree with the mainline tree. Strategies followed are largerly
6 # based on cvs revision numbers and diffs between those revisions. For
7 # the real internals, please look at the comments below in the code. In
8 # general, this script checks if an ebuild contains the most recent
9 # changes to it, and if there is a newer ebuild available. In both
10 # cases (cross) diffing techniques are used to maintain the manually
11 # made changes.
12 #
13 # This script doesn't run out of the box, you have to feed it some paths
14 # so it can do it's magic stuff. Also, you have to be a gentoo
15 # developer with cvs access. (Or when anoncvs is available, every user
16 # can do it.) For your convenience it is intended that you rename this
17 # file to something without the .in and change the paths below.
18
19 # Main Tree Directory, an rsynced portage tree is fine
20 MTREEDIR='/usr/portage'
21 # Prefix Tree Directory
22 PTREEDIR='/my/prefix/usr/portage'
23 # How to reach the CVS server for retrieving revision diffs
24 CVSROOT=':ext:developer@cvs.gentoo.org:/var/cvsroot/'
25 # Don't touch this. You really don't want to.
26 CVSMODULE='gentoo-x86'
27 # Voodoo to figure out what package you're currently messing with
28 EPACKAGE="`pwd -P`"; EPACKAGE=${EPACKAGE#*${PTREEDIR}/}
29
30 get_cvsversion() {
31 if [[ -z $1 ]];
32 then
33 echo 0
34 return
35 fi
36
37 ver=`egrep '^# \\\$Header:' "$1" | egrep -o "v [0-9.]+"`
38 if [[ $ver == "" ]];
39 then
40 echo 0
41 return
42 fi
43 echo ${ver#v }
44 }
45
46 get_ebuildversion() {
47 if [[ -z $1 ]];
48 then
49 echo 0
50 return
51 fi
52
53 # strip extention
54 t=${1%.ebuild}
55 # strip package name
56 t=${t#*-}
57 # sometimes there are dashes in the package name
58 while [[ ${t:0:1} < "0" || ${t:0:1} > "9" ]];
59 do
60 t=${t#*-}
61 done
62
63 ver=`echo $t | cut -d'-' -f1`
64 rev=`echo ${t#$ver} | cut -d'-' -f2`
65 t=$ver
66 ver=`echo $t | cut -d'_' -f1`
67 suf=`echo ${t#$ver} | cut -d'_' -f2`
68
69 # somehow "normalise" ver to a value like 0000.0000.0000.0000.0000
70 ver=`echo $ver | awk -F'.' '{
71 printf("%4s.%4s.%4s.%4s.%4s", $1, $2, $3, $4, $5);
72 }' | sed 's| |-|g'`
73 # turn suf into a int, keeping precedence rules
74 # alpha 100000
75 # beta 200000
76 # pre 300000
77 # rc 400000
78 # (none) 500000
79 # p 600000
80 case $suf in
81 alpha*)
82 suf=$((${suf#alpha} + 100000))
83 ;;
84 beta*)
85 suf=$((${suf#beta} + 200000))
86 ;;
87 pre*)
88 suf=$((${suf#pre} + 300000))
89 ;;
90 rc*)
91 suf=$((${suf#rc} + 400000))
92 ;;
93 p*)
94 suf=$((${suf#p} + 600000))
95 ;;
96 *)
97 suf=500000
98 ;;
99 esac
100 # turn rev into a normal int, starting with 1000
101 rev=$((${rev#r} + 1000))
102 # echo "ver: $ver, suf: $suf, rev: $rev"
103 echo "$ver.$suf.$rev"
104 }
105
106 get_versionebuild() {
107 if [[ -z $1 ]];
108 then
109 echo 0
110 return
111 fi
112
113 echo $1 | sed 's|-||g' | awk -F'.' '{
114 out = $1;
115 # should only have empty ones at the end, never inbetween
116 if ($2 != "") { out = out "." $2; }
117 if ($3 != "") { out = out "." $3; }
118 if ($4 != "") { out = out "." $4; }
119 if ($5 != "") { out = out "." $5; }
120
121 if ($6 == 100000) {
122 out = out "_alpha";
123 } else if ($6 > 100000 && $6 < 200000) {
124 out = out "_alpha" ($6 - 100000);
125 } else if ($6 == 200000) {
126 out = out "_beta";
127 } else if ($6 > 200000 && $6 < 300000) {
128 out = out "_beta" ($6 - 200000);
129 } else if ($6 == 300000) {
130 out = out "_pre";
131 } else if ($6 > 300000 && $6 < 400000) {
132 out = out "_pre" ($6 - 300000);
133 } else if ($6 == 400000) {
134 out = out "_rc";
135 } else if ($6 > 400000 && $6 < 500000) {
136 out = out "_rc" ($6 - 400000);
137 } else if ($6 == 600000) {
138 out = out "_p";
139 } else if ($6 > 600000 && $6 < 700000) {
140 out = out "_p" ($6 - 600000);
141 }
142 if ($7 > 1000) {
143 out = out "-r" ($7 - 1000);
144 }
145
146 print out;
147 }'
148 }
149
150 if [[ ! -d ${MTREEDIR}/${EPACKAGE} ]];
151 then
152 echo "no such package in main tree: ${EPACKAGE}"
153 exit -1
154 fi
155
156 echo "Processing ${EPACKAGE}"
157 mt=`cd "${MTREEDIR}"/${EPACKAGE}/ && ls *.ebuild`
158 pt=`ls *.ebuild`
159 # do a nested loop join, where we know that both sides are sorted and
160 # that pt is more important, because we're not interested in older
161 # versions
162 for mte in $mt;
163 do
164 mtev=$(get_ebuildversion $mte)
165 [[ $mtev > $mtelv ]] && mtelv=$mtev
166 for pte in $pt;
167 do
168 if [[ $mte == $pte ]];
169 then
170 # look inside the files to see if the file was updated or not
171 echo -n " found $mte in both ... "
172 mtecv=$(get_cvsversion "${MTREEDIR}/${EPACKAGE}"/$mte)
173 ptecv=$(get_cvsversion $pte)
174 # Gentoo never increments the major, and branches are not
175 # allowed, so we can make things easy and only use the minor
176 if [[ ${mtecv#1.} -eq ${ptecv#1.} ]];
177 then
178 echo "up-to-date (rev: $mtecv)"
179 elif [[ ${mtecv#1.} -gt ${ptecv#1.} ]];
180 then
181 echo "out-of-date, applying diff -r$ptecv -r$mtecv"
182 # checkout both original versions and make the diffs,
183 # ignoring keywords
184 cvs -d"${CVSROOT}" \
185 checkout -r$ptecv -p ${CVSMODULE}/${EPACKAGE}/$pte \
186 2> /dev/null \
187 > /var/tmp/$pte-$ptecv.tmp
188 cvs -d"${CVSROOT}" \
189 checkout -r$mtecv -p ${CVSMODULE}/${EPACKAGE}/$mte \
190 2> /dev/null \
191 > /var/tmp/$mte-$mtecv.tmp
192 # make KEYWORDS and EAPI void in the diff
193 sed -i \
194 -e 's|^KEYWORDS=.*$|'"`egrep '^KEYWORDS=' $pte`"'|' \
195 -e 's|^# \$Header:.*$|&\n\nEAPI="prefix"|' \
196 /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp
197 # show what's going to change
198 diff -U 1 /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp
199 # (attempt to) do it!
200 diff -u /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp \
201 | patch --no-backup-if-mismatch $pte
202 rm /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp
203 fi
204 fi
205 done
206 done
207 for pte in $pt;
208 do
209 ptev=$(get_ebuildversion $pte)
210 [[ $ptev > $ptelv ]] && ptelv=$ptev
211 done
212 if [[ $mtelv > $ptelv ]];
213 then
214 mver=$(get_versionebuild $mtelv)
215 pver=$(get_versionebuild $ptelv)
216 echo -n " new version in main tree: ${mver} [${pver}] ... "
217 mte=`basename "${MTREEDIR}/${EPACKAGE}"/*${mver}.ebuild`
218 pte=`echo *${pver}.ebuild`
219 mtecv=$(get_cvsversion "${MTREEDIR}/${EPACKAGE}"/$mte)
220 ptecv=$(get_cvsversion $pte)
221 echo "cross diff from $ptecv to $mtecv"
222 # checkout both original versions and make the diffs,
223 # ignoring keywords
224 cvs -d"${CVSROOT}" \
225 checkout -r$ptecv -p ${CVSMODULE}/${EPACKAGE}/$pte \
226 2> /dev/null \
227 > /var/tmp/$pte-$ptecv.tmp
228 cvs -d"${CVSROOT}" \
229 checkout -r$mtecv -p ${CVSMODULE}/${EPACKAGE}/$mte \
230 2> /dev/null \
231 > /var/tmp/$mte-$mtecv.tmp
232 # create the new file to patch against
233 cp $pte $mte
234 # sanitise the $Header line, because it may differ being in the
235 # Attic or something
236 sed -i \
237 -e 's|^# \$Header: .*/'$pte',v \(.*\)$|# $Header: '$pte',v \1|' \
238 $mte /var/tmp/$pte-$ptecv.tmp
239 # make KEYWORDS and EAPI void in the diff
240 sed -i \
241 -e 's|^KEYWORDS=.*$|'"`egrep '^KEYWORDS=' $pte`"'|' \
242 -e 's|^# \$Header:.*$|&\n\nEAPI="prefix"|' \
243 /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp
244 # (attempt to) do it!
245 diff -u /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp \
246 | patch --no-backup-if-mismatch $mte
247 rm /var/tmp/$pte-$ptecv.tmp /var/tmp/$mte-$mtecv.tmp
248 fi
249 echo "done"

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20