File sdsc-fetch-source-git of Package suse-doc-style-checker
#!/bin/bash
#
#
# Create sdsc source tarball from GitHub
# Makes it simpler to update the package.
#
# Copyright (C) 2015, 2016 SUSE Linux GmbH
#
# Authors:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
# Stefan Knorr <sknorr at suse dot de>
#
NAME=sdsc
REPOORG=openSUSE
REPONAME=suse-doc-style-checker
PNAME=suse-doc-style-checker
VERSION=
SPECFILE=${PNAME}.spec
TMPDIR=$(mktemp -q -d --tmpdir ${NAME}-XXXXXXXX)
OBSDIR=$(pwd)
#----------
# Functions
#----------
# exit on error
#
function exit_on_error {
echo -e "$1"
exit 1
}
function help {
echo -e "$(basename $0) <ARCHIVE_FILENAME>\n"
}
function download_archive {
echo "Downloading archive:"
(cd $TMPDIR && wget -nv $ARCHIVE_URL) || exit_on_error "Download of $ARCHIVE_URL failed"
}
function copy_archive {
echo "Copying archive:"
cp -v $ARCHIVE_URL $TMPDIR || exit_on_error "Copying of $ARCHIVE_URL failed"
}
function unpack_archive {
case ${ARCHIVE_NAME##*.} in
zip)
UNPACK="unzip"
ARCHIVE_DIR=$(basename $ARCHIVE_NAME .zip)
;;
gz)
UNPACK="tar xfz"
ARCHIVE_DIR=$(basename $ARCHIVE_NAME .tar.gz)
;;
bz2)
UNPACK="tar xfj"
ARCHIVE_DIR=$(basename $ARCHIVE_NAME .tar.bz2)
;;
*)
exit_on_error "Unknown archive format"
esac
}
#-----
# MAIN
#-----
#
# Check for archive file name
#
if [[ -z $1 ]]; then
exit_on_error "Please specify a URL for a $NAME release archive on Github, e.g.\https://github.com/$REPOORG/$REPONAME/archive/[TAG_NAME].tar.gz. Alternatively, use --tag [TAG_NAME]."
elif [[ $1 = '--tag' ]] && [[ $2 ]]; then
ARCHIVE_URL="https://github.com/$REPOORG/$REPONAME/archive/$2.tar.gz"
ARCHIVE_NAME="${ARCHIVE_URL##*/}"
else
ARCHIVE_URL="$1"
ARCHIVE_NAME="${ARCHIVE_URL##*/}"
fi
# This script needs to be called from the osc checkout directory, so
# lets check whether we are in the correct directory
#
if [[ ! -s $SPECFILE && ! -d .osc ]]; then
echo "Looks like you are not in the $NAME checkout directory."
read -p "Continue anyway (y/n) [n]: " CONT
if [[ n = $CONT || N = $CONT ]]; then
exit_on_error "Aborted by user."
fi
fi
#-----------
# Download archive
#
if [[ ${ARCHIVE_URL} == http* ]]; then
download_archive
unpack_archive
else
copy_tar
fi
#-----------
# Unpack archive
#
(cd $TMPDIR && $UNPACK $ARCHIVE_NAME) || exit_on_error "Unpacking $ARCHIVE_NAME failed"
cd ${TMPDIR}
cd "$(ls | grep $REPONAME)"
SRCDIR=$(pwd)
#-----------
# Create the tarball
#
./setup.py sdist > /dev/null 2> /dev/null || exit_on_error "setup.py sdist failed."
cp dist/"$(ls dist | grep $REPONAME | grep 'tar\.bz2')" ${OBSDIR} || exit_on_error "Failed to copy new archive."
#
# Copy the spec file if necessary
#
cp ${SRCDIR}/packaging/$SPECFILE ${OBSDIR} || exit_on_error "Failed to copy the specfile."
echo "Successfully updated the spec file."
exit 0