source: obs/obs-service-dsc_filelist/usr/lib/obs/service/dsc_filelist@ 1129

Last change on this file since 1129 was 1129, checked in by joergs, on Dec 19, 2012 at 7:02:47 PM

better wildcsrd handling

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/bin/bash
2
3# A simple script to update spec or dsc file
4# very, very simple. I am happy about patches which handles multiple files with different version numbers
5#
6# (C) 2012 by <joerg.steffens@dass-it.de>
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License
10# as published by the Free Software Foundation; either version 2
11# of the License, or (at your option) any later version.
12# See http://www.gnu.org/licenses/gpl-2.0.html for full license text.
13
14
15# defaults
16MYVERSION=""
17FILES=""
18
19while test $# -gt 0; do
20 case $1 in
21 *-file)
22 FILES="$FILES $2"
23 shift
24 ;;
25 *-outdir)
26 MYOUTDIR="$2"
27 shift
28 ;;
29 *)
30 echo Unknown parameter $1.
31 echo 'Usage: set_version --version $VERSION --file $FILE --basename $BASENAME --outdir $OUT'
32 exit 1
33 ;;
34 esac
35 shift
36done
37
38if [ -z "$FILES" ]; then
39 echo "ERROR: no inputs files are given via --file parameter!"
40 exit 1
41fi
42
43
44
45get_version_from_file () {
46 if [ -z "$MYVERSION" ]; then
47 MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tar.*,\1,p" | head -n 1`
48 fi
49 if [ -z "$MYVERSION" ]; then
50 MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tgz$,\1,p" | head -n 1`
51 fi
52 if [ -z "$MYVERSION" ]; then
53 MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).tbz2$,\1,p" | head -n 1`
54 fi
55 if [ -z "$MYVERSION" ]; then
56 MYVERSION=`ls -1t | sed -n "s,$BASENAME.*-\([0123456789].*\).zip$,\1,p" | head -n 1`
57 fi
58 if [ -z "$MYVERSION" ]; then
59 echo "ERROR: no version is given and can't get detected automatically"
60 exit 1
61 fi
62 echo "Detected version as $MYVERSION"
63}
64
65write_files () {
66 if [ -z "$FILES" ]; then
67 FILES="*.spec *.dsc"
68 fi
69 if [ -z "$MYOUTDIR" ]; then
70 echo "ERROR: no output directory is given via --outdir parameter!"
71 exit 1
72 fi
73
74 for i in $FILES; do
75 FILE=`ls -1 $i 2>/dev/null`
76 [ -e "$FILE" ] || continue
77
78 sed "0,/^Version:\(\s*\)[^%]*/s//Version:\1$MYVERSION/" "$FILE" > "$MYOUTDIR/$FILE" || exit 1
79 echo "Updated first occurrence (if any) of Version in $FILE to $MYVERSION"
80 if [ "${FILE%.spec}" != "$FILE" ]; then
81 # set release back to zero after version upgrade, will be increased by OBS during build
82 # also keep macros in release in case of fedora/mandriva
83 sed -r -i "s,^Release:(\s*)[^%]*,Release:\10," "$MYOUTDIR/$FILE" || exit 1
84 fi
85
86 if [ "${FILE#_service:}" != "$FILE" ]; then
87 # we can remove service files, no need to store them twice
88 rm -f "$FILE"
89 fi
90 done
91}
92
93#get_version_from_file
94#write_files
95
96filesize()
97{
98 stat --format='%s' $*
99}
100
101md5()
102{
103 md5sum $* | cut -f 1 -d ' '
104}
105
106export LANG=C
107
108FILES_DSC="*.dsc"
109
110# update the file list in the description file
111for FILE_DSC in $FILES_DSC; do
112 [ -e $FILE_DSC ] || continue
113 printf "$0: modifing file $FILE_DSC, adding "
114 grep -q "^Files:" $FILE_DSC || echo "Files: " >> $FILE_DSC
115 for filename in $FILES; do
116 path=`ls -1 "$filename 2>/dev/null" || eval ls -1 "_service:*:$filename 2>/dev/null"`
117 [ -e $path ] || continue
118 printf "${path##*:} (${path})"
119 printf ' %s %s %s\n' `md5 $path` `filesize $path` ${path##*:} >> $FILE_DSC
120 done
121 printf "\n"
122done
123
124exit 0
Note: See TracBrowser for help on using the repository browser.