From 4d7aa5d98c4e923e730d1c8b8531be6b4eae3bc199250137184ad1b68ea764bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Wed, 11 May 2011 13:04:12 +0000 Subject: [PATCH] osc copypac from project:openSUSE:Tools package:obs-service-recompress revision:5 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-recompress?expand=0&rev=7 --- obs-service-recompress.spec | 2 -- recompress | 72 ++++++++++++++----------------------- recompress.service | 3 -- 3 files changed, 26 insertions(+), 51 deletions(-) diff --git a/obs-service-recompress.spec b/obs-service-recompress.spec index 3b56633..006995a 100644 --- a/obs-service-recompress.spec +++ b/obs-service-recompress.spec @@ -21,8 +21,6 @@ It supports to compress, uncompress or recompress files from or to bz2 : Bzip2 Compression xz : XZ Compression -It also allow to rename the archive - %prep %setup -q -D -T 0 -n . diff --git a/recompress b/recompress index 3e97e5c..56b350e 100644 --- a/recompress +++ b/recompress @@ -1,21 +1,17 @@ #!/bin/bash -set -x -# A simple script to recomress the archive -# -# +# A simple script to checkout or update a svn or git repo as source service +# # (C) 2010 by Adrian Schröter -# -# 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. - +# +# 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 MYCOMPRESSION="" -RENAME_PATTERN="" FILES="" while test $# -gt 0; do @@ -24,10 +20,6 @@ while test $# -gt 0; do MYCOMPRESSION="$2" shift ;; - *-rename_pattern) - RENAME_PATTERN="$2" - shift - ;; *-file) FILES="$FILES ${2##*/}" shift @@ -38,7 +30,7 @@ while test $# -gt 0; do ;; *) echo Unknown parameter $1. - echo 'Usage: recompress --compression $COMPRESSION --rename_pattern $RENAME_PATTERN --file $FILE --outdir $OUT' + echo 'Usage: recompress --compression $COMPRESSION --file $FILE --outdir $OUT' exit 1 ;; esac @@ -56,26 +48,21 @@ if [ -z "$MYOUTDIR" ]; then echo "ERROR: no output directory is given via --outdir parameter!" exit 1 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 - FILE=`ls -1 $i` + FILE=`ls -1 "$i" || ls -1 "_service:*:$i"` + if [ ! -f "$FILE" ]; then + echo "Unknown file $i" + exit 1 + fi UNCOMPRESS="cat" BASENAME="$FILE" if [ "${FILE%.gz}" != "$FILE" ]; then UNCOMPRESS="gunzip -c" BASENAME="${FILE%.gz}" + elif [ "${FILE%.tgz}" != "$FILE" ]; then + UNCOMPRESS="gunzip -c" + BASENAME="${FILE%.tgz}.tar" elif [ "${FILE%.bz2}" != "$FILE" ]; then UNCOMPRESS="bunzip2 -c" BASENAME="${FILE%.bz2}" @@ -83,33 +70,26 @@ for i in $FILES; do UNCOMPRESS="xz -dc" BASENAME="${FILE%.xz}" 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 - gzip "$MYOUTDIR/$BASENAME" + COMPRESS="gzip -c -" + NEWFILE="${BASENAME#_service:}.gz" elif [ "$MYCOMPRESSION" == "bz2" ]; then - bzip2 "$MYOUTDIR/$BASENAME" + COMPRESS="bzip2 -c -" + NEWFILE="${BASENAME#_service:}.bz2" elif [ "$MYCOMPRESSION" == "xz" ]; then - xz "$MYOUTDIR/$BASENAME" + COMPRESS="xz -c -" + NEWFILE="${BASENAME#_service:}.xz" elif [ "$MYCOMPRESSION" == "none" ]; then COMPRESS="cat -" + NEWFILE="${BASENAME#_service:}" else echo "ERROR: Unknown compression $MYCOMPRESSION" exit 1 fi + # do the real work + $UNCOMPRESS "$FILE" | $COMPRESS > "$MYOUTDIR/$NEWFILE" || exit 1 if [ "${FILE#_service:}" != "$FILE" ]; then # we can remove service files, no need to store them twice diff --git a/recompress.service b/recompress.service index 9e1c1b2..ce6e14e 100644 --- a/recompress.service +++ b/recompress.service @@ -14,9 +14,6 @@ xz - - Rename the archive. You can use %VERSION% or %RELESE% variables - name of file to be recompressed. RegExp are allowed.