From 3d00d2cc6d133aee5f11c671fb9f197973007fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 20 Jan 2019 14:26:59 +0000 Subject: check_updates.sh: removes obsolete script. etc/rotate_archives.sh: moved & minor cleanup from rotate_tarballs.sh. --- check_updates.sh | 102 ------------------------------------------------- etc/rotate_archives.sh | 57 +++++++++++++++++++++++++++ rotate_tarballs.sh | 55 -------------------------- 3 files changed, 57 insertions(+), 157 deletions(-) delete mode 100755 check_updates.sh create mode 100755 etc/rotate_archives.sh delete mode 100755 rotate_tarballs.sh diff --git a/check_updates.sh b/check_updates.sh deleted file mode 100755 index 9699d360..00000000 --- a/check_updates.sh +++ /dev/null @@ -1,102 +0,0 @@ -# -# set -o errexit -o noglob are assumed. -# - -modep_cpu_get_fnames() { - if test_cmd pkg_${cu_name}_check_updates; then - pkg_${cu_name}_check_updates get_fnames; - fi; - if [ -z "${cu_fnames}" ]; then - if [ "${cu_url#*://github.com/*}" != "${cu_url}" ]; then - _cpugf_uname="${cu_url#*/github.com/}"; - _cpugf_uname="${_cpugf_uname%%/*}"; - _cpugf_pname="${cu_url#*/github.com/${_cpugf_uname}/}"; - _cpugf_pname="${_cpugf_pname%%/*}"; - cu_url_index="https://github.com/${_cpugf_uname%%/*}/${_cpugf_pname%%/*}/releases/"; - unset _cpu_uname _cpu_pname; - cu_fnames="$(wget ${DEFAULT_WGET_ARGS} -qO- ${cu_url_index} |\ - sed -n '//s/^.*\([a-zA-Z]\+-\|v\|\)\(.\+\)<\/span>.*$/\3/p')"; - cu_fname_base="${cu_name}"; - cu_fname_ext="${cu_fname#v${cu_version}.}"; - else - cu_url_index="${cu_url%/*}/"; - cu_fnames="$(wget ${DEFAULT_WGET_ARGS} -qO- "${cu_url_index}" |\ - sed -n '/[hH][rR][eE][fF]="[^"]\+"/s/^.*[hH][rR][eE][fF]="\([^"]\+\)".*$/\1/p')"; - fi; - fi; - : ${cu_fname:="${cu_url##*/}"}; - : ${cu_fname_base:="${cu_fname%%-*}"}; - : ${cu_fname_ext:="${cu_fname#${cu_fname_base}-${cu_version}.}"}; -}; - -modep_check_cpu_get_version() { - unset cu_fname_version; - if test_cmd pkg_${cu_name}_check_updates; then - pkg_${cu_name}_check_updates get_version; - fi; - if [ -z "${cu_fname_version}" ]; then - if [ "${cu_url#*://github.com/*}" != "${cu_url}" ]; then - if [ "${cu_fname#${cu_fname_base}-}" = "${cu_fname}" ]\ - && [ "${cu_fname%.${cu_fname_ext}}" = "${cu_fname}" ]; then - cu_fname_version="${cu_fname}"; - fi; - elif [ "${cu_fname#${cu_fname_base}-}" != "${cu_fname}" ]\ - && [ "${cu_fname%.${cu_fname_ext}}" != "${cu_fname}" ]; then - cu_fname_version="${cu_fname#${cu_fname_base}-}"; - cu_fname_version="${cu_fname_version%.${cu_fname_ext}}"; - fi; - fi; -}; - -mode_check_pkg_updates() { - cu_name="${1}"; cu_NAME="${2}"; - cu_version="$(get_var_unsafe PKG_${cu_NAME}_VERSION)"; - cu_url="$(get_var_unsafe PKG_${cu_NAME}_URL)"; - cu_url_type="$(get_var_unsafe PKG_${cu_NAME}_URL_TYPE)"; - . vars/check_updates.vars; - if lmatch "${CHECK_UPDATES_SKIP}" " " "${cu_name}"; then - log_msg vnfo "Skipping \`${cu_name}' (set in \${CHECK_UPDATES_SKIP}.)"; - return 0; - elif [ "${cu_url_type}" = "git" ]; then - log_msg vnfo "Skipping \`${cu_name}' (URL_TYPE is Git.)"; - return 0; - elif [ -z "${cu_version}" -o -z "${cu_url}" ]; then - log_msg fail "Zero-length \${cu_version} and/or \${cu_url} for \`${cu_name}' (ignored.)"; - return 0; - else - log_msg vnfo "Checking ${cu_name} v${cu_version} for updates."; - modep_cpu_get_fnames; _cpu_versions=""; - fi; - for cu_fname in ${cu_fnames}; do - cu_fname="${cu_fname##*/}"; modep_check_cpu_get_version; - if [ -z "${cu_fname_version}" ]; then - continue; - elif ! echo "${cu_fname_version}" | grep -Eq '^[-_.0-9a-zA-Z]+$' \ - || echo "${cu_fname_version}" | grep -Eq '^[_.a-zA-Z]+'; then - log_msg varn "Skipping \`${cu_fname_version}' (invalid version.)"; - else - _cpu_versions="${_cpu_versions:+${_cpu_versions} }${cu_fname_version}"; - fi; - done; - if [ -z "${_cpu_versions}" ]; then - log_msg warn "No versions available for \`${cu_name}' (Filename URL: ${cu_url}, index URL: ${cu_url_index})."; - else - _cpu_versions="$(echo "${_cpu_versions}" |\ - sed 's/ /\n/g' | sort -rV | uniq |\ - head -n${CHECK_UPDATES_SHOW_NEW:-6} |\ - paste -d" " -s)"; - if test_cmd pkg_${cu_name}_check_updates; then - pkg_${cu_name}_check_updates version_fixup; - fi; - if [ "${_cpu_versions%% *}" != "${cu_version}" ]; then - log_msg info "New release(s) available for ${cu_name} v${cu_version}: ${_cpu_versions}."; - else - log_msg vnfo "${cu_name} v${cu_version} is up to date."; - fi; - fi; - unset cu_fname cu_fname_base cu_fname_ext cu_fnames cu_fname_version \ - cu_name cu_url cu_url_fname cu_url_fname_base cu_url_fname_ext \ - cu_url_index cu_url_type cu_version _cpu_versions; -}; - -# vim:filetype=sh diff --git a/etc/rotate_archives.sh b/etc/rotate_archives.sh new file mode 100755 index 00000000..546fdf0b --- /dev/null +++ b/etc/rotate_archives.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +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.* \ + ${_build_dname}/*.zip \ + ${_build_dname}/*.zip.*); do + if [ -e "${_dist_fname}" ]; then + _dist_date="${_dist_fname#*@${_hostname}-}"; + _dist_date="${_dist_date%.tar.*}"; + _dist_date="${_dist_date%.zip}"; + _dist_date="${_dist_date%.zip.*}"; + _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; +}; + +set -o errexit -o noglob; +rotate_builds "${1}" "${2:-3}"; + +# vim:noexpandtab sw=8 ts=8 diff --git a/rotate_tarballs.sh b/rotate_tarballs.sh deleted file mode 100755 index f4efaeeb..00000000 --- a/rotate_tarballs.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/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 -- cgit v1.2.3