diff options
author | Lucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de> | 2018-02-27 21:40:07 +0000 |
---|---|---|
committer | Lucio Andrés Illanes Albornoz (arab, vxp) <lucio@lucioillanes.de> | 2018-02-27 21:40:07 +0000 |
commit | ed54b7b90163424c1e0b18f32edbe3f4fa540158 (patch) | |
tree | ace21048a3cc1f765a162749cd5ae7c9f6a9c53f | |
parent | b2ecd92d466ac2dca394c8edd019a45c8651bb12 (diff) | |
download | midipix_build-ed54b7b90163424c1e0b18f32edbe3f4fa540158.tar.bz2 midipix_build-ed54b7b90163424c1e0b18f32edbe3f4fa540158.tar.xz |
rotate_tarballs.sh: added to repository for convenience.
-rwxr-xr-x | rotate_tarballs.sh | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/rotate_tarballs.sh b/rotate_tarballs.sh new file mode 100755 index 00000000..f0b81818 --- /dev/null +++ b/rotate_tarballs.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +set -o errexit -o noglob; + +glob() { set +o noglob; echo ${@}; set -o noglob; }; +map() { local _ifs="${IFS}" _sep="${1}"; shift; IFS="${_sep}"; echo "${*}"; IFS="${_ifs}"; }; +rc() { echo "${@}"; "${@}"; }; + +rotate_build() { + local _build_dname="${1}" _hostname="${2}" _limit="${3}"; + local _dist_dates=""; + for _dist_fname in $(glob \ + ${_build_dname}/*.tar.xz \ + ${_build_dname}/*.tar.xz.asc); do + if [ -e "${_dist_fname}" ]; then + _dist_date="${_dist_fname#*@${_hostname}-}"; + _dist_date="${_dist_date%.tar.xz*}"; + _dist_date="${_dist_date%-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]}"; + _dist_dates="${_dist_dates:+${_dist_dates} }${_dist_date}"; + fi; + done; + if [ -n "${_dist_dates}" ]; then + rotate_build_dates "${_build_dname}" "${_dist_dates}" "${_limit}"; + fi; +}; + +rotate_build_dates() { + local _build_dname="${1}" _dist_dates="${2}" _limit="${3}"; + local _dist_dates_count _dist_dates_count_limit="" _dist_fname="" _nl=" +"; _dist_dates="$(map "${_nl}" ${_dist_dates} | sort | uniq)"; + _dist_dates_count="$(echo "${_dist_dates}" | wc -l)"; + if [ "${_dist_dates_count}" -gt "${_limit}" ]; then + _dist_dates_count_limit=$((${_dist_dates_count}-${_limit})); + _dist_dates="$(echo "${_dist_dates}" |\ + sed -n "1,${_dist_dates_count_limit}p")"; + for _dist_date in ${_dist_dates}; do + for _dist_fname in $(glob \ + ${_build_dname}/*-${_dist_date}-*.tar.xz*); do + rc rm -f "${_dist_fname}"; + done; + done; + fi; +}; + +rotate_builds() { + local _build_dnames="${1}" _limit="${2}"; + local _hostname="$(hostname)"; + for _build_dname in ${_build_dnames}; do + rotate_build "${_build_dname}" "${_hostname}" "${_limit}"; + done; +}; + +rotate_builds "${1}" "${2:-3}"; + +# vim:filetype=sh noexpandtab sw=8 ts=8 |