forked from pool/obs-service-recompress
Accepting request 69435 from home:dibo2010:buildservice
Added raname opttion OBS-URL: https://build.opensuse.org/request/show/69435 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-recompress?expand=0&rev=6
This commit is contained in:
parent
541c83f928
commit
8f7661f399
@ -21,6 +21,8 @@ It supports to compress, uncompress or recompress files from or to
|
|||||||
bz2 : Bzip2 Compression
|
bz2 : Bzip2 Compression
|
||||||
xz : XZ Compression
|
xz : XZ Compression
|
||||||
|
|
||||||
|
It also allow to rename the archive
|
||||||
|
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q -D -T 0 -n .
|
%setup -q -D -T 0 -n .
|
||||||
|
72
recompress
72
recompress
@ -1,17 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -x
|
||||||
|
|
||||||
# A simple script to checkout or update a svn or git repo as source service
|
# A simple script to recomress the archive
|
||||||
#
|
#
|
||||||
|
#
|
||||||
# (C) 2010 by Adrian Schröter <adrian@suse.de>
|
# (C) 2010 by Adrian Schröter <adrian@suse.de>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
# See http://www.gnu.org/licenses/gpl-2.0.html for full license text.
|
# See http://www.gnu.org/licenses/gpl-2.0.html for full license text.
|
||||||
|
|
||||||
|
|
||||||
# defaults
|
# defaults
|
||||||
MYCOMPRESSION=""
|
MYCOMPRESSION=""
|
||||||
|
RENAME_PATTERN=""
|
||||||
FILES=""
|
FILES=""
|
||||||
|
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
@ -20,6 +24,10 @@ while test $# -gt 0; do
|
|||||||
MYCOMPRESSION="$2"
|
MYCOMPRESSION="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
*-rename_pattern)
|
||||||
|
RENAME_PATTERN="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*-file)
|
*-file)
|
||||||
FILES="$FILES ${2##*/}"
|
FILES="$FILES ${2##*/}"
|
||||||
shift
|
shift
|
||||||
@ -30,7 +38,7 @@ while test $# -gt 0; do
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo Unknown parameter $1.
|
echo Unknown parameter $1.
|
||||||
echo 'Usage: recompress --compression $COMPRESSION --file $FILE --outdir $OUT'
|
echo 'Usage: recompress --compression $COMPRESSION --rename_pattern $RENAME_PATTERN --file $FILE --outdir $OUT'
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -48,21 +56,26 @@ if [ -z "$MYOUTDIR" ]; then
|
|||||||
echo "ERROR: no output directory is given via --outdir parameter!"
|
echo "ERROR: no output directory is given via --outdir parameter!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ -n $RENAME_PATTERN ] ; then
|
||||||
|
MYVERSION=""
|
||||||
|
MYRELEASE=""
|
||||||
|
if [ -f _service:extract_version:release ]; then
|
||||||
|
MYRELEASE=`cat _service:extract_version:release`
|
||||||
|
fi
|
||||||
|
if [ -f _service:extract_version:version ]; then
|
||||||
|
MYVERSION=`cat _service:extract_version:version`
|
||||||
|
fi
|
||||||
|
RENAME_PATTERN=${RENAME_PATTERN//%RELEASE%/$MYRELEASE}
|
||||||
|
RENAME_PATTERN=${RENAME_PATTERN//%VERSION%/$MYVERSION}
|
||||||
|
fi
|
||||||
|
|
||||||
for i in $FILES; do
|
for i in $FILES; do
|
||||||
FILE=`ls -1 "$i" || ls -1 "_service:*:$i"`
|
FILE=`ls -1 $i`
|
||||||
if [ ! -f "$FILE" ]; then
|
|
||||||
echo "Unknown file $i"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
UNCOMPRESS="cat"
|
UNCOMPRESS="cat"
|
||||||
BASENAME="$FILE"
|
BASENAME="$FILE"
|
||||||
if [ "${FILE%.gz}" != "$FILE" ]; then
|
if [ "${FILE%.gz}" != "$FILE" ]; then
|
||||||
UNCOMPRESS="gunzip -c"
|
UNCOMPRESS="gunzip -c"
|
||||||
BASENAME="${FILE%.gz}"
|
BASENAME="${FILE%.gz}"
|
||||||
elif [ "${FILE%.tgz}" != "$FILE" ]; then
|
|
||||||
UNCOMPRESS="gunzip -c"
|
|
||||||
BASENAME="${FILE%.tgz}.tar"
|
|
||||||
elif [ "${FILE%.bz2}" != "$FILE" ]; then
|
elif [ "${FILE%.bz2}" != "$FILE" ]; then
|
||||||
UNCOMPRESS="bunzip2 -c"
|
UNCOMPRESS="bunzip2 -c"
|
||||||
BASENAME="${FILE%.bz2}"
|
BASENAME="${FILE%.bz2}"
|
||||||
@ -70,26 +83,33 @@ for i in $FILES; do
|
|||||||
UNCOMPRESS="xz -dc"
|
UNCOMPRESS="xz -dc"
|
||||||
BASENAME="${FILE%.xz}"
|
BASENAME="${FILE%.xz}"
|
||||||
fi
|
fi
|
||||||
|
$UNCOMPRESS "$FILE" > "$MYOUTDIR/$BASENAME" || exit 1
|
||||||
|
|
||||||
|
if [ -n $RENAME_PATTERN ]; then
|
||||||
|
if [ "${BASENAME%.tar}" != "$BASENAME" ]; then
|
||||||
|
tar xf $MYOUTDIR/$BASENAME -C $MYOUTDIR || exit 1
|
||||||
|
OLDDIR=${BASENAME%.tar}
|
||||||
|
OLDDIR=${OLDDIR##_service:*:}
|
||||||
|
mv "$MYOUTDIR/$OLDDIR" "$MYOUTDIR/$RENAME_PATTERN" || exit 1
|
||||||
|
tar cf "$MYOUTDIR/$RENAME_PATTERN.tar" -C $MYOUTDIR $RENAME_PATTERN || exit 1
|
||||||
|
rm -rf "$MYOUTDIR/$RENAME_PATTERN" "$MYOUTDIR/$BASENAME"|| exit 1
|
||||||
|
BASENAME="$RENAME_PATTERN.tar"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$MYCOMPRESSION" == "gz" ]; then
|
if [ "$MYCOMPRESSION" == "gz" ]; then
|
||||||
COMPRESS="gzip -c -"
|
gzip "$MYOUTDIR/$BASENAME"
|
||||||
NEWFILE="${BASENAME#_service:}.gz"
|
|
||||||
elif [ "$MYCOMPRESSION" == "bz2" ]; then
|
elif [ "$MYCOMPRESSION" == "bz2" ]; then
|
||||||
COMPRESS="bzip2 -c -"
|
bzip2 "$MYOUTDIR/$BASENAME"
|
||||||
NEWFILE="${BASENAME#_service:}.bz2"
|
|
||||||
elif [ "$MYCOMPRESSION" == "xz" ]; then
|
elif [ "$MYCOMPRESSION" == "xz" ]; then
|
||||||
COMPRESS="xz -c -"
|
xz "$MYOUTDIR/$BASENAME"
|
||||||
NEWFILE="${BASENAME#_service:}.xz"
|
|
||||||
elif [ "$MYCOMPRESSION" == "none" ]; then
|
elif [ "$MYCOMPRESSION" == "none" ]; then
|
||||||
COMPRESS="cat -"
|
COMPRESS="cat -"
|
||||||
NEWFILE="${BASENAME#_service:}"
|
|
||||||
else
|
else
|
||||||
echo "ERROR: Unknown compression $MYCOMPRESSION"
|
echo "ERROR: Unknown compression $MYCOMPRESSION"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do the real work
|
|
||||||
$UNCOMPRESS "$FILE" | $COMPRESS > "$MYOUTDIR/$NEWFILE" || exit 1
|
|
||||||
|
|
||||||
if [ "${FILE#_service:}" != "$FILE" ]; then
|
if [ "${FILE#_service:}" != "$FILE" ]; then
|
||||||
# we can remove service files, no need to store them twice
|
# we can remove service files, no need to store them twice
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
<allowedvalue>xz</allowedvalue>
|
<allowedvalue>xz</allowedvalue>
|
||||||
<required/>
|
<required/>
|
||||||
</parameter>
|
</parameter>
|
||||||
|
<parameter name="rename_pattern">
|
||||||
|
<description>Rename the archive. You can use %VERSION% or %RELESE% variables</description>
|
||||||
|
</parameter>
|
||||||
<parameter name="file">
|
<parameter name="file">
|
||||||
<description>name of file to be recompressed. RegExp are allowed.</description>
|
<description>name of file to be recompressed. RegExp are allowed.</description>
|
||||||
<required/>
|
<required/>
|
||||||
|
Loading…
Reference in New Issue
Block a user