Last active
August 29, 2015 14:01
-
-
Save scarytom/e58a4927e86be06b90e0 to your computer and use it in GitHub Desktop.
Aptly Package Upload
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 -eu | |
LOCKFILE='/var/lock/.aptly-upload.exclusivelock' | |
LOCK_TIMEOUT_SECONDS='300' | |
PROMOTE=0 | |
DISTRIBUTION='all' | |
STABLE_PREFIX='stable' | |
UNSTABLE_PREFIX='unstable' | |
# process command-line args | |
while [[ ${#} > 1 ]] | |
do | |
key="${1}" | |
case "${key}" in | |
-t|--lock-timeout) | |
LOCK_TIMEOUT_SECONDS="${2}" | |
shift | |
;; | |
-d|--distribution) | |
DISTRIBUTION="${2}" | |
shift | |
;; | |
-p|--promote) | |
PROMOTE=1 | |
;; | |
*) | |
break | |
;; | |
esac | |
shift | |
done | |
process_artifact() { | |
STABLE_REPO="${DISTRIBUTION}_${STABLE_PREFIX}" | |
UNSTABLE_REPO="${DISTRIBUTION}_${UNSTABLE_PREFIX}" | |
if [ '1' == "${PROMOTE}" ]; then | |
aptly repo move "${UNSTABLE_REPO}" "${STABLE_REPO}" "${1}" | |
aptly publish update "${DISTRIBUTION}" "${STABLE_PREFIX}" | |
aptly publish update "${DISTRIBUTION}" "${UNSTABLE_PREFIX}" | |
else | |
aptly repo add -remove-files=true "${UNSTABLE_REPO}" "${1}" | |
aptly publish update "${DISTRIBUTION}" "${UNSTABLE_PREFIX}" | |
fi | |
} | |
# Obtain lock and execute | |
( | |
flock -x -w "${LOCK_TIMEOUT_SECONDS}" 200 | |
for TARGET in "${@}" | |
do | |
process_artifact "${TARGET}" | |
done | |
) 200>"${LOCKFILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment