Skip to content

Instantly share code, notes, and snippets.

@drfill
Forked from bdrewery/bulk.sh
Last active July 6, 2018 18:06
Show Gist options
  • Save drfill/1c87a99c5d506be094ad44e3794f7562 to your computer and use it in GitHub Desktop.
Save drfill/1c87a99c5d506be094ad44e3794f7562 to your computer and use it in GitHub Desktop.
Hook to upload packages to S3 after bulk is successful.
#! /bin/sh
#
# Copyright (c) 2013-2014 Bryan Drewery <bdrewery@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
err() {
local status="$1"
shift
echo "$@" >&2
exit ${status}
}
[ -n "${SETNAME}" ] || err 1 "SETNAME not set"
[ -n "${MASTERNAME}" ] || err 1 "MASTERNAME not set"
[ -f "${POUDRIERED}/hooks/bulk.conf" ] &&
. "${POUDRIERED}/hooks/bulk.conf"
[ -f "${POUDRIERED}/${SETNAME}-bulk.conf" ] &&
. "${POUDRIERED}/${SETNAME}-bulk.conf"
bulk_start() {
local n_tobuild=$1
}
sync_packages_to_nfs() {
[ "${SHOULD_SYNC_TO_NFS:-0}" -eq 1 ] || return 0
[ -n "${PACKAGES}" ] || err 1 "PACKAGES not set"
[ -n "${NFS_PATH}" ] || err 1 "NFS_PATH not set"
echo "%%%> Syncing ${PACKAGES}/ -> /mnt/all-packages/${MASTERNAME}/"
rsync -q -avH --del -O ${PACKAGES}/ ${NFS_PATH}/
}
sync_packages_to_s3() {
local arch
[ "${SHOULD_SYNC_TO_S3:-0}" -eq 1 ] || return 0
[ -n "${S3_PATH}" ] || err 1 "S3_PATH not set"
[ -n "${S3_ARCH_GLOB}" ] || err 1 "S3_ARCH_GLOB not set"
arch=$(pkg info -f -F ${PACKAGES}/Latest/pkg.txz |
awk '$1 == "Architecture" {print $3}')
case ${arch} in
${S3_ARCH_GLOB})
;;
*)
return 0
;;
esac
echo "%%%> Syncing ${arch} [${PACKAGES}] to S3"
# Fix + to be a space to workaround S3 bug
find ${PACKAGES}/All -name '*+*' | while read file; do
fixed_path="$(echo "${file}"|tr '+' ' ')"
[ -f "${fixed_path}" ] ||
ln -v "${file}" "${fixed_path}"
done
s3cmd sync -P --rr --delete-removed ${PACKAGES}/ \
s3://${S3_PATH}/${arch}/
# Delete S3 hack of '+'->' '
find ${PACKAGES}/All/ -name '* *' -delete
}
bulk_stop() {
local n_built=$1
local n_failed=$2
local n_ignored=$3
local n_skipped=$4
sync_packages_to_nfs
[ $((${n_failed} + ${n_skipped})) -eq 0 ] && sync_packages_to_s3
return 0
}
status="$1"
shift
case ${status} in
start)
bulk_start "$@"
;;
"done")
bulk_stop "$@"
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment