summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViktor Hercinger <vhercing@redhat.com>2013-04-02 13:24:45 +0200
committerViktor Hercinger <vhercing@redhat.com>2013-04-02 13:24:45 +0200
commitdabbf6b844672b640cc19a4f12b9cd0ecb2e3931 (patch)
tree9fd1b7efaeddb1fe5f596014eff92377ef964a25
parent021fec16ef3f4c610e5c6d9538a3d73f93f3813f (diff)
downloadrpm-tools-dabbf6b844672b640cc19a4f12b9cd0ecb2e3931.tar.gz
rpm-tools-dabbf6b844672b640cc19a4f12b9cd0ecb2e3931.tar.xz
rpm-tools-dabbf6b844672b640cc19a4f12b9cd0ecb2e3931.zip
added source-archive script
-rw-r--r--rpmtools.spec5
-rwxr-xr-xscripts/source-archive155
2 files changed, 159 insertions, 1 deletions
diff --git a/rpmtools.spec b/rpmtools.spec
index 7be52bf..fb3dbf9 100644
--- a/rpmtools.spec
+++ b/rpmtools.spec
@@ -1,6 +1,6 @@
Name: rpmtools
Version: 1.0
-Release: 6%{?dist}
+Release: 7%{?dist}
Summary: Local RPM toolkit
BuildArch: noarch
@@ -29,6 +29,9 @@ install -m 755 * %{buildroot}/%{_bindir}
%{_bindir}/*
%changelog
+* Tue Apr 02 2013 Hercinger Viktor <hercinger.viktor@gmail.com> - 1.0-7
+- added archive source creator
+
* Fri Mar 29 2013 Hercinger Viktor <hercinger.viktor@gmail.com> - 1.0-6
- do not clean up repo before rebuilding with new packages
diff --git a/scripts/source-archive b/scripts/source-archive
new file mode 100755
index 0000000..790d1b9
--- /dev/null
+++ b/scripts/source-archive
@@ -0,0 +1,155 @@
+#!/bin/sh
+
+CURRENT_DIR=$(pwd)
+PKGNAME=$(basename $CURRENT_DIR)
+
+FORMAT="tgz"
+VERSION="1.0"
+SPECDIR="$HOME/.specs"
+OUTPUT=$SPECDIR/$PKGNAME
+UPDATE_SOURCES=1
+
+function die
+{
+ echo $@ >&2
+ exit 1
+}
+
+function check_set
+{
+ VALUE=$1
+ shift
+
+ while [ $# -ne 0 ]
+ do
+ if [ "x$1" = "x$VALUE" ]
+ then
+ return 0
+ fi
+ shift
+ done
+
+ return 1
+}
+
+function compress_tar
+{
+ tee
+}
+
+function compress_tgz
+{
+ gzip
+}
+
+function compress_tbz2
+{
+ bzip2
+}
+
+function compress_txz
+{
+ xz
+}
+
+function extension
+{
+ case $1 in
+ tar)
+ echo tar
+ ;;
+
+ tgz)
+ echo tar.gz
+ ;;
+
+ tbz2)
+ echo tar.bz2
+ ;;
+
+ txz)
+ echo tar.xz
+ ;;
+
+ *)
+ die "Unkown format $1"
+ ;;
+ esac
+}
+
+while [ $# -gt 0 ]
+do
+ OPTION=$1
+ shift
+
+ case $OPTION in
+ -f|--format)
+ FORMAT=$1
+ shift
+ ;;
+
+ -v|--version)
+ VERSION=$1
+ shift
+ ;;
+
+ -o|--output)
+ OUTPUT=$1
+ shift
+ ;;
+
+ --no-update)
+ UPDATE_SOURCES=0
+ ;;
+
+ -h|--help)
+ echo "Create archive from the current git repository
+
+usage: $0 [ options ]
+
+options:
+ -f --format Format of the archive (see supported formats below) (default: $FORMAT)
+ -v --version Set version of script (default: $VERSION)
+ -o --output Output directory or file (default: $OUTPUT)
+ --no-update Do not update sources file
+
+ -h --help Show this help message
+
+Supported formats:
+ tar
+ tgz
+ tbz2
+ txz"
+ exit 1
+ ;;
+
+ -*)
+ echo "Unkown option $OPTION" >&2
+ exit 1
+ ;;
+ esac
+done
+
+[ ! -d $OUTPUT -o ! -d $(dirname $OUTPUT) ] && die "$OUTPUT is not a file or directory"
+
+check_set $FORMAT tar tgz tbz2 txz || die "$FORMAT is not supported"
+
+if [ -d $OUTPUT ]
+then
+ SAVE_TO=$OUTPUT/$PKGNAME-$VERSION.$(extension $FORMAT)
+else
+ SAVE_TO=$OUTPUT
+fi
+
+git archive --format=tar --prefix=$PKGNAME-$VERSION/ HEAD | compress_$FORMAT > $SAVE_TO
+echo "Archive saved to $SAVE_TO"
+
+if [ $UPDATE_SOURCES -ne 0 -a -d $OUTPUT -a -f $OUTPUT/sources ]
+then
+ ARCH=$(basename $SAVE_TO)
+ cd $OUTPUT
+ md5sum $ARCH > sources
+ cd - >/dev/null
+
+ echo "MD5 checksum saved to 'sources' file"
+fi