~ubuntu-on-ec2/vmbuilder/jenkins_kvm-philroche-eoan-python3-openstackclient

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash

set -eux

BASE_DIR="$1"
VERSIONS=$(find "${BASE_DIR}" -mindepth 1 -maxdepth 1 -type d | sort -V)
LATEST_SERIAL="$(basename "$(echo "${VERSIONS}" | tail -n1)")"
echo "Latest serial is ${LATEST_SERIAL}; updating current symlink..."
rm -f "${BASE_DIR}/current"
(cd "${BASE_DIR}" && ln -s "${LATEST_SERIAL}" "current")

OLD_VERSIONS=$(echo "${VERSIONS}" | head -n-5)
if [[ ! -z ${OLD_VERSIONS} ]]; then
  echo "Cleaning up old versions:"
  echo "${OLD_VERSIONS}"
  echo "${OLD_VERSIONS}" | xargs rm -rf
fi