Skip to content

Instantly share code, notes, and snippets.

@scarytom
Last active August 29, 2015 14:01
Show Gist options
  • Save scarytom/e58a4927e86be06b90e0 to your computer and use it in GitHub Desktop.
Save scarytom/e58a4927e86be06b90e0 to your computer and use it in GitHub Desktop.
Aptly Package Upload
#!/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