File Ref of Package jw-env

#!/bin/bash
#
# A reimplementation of Re using quilt.
# this also refrehses the patches while applying them, so that
# the packager can see the quality of his patches.
#
# (C) Copyright 2010-2012 jw@suse, Novell Inc.
# Distribute under GPLv2 or GPLv3, have mercy.
#
# 2010-08-26, v0.2 -- jw, added hints for quilt usage.
# 2010-11-01, v0.3 -- jw, make sure patches symlink exists.
# 2011-02-09, v0.4 -- jw, added workaround for unsupported %translation-update-upstream
# 2011-04-15, v0.5 -- jw, added workaround for _service:bla:*.tar.bz2
# 2012-03-27, v0.6 -- jw, quilt refresh -U 5 instead of -U 3
# 2012-09-30, v0.6a -- jw, added workaround for BuildRequires: -makeinfo -post-build-check
# 2012-10-03, v0.7 -- jw, increased diff context to -U 5
# 2013-03-02, v0.8 -- jw, move to /tmp, and symlink. This avoids odd issues due to : in path.
#                         gcc would fail, several perl modules' test suites would fail.
version=0.8
spec=$1
refresh=1

if [ "x$1" = "x-n" ]; then
  refresh=
  spec=""
fi

if [ "x$2" = "x-n" ]; then
  refresh=
fi
if [ "x$1" = 'x-h' -o "x$1" = 'x--help' ]; then
  cat << EOF
Ref version $version"

Usage: $0 [*.spec] [ -n ]
   -n        do not refresh patches

Ref unpacks an RPM source directory and applies all patches
according to the spec-file.
It is implemented via quilt setup and quilt push.
Unless option -n is given, it also does quilt refresh on all patches.

EOF

  exit;
fi

if [ -z "$spec" ]; then spec=*.spec; fi
echo "Using specfile: $spec"

for file in $(ls); do
  case $file in
  _service:*)
    short=${file##_service*:}
    test -e $short && continue
    echo symlinking $short to $file
    ln -s $file $short
    ;;
  esac
done

# quilt always complains about several unexpanded macros. hack them away.
# %glib2_gsettings_schema_requires	# in e.g. brasero 
# %{perl_requires}			# in any perl package
# Release: 18.<RELEASE34>		# in older packages. e.g. freetype2 
# BuildRelease: -makeinfo
rm -rf $(readlink BUILD) BUILD
mkdir /tmp/Ref-$$-BUILD
sed -e 's/%{perl_requires}//' \
    -e 's/^Release: .*/Release: 0/' \
    -e 's/%glib2_gsettings_schema_requires//' \
    -e 's/^BuildRequires:\s.*//' \
    < $spec > /tmp/Ref-$$-BUILD/.spec
echo quilt setup -v -d /tmp/Ref-$$-BUILD /tmp/Ref-$$-BUILD/.spec
quilt setup -v -d /tmp/Ref-$$-BUILD /tmp/Ref-$$-BUILD/.spec || exit 0

ln -s /tmp/Ref-$$-BUILD BUILD
rm -f /tmp/Ref-$$-BUILD/*/patches
# all meta stuff start with dot, so we can use * to enter the main directory.
ln -s $(pwd) $(echo /tmp/Ref-$$-BUILD/*)/patches
ln -s $(pwd) /tmp/Ref-$$-BUILD/.src
cd BUILD/*
quilt unapplied

while quilt push; do
  test $refresh && quilt refresh -U 5 --diffstat
done


echo "unpacked in ./BUILD"

# the blurb below is taken from http://en.opensuse.org/openSUSE:Junior_jobs
cat <<EOF

Suggested actions:
      pushd BUILD/*

      ## continue last patch
      quilt edit src/half_fixed_file.c	
      quilt refresh -U 5 --diffstat 	# now the patch is updated

      ## create a new patch
      quilt new another_bug.diff	
      quilt edit src/more_bugs.c
      quilt refresh -p1 -U 5 --diffstat	# now the new patch exists

      ## import a new patch
      quilt import -P bnc633938.patch ~/somewhere/bnc633938/fix.patch
      vi patches/bnc633938.patch	# trim suff that we know to fail, if any.
      quilt push 			# if hunks fail: push -f; vi *.rej
      quilt refresh -p1 -U 5 --diffstat	# now the new patch is fine

      popd
      osc vc; osc commit
EOF

openSUSE Build Service is sponsored by