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
|
---|
16 | MYVERSION=""
|
---|
17 | FILES=""
|
---|
18 |
|
---|
19 | while 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
|
---|
36 | done
|
---|
37 |
|
---|
38 | if [ -z "$FILES" ]; then
|
---|
39 | echo "ERROR: no inputs files are given via --file parameter!"
|
---|
40 | exit 1
|
---|
41 | fi
|
---|
42 |
|
---|
43 |
|
---|
44 | write_files () {
|
---|
45 | if [ -z "$FILES" ]; then
|
---|
46 | FILES="*.spec *.dsc"
|
---|
47 | fi
|
---|
48 | if [ -z "$MYOUTDIR" ]; then
|
---|
49 | echo "ERROR: no output directory is given via --outdir parameter!"
|
---|
50 | exit 1
|
---|
51 | fi
|
---|
52 |
|
---|
53 | for i in $FILES; do
|
---|
54 | FILE=`ls -1 $i 2>/dev/null`
|
---|
55 | [ -e "$FILE" ] || continue
|
---|
56 |
|
---|
57 | sed "0,/^Version:\(\s*\)[^%]*/s//Version:\1$MYVERSION/" "$FILE" > "$MYOUTDIR/$FILE" || exit 1
|
---|
58 | echo "Updated first occurrence (if any) of Version in $FILE to $MYVERSION"
|
---|
59 | if [ "${FILE%.spec}" != "$FILE" ]; then
|
---|
60 | # set release back to zero after version upgrade, will be increased by OBS during build
|
---|
61 | # also keep macros in release in case of fedora/mandriva
|
---|
62 | sed -r -i "s,^Release:(\s*)[^%]*,Release:\10," "$MYOUTDIR/$FILE" || exit 1
|
---|
63 | fi
|
---|
64 |
|
---|
65 | if [ "${FILE#_service:}" != "$FILE" ]; then
|
---|
66 | # we can remove service files, no need to store them twice
|
---|
67 | rm -f "$FILE"
|
---|
68 | fi
|
---|
69 | done
|
---|
70 | }
|
---|
71 |
|
---|
72 | filesize()
|
---|
73 | {
|
---|
74 | stat --format='%s' $*
|
---|
75 | }
|
---|
76 |
|
---|
77 | md5()
|
---|
78 | {
|
---|
79 | md5sum $* | cut -f 1 -d ' '
|
---|
80 | }
|
---|
81 |
|
---|
82 | export LANG=C
|
---|
83 |
|
---|
84 | FILES_DSC="*.dsc"
|
---|
85 |
|
---|
86 | # update the file list in the description file
|
---|
87 | for FILE_DSC in $FILES_DSC; do
|
---|
88 | [ -e $FILE_DSC ] || continue
|
---|
89 | printf "$0: modifing file $FILE_DSC, adding "
|
---|
90 | grep -q "^Files:" $FILE_DSC || echo "Files: " >> $FILE_DSC
|
---|
91 | for filename in $FILES; do
|
---|
92 | path=`ls -1 "$filename 2>/dev/null" || eval ls -1 "_service:*:$filename 2>/dev/null"`
|
---|
93 | [ -e $path ] || continue
|
---|
94 | printf "${path##*:} (${path})"
|
---|
95 | printf ' %s %s %s\n' `md5 $path` `filesize $path` ${path##*:} >> $FILE_DSC
|
---|
96 | done
|
---|
97 | printf "\n"
|
---|
98 | done
|
---|
99 |
|
---|
100 | exit 0
|
---|