Created
July 14, 2014 06:28
-
-
Save loomsen/740fab44d7eb0d1e1b50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
:<<'_literal_' | |
This script checks for changes on github and triggers an rpm rebuild | |
_literal_ | |
readonly progname=${0##*/} | |
readonly version=0.1 | |
:<<< '+++++++ config options ++++++++++++' | |
readonly project="omniscale" | |
readonly resign="$HOME"/bin/rpm-resign-auto-"$project".expect | |
readonly source_dir="$HOME"/src/"$project"/imposm3 | |
readonly build_dir=/srv/"$project"/build | |
readonly hist_file="$build_dir"/.imposm3_last_build.txt | |
readonly last_commit_built=$(<"$hist_file") | |
readonly spec_file="$HOME"/rpmbuild/SPECS/"$project"/imposm3.spec | |
readonly rpm_dir=/srv/"$project"/RPMS/x86_64 | |
readonly srpm_dir=/srv/"$project"/SRPMS | |
:<<< '++++++++ end config ++++++++++++++++' | |
# functions | |
commit_id() { | |
pushd "$source_dir" >/dev/null | |
git rev-parse HEAD | |
popd >/dev/null | |
} | |
commit_id_short() { | |
pushd "$source_dir" >/dev/null | |
git rev-parse HEAD | cut -c -7 | |
popd >/dev/null | |
} | |
build() { | |
local log=/srv/"$project"/logs/buildlog.txt | |
# build srpm for mock | |
rpmbuild -bs "$spec_file" &> "$log" || return 1 | |
# build package and move result to repo | |
mock -r "$project" --rebuild $(awk '/src.rpm$/{print $2}' "$log") --resultdir="$build_dir" && ( | |
mv -v -- "$build_dir"/*.src.rpm "$srpm_dir" && \ | |
mv -v -- "$build_dir"/*.rpm "$rpm_dir" | |
#+++ rpm signing is manual at the moment, we need an expect script +++ # | |
"$resign" "$rpm_dir"/*.rpm "$srpm_dir"/*.rpm | |
repo_update "$project" | |
) || { printf 'mock build failed\n'; return 1; } | |
} | |
git_pull() { | |
pushd "$source_dir" >/dev/null | |
git pull origin master || return 1 | |
popd >/dev/null | |
} | |
repo_update() { | |
local dirs=( "$rpm_dir" "$srpm_dir" ) | |
for dir in "${dirs[@]}"; do | |
createrepo "$dir" | |
done | |
} | |
bumpspec() { | |
user="${1:-norbert}" | |
comment="${2:-"automatic build"}" | |
shift 2 | |
if [[ "$user" == norbert ]]; then | |
user="Norbert Varzariu <[email protected]>" | |
elif [[ "$user" == hendrik ]]; then | |
user="Hendrik Horeis <[email protected]>" | |
fi | |
sed -ri.bak.autobuild -- "/global commit /{s/^(.+commit) *([^ ]+)$/\1 $(commit_id)/}" "$spec_file" | |
rpmdev-bumpspec -u "$user" -c "$comment" "$spec_file" | |
} | |
main() { | |
bumpspec || return 1 | |
build || return 1 | |
repo_update || return 1 | |
} | |
upload() { | |
#FIXME to be written | |
echo uploading package | |
# rsync repo to imposm | |
} | |
# sanity checks | |
if ! which git expect rsync mock; then | |
printf -- "you need git, rsync, mock and expect, please install\n" | |
exit 1 | |
fi | |
if [[ ! -d "$rpm_dir" ]]; then | |
printf -- 'designated output directory not found, please create a repo where I can write to\n' | |
exit 1 | |
fi | |
if [[ ! -x "$resign" ]]; then | |
printf -- '%s is not executable, bailing out.\n' "$resign" | |
exit 1 | |
fi | |
# may the source be with us | |
git_pull || { printf -- 'whoopsie, something went wrong, I cannot get an update from github\n' && exit 1; } | |
# check for first run | |
if [[ ! -f "$hist_file" ]]; then | |
printf -- "this seems to be your first run, I will build the most current revision" | |
commit_id > "$hist_file" | |
main || exit 1 | |
elif grep -q -- "$(commit_id)" "$hist_file"; then | |
#printf "already built this one\n" | |
exit 0 | |
else | |
if (( $(find "$rpm_dir" -type f -iname "*$(commit_id_short)*" -printf '.' | wc -c) == 0 )); then | |
printf -- "spec changed but package was not found. building it now\n" | |
# FIXME: build package | |
main || exit 1 | |
# update history file to keep track of builds | |
mv -f -- "${hist_file}"{,.pre} | |
commit_id > "$hist_file" | |
else | |
printf -- 'there is already a package for this commit, nothing to do\n' | |
fi | |
fi | |
exit $? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
### rpm-sign.exp -- Sign RPMs by sending the passphrase. | |
spawn rpm --resign {*}$argv | |
expect -exact "Enter pass phrase: " | |
send -- "\r" | |
expect eof | |
## end of rpm-sign.exp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment