Mailinglist Archive: opensuse-buildservice (151 mails)

< Previous Next >
Re: [opensuse-buildservice] EXE package format
  • From: Martin Koegler <martin.koegler@xxxxxxxxx>
  • Date: Sun, 2 Mar 2014 19:55:53 +0100
  • Message-id: <20140302185553.GA1186@mail.zuhause>
On Thu, Feb 27, 2014 at 09:52:06PM +0100, Martin Koegler wrote:
One usefull addtion to the source services would be a "sed" service.

Would it be possible to get something like the attached sketch into OBS?

Regards,
Martin
#!/bin/bash

# A simple script to update spec or dsc file
# very, very simple. I am happy about patches which handles multiple files with
different version numbers
#
# (C) 2014 martin.koegler@xxxxxxxxx
# (C) 2010 by Adrian Schröter <adrian@xxxxxxx>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# See http://www.gnu.org/licenses/gpl-2.0.html for full license text.


# defaults
REGEX=
FILES=""

while test $# -gt 0; do
case $1 in
*-regex)
REGEX="$2"
shift
;;
*-file)
FILES="$FILES ${2##*/}"
shift
;;
*-outdir)
MYOUTDIR="$2"
shift
;;
*)
echo Unknown parameter $1.
echo 'Usage: regex_replace --regex $REGEX --file $FILE --outdir $OUT'
exit 1
;;
esac
shift
done

write_files () {
if [ -z "$REGEX" ]; then
echo "ERROR: no regular expresion is given via --regex parameter!"
exit 1
fi
if [ -z "$FILES" ]; then
echo "ERROR: no file is given via --file parameter!"
exit 1
fi
if [ -z "$MYOUTDIR" ]; then
echo "ERROR: no output directory is given via --outdir parameter!"
exit 1
fi

for i in $FILES; do
FILE=`ls -1 $i 2>/dev/null`
[ -e "$FILE" ] || continue

sed -e "$REGEX" "$FILE" > "$MYOUTDIR/$FILE" || exit 1

if [ "${FILE#_service:}" != "$FILE" ]; then
# we can remove service files, no need to store them twice
rm -f "$FILE"
fi
done
}

write_files

exit 0
<service name="regex_replace">
<summary>Manipulate files via regualar expressions</summary>
<description>This service updates files via regular expressions.
</description>
<parameter name="regex">
<description>Sed compatible regular expression</description>
</parameter>
<parameter name="file">
<description>Update the given file.</description>
</parameter>
</service>

< Previous Next >
Follow Ups