Commit 159afcf7 authored by Otheus Shelling's avatar Otheus Shelling 😀
Browse files

initial

parents
Pipeline #942 skipped
This project is to help RPM-packagers build .spec files that can pull sources
directly from git. The usage is something like this (inside .spec file):
URL: https://github.org/api/v3/user/projectname/repository/archive?ref=v%{version}
%prep
%if 0%{?setup_from_git:1}
%setup_from_git -U %{url} -S %{S:0} -n %{name}-%{version}
%else
# setup compatible with github-generated tarball
%setup -c -T
tar axf %{S:0} --strip-components 1
%endif
The included macro must be appended to either `~/.rpmmacros` or one of the site macro files
(see `man rpmbuild`)
#!/bin/sh
# Log into git-hub repo specified by url
# otheus@gmail.com
# 2016-03-17
urlbase=$(echo "${1:-https://git.uibk.ac.at/api/v3/}" | sed 's%\(/api/v.\)/.*%\1/%')
echo >&2 "Using git repo at $urlbase"
set -o pipefail
let try_again=3
let success=0
if [[ -n "$PRIVATE_TOKEN" ]]; then
if curl -o- -f -H "PRIVATE-TOKEN: $PRIVATE_TOKEN" "$urlbase/user" &>/dev/null ; then
echo "PRIVATE_TOKEN='$PRIVATE_TOKEN';export PRIVATE_TOKEN"
exit 0
else
echo >&2 "Current PRIVATE_TOKEN invalid; requesting new one."
fi
fi
while [[ $success = 0 && $try_again -gt 0 ]]; do
read -p "Repository Username: " repo_username
read -s -p "Password: " repo_password
echo
let try_again=try_again-1
if curl -o- -d "login=$repo_username" -d "password=$repo_password" "$urlbase/session" 2>/dev/null |
perl -ln \
-e 'BEGIN{$key="PRIVATE_TOKEN"}' \
-e '/"$key":"(\w+)"/io and $tok||=$1;' \
-e 'END{ exit 1 unless $tok; print "$key=\"$tok\";export $key"; }'
then
let success=1
fi
done
%setup_from_git(U:S:n:t:H:O:) \
# Version 1.0 \
# by otheus@gmail.com \
# Pull source.tar.gz from given repository \
# Usage : \
if [ -z '%{-U*}' -o -z '%{-S*}' -o -z '%{-n*}' ]; then \
set +x \
echo >&2 "The git_setup macro requires -U <URL> -S <source-tarfile> -n <source-dir>" \
echo >&2 "The downloaded URL will be saved as <source-tarfile> and extracted into <source-dir>" \
exit 1 \
fi \
# Also -O to to specify options to curl ( headers, proxy, etc ) \
# Better yet, use -O to specify "-K tmpfile" and fill tmpfile with config options \
# and -t to override environment PRIVATE_TOKEN for PRIVATE-TOKEN header \
# see https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/session.md \
\
cd %{_sourcedir} \
if [ ! -f '%{-S*}' ]; then \
let try_again=1 \
while [[ $try_again -gt 0 ]]; do \
let try_again=try_again-1 ||: \
# Pass auth token via pipe for security, using curl's -K option \
auth_token="%{-t:%{-t*}}%{!-t:${PRIVATE_TOKEN}}" \
echo "header = \\"PRIVATE-TOKEN: ${auth_token}\\"" | \
%{_urlhelper} '%{-S*}' -v -K - %{-O*} '%{-U*}' \
if [ $? != 0 ]; then \
set +x \
echo >&2 'Failed to download tarfile from repository at %{-U*}' \
[[ -z $auth_token ]] && \
echo >&2 'Perhaps you must specify -t or setenv PRIVATE_TOKEN to authenticate' \
exit 1 \
fi \
done \
fi \
\
# the setup macro is needed to "Remember" the directory to cd into in other build phases \
%setup -c -T -n %{-n*} \
if ! %{__tar} xfvva "%{-S*}" --strip-components 1 \
then \
set +x \
echo >&2 Could not extract tar file %{-S*} \
exit 1 \
fi \
# end macro
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment