Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zentraler Informatikdienst
Z
Zentrale Systeme
zid-scripts
rpmbuild-setup-from-git
Commits
159afcf7
Commit
159afcf7
authored
Mar 17, 2016
by
Otheus Shelling
😀
Browse files
initial
parents
Pipeline
#942
skipped
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
0 deletions
+95
-0
README.md
README.md
+17
-0
git-login
git-login
+33
-0
setup-from-git.macro
setup-from-git.macro
+45
-0
No files found.
README.md
0 → 100644
View file @
159afcf7
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`
)
git-login
0 → 100755
View file @
159afcf7
#!/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.macro
0 → 100644
View file @
159afcf7
%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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment