#438 Add post-compose rsync script
Closed 3 years ago by humaton. Opened 6 years ago by kellin.
kellin/pungi-fedora add-rsync-script  into  master

@@ -0,0 +1,216 @@ 

+ #!/bin/sh

+ 

+ ################################################################################

+ # sync-release-candidate.sh

+ #

+ # synchronizes the release candidate compose to the staging area if it has any

+ # completion status other than DOOMED

+ #

+ # This script is designed to run on a compose host.

+ ################################################################################

+ 

+ #------------------------------------------------------------------------------

+ # Helper Functions

+ #------------------------------------------------------------------------------

+ show_help()

+ {

+     exit_code=0

+     if [ "$1" = "ERR" ]; then

+         exit_code=1

+     fi

+     echo "$0 release-version release-type compose-path"

+     echo "    release-version:    The Fedora release number"

+     echo "    release-type:       Alpha, Beta, RC"

+     echo "    compose-path:       full path to compose to sync"

+     echo ""

+     echo "EXAMPLE:"

+     echo "    ${0} 26 Alpha /mnt/koji/compose/26/Fedora-26-20160329.1"

+     exit "${exit_code}"

+ }

+ 

+ display_error()

+ {

+     msg="$1"

+     echo "ERROR: ${msg}"

+     echo ""

+     show_help "ERR"

+ }

+ 

+ display_info()

+ {

+     msg="$1"

+     echo "INFO: ${msg}"

+ }

+ 

+ 

+ #------------------------------------------------------------------------------

+ # static defines

+ #------------------------------------------------------------------------------

+ VARIANTS="Everything \

+     Cloud \

+     CloudImages \

+     Docker \

+     Labs \

+     Server \

+     Spins \

+     Workstation \

+     Workstation-Ostree \

+     metadata"

+ 

+ COMPOSES_DIRECTORY="/mnt/koji/compose/"

+ RC_DIRECTORY="/pub/alt/stage/"

+ DEVEL_DIRECTORY="/pub/fedora/linux/development/"

+ 

+ [ -d "${COMPOSES_DIRECTORY}" ] || display_error "${COMPOSES_DIRECTORY} missing"

+ [ -d "${RC_DIRECTORY}" ] || display_error "${RC_DIRECTORY} missing"

+ [ -d "${DEVEL_DIRECTORY}" ] || display_error "${DEVEL_DIRECTORY} missing"

+ 

+ 

+ #------------------------------------------------------------------------------

+ # validate correct effective user

+ #------------------------------------------------------------------------------

+ effective_user=$(id -un)

+ 

+ if [ "${effective_user}" != "ftpsync" ]; then

+     display_error "Script must run as ftpsync user"

+ fi

+ 

+ 

+ #------------------------------------------------------------------------------

+ # assign input

+ #------------------------------------------------------------------------------

+ release_version="$1"

+ release_type="$2"

+ compose_path="$3"

+ 

+ [ -z "${release_version}" ] && display_error "Release version missing"

+ [ -z "${release_type}" ] && display_error "Release type missing"

+ [ -z "${compose_path}" ] && display_error "Compose path missing"

+ 

+ 

+ #------------------------------------------------------------------------------

+ # sanitize input

+ #------------------------------------------------------------------------------

+ sanitized_release_version=$(echo "${release_version}" | sed 's/[0-9]//g')

+ if [ -n "${sanitized_release_version}" ]; then

+     display_error "Fedora release may only be a number"

+ fi

+ 

+ case "${release_type}" in 

+     [Aa][Ll][Pp][Hh][Aa] )

+         release_type="Alpha"

+         ;;

+     [Bb][Ee][Tt][Aa] )

+         release_type="Beta"

+         ;;

+     [Rr][Cc] )

+         release_type="RC"

+         ;;

+     *)

+         display_error "Candidate type must follow convention (Alpha|Beta|RC)"

+         ;;

+ esac

+ 

+ 

+ # canonicalize the path name

+ compose_path=$(readlink -sf "${compose_path}")

+ 

+ if [ ! -d "${compose_path}" ]; then

+     display_error "Path not found - ${compose_path}"

+ fi

+ 

+ 

+ #------------------------------------------------------------------------------

+ # make sure the compose is not doomed

+ #------------------------------------------------------------------------------

+ compose_status_file="${compose_path}/STATUS"

+ 

+ [ -f "${compose_status_file}" ] || display_error "Compose STATUS is missing"

+ 

+ if grep -q "DOOMED" "${compose_status_file}"; then

+     display_error "Compose was DOOMED - sync is invalid"

+ fi

+ 

+ 

+ #------------------------------------------------------------------------------

+ # calculate the candidate number for the release-label

+ #------------------------------------------------------------------------------

+ current_candidate_number=0

+ previous_candidate_number=0

+ composes=$(find "${COMPOSES_DIRECTORY}${release_version}/"* -maxdepth 0 -type d)

+ unset current_compose

+ unset previous_compose

+ for compose in ${composes}; do

+     if [ -n "${current_compose}" ]; then

+         previous_compose="${current_compose}"

+         if ! grep -q "DOOMED" "${previous_compose}/STATUS"; then

+             previous_candidate_number="${current_candidate_number}"

+         fi

+     fi

+     current_compose=$(readlink -sf "${compose}")

+     current_candidate_number=$((current_candidate_number+1))

+ 

+     if [ "${current_compose}" = "${compose_path}" ]; then

+         break

+     fi

+ done

+ 

+ #------------------------------------------------------------------------------

+ # determine current and previous release labels

+ #------------------------------------------------------------------------------

+ partial_label="${release_version}_${release_type}-1."

+ 

+ current_release_label="${partial_label}${current_candidate_number}"

+ current_stage_path="${RC_DIRECTORY}${current_release_label}"

+ 

+ if [ "${previous_candidate_number}" -eq 0 ]; then

+     # the previous link for the first release candidate is the devel path

+     previous_stage_path="${DEVEL_DIRECTORY}${release_version}"

+ else

+     previous_release_label="${partial_label}${previous_candidate_number}"

+     previous_stage_path="${RC_DIRECTORY}${previous_release_label}"

+ fi

+ 

+ if [ ! -d "${previous_stage_path}" ]; then

+     display_error "Expected to hardlink from ${previous_stage_path} but it doesn't exist!"

+ fi

+ 

+ 

+ #------------------------------------------------------------------------------

+ # set up and execute sync

+ #------------------------------------------------------------------------------

+ rsync="/usr/bin/rsync"

+ flags="-avhH"

+ 

+ # set up the path to hardlink against if applicable

+ hardlink_source_path="${previous_stage_path}/Everything"

+ 

+ if [ -d "${hardlink_source_path}" ]; then

+     link_dest_argument="--link-dest=${hardlink_source_path}"

+ else

+     display_error "Directory missing: ${hardlink_source_path}"

+ fi

+ 

+ # create the destination staging path if it does not already exist

+ if [ -d "${current_stage_path}" ]; then

+     display_info "${current_stage_path} already exists"

+ else

+     if ! mkdir -p "${current_stage_path}"; then

+         display_error "Could not make ${current_stage_path}"

+     fi

+ fi

+ 

+ # do the actual rsync now

+ for variant in ${VARIANTS}; do

+     src_path="${compose_path}/compose/${variant}"

+     dest_path="${current_stage_path}/${variant}"

+ 

+     display_info "CLI INVOCATION: ${rsync} ${flags} ${src_path} ${dest_path} ${link_dest_argument}"

+     if ${rsync} ${flags} "${src_path}" "${dest_path}" "${link_dest_argument}"; then

+         display_info "${variant} sync is complete"

+     else

+         display_error "Sync failure in ${variant} variant"

+     fi

+ done

+ 

+ exit 0

  • convert one-liner shell script from post compose rsync into a full
    into a full script
  • validate user input to the script
  • check for previous syncs and do not move forward if previous syncs
    were not properly completed
  • does not sync DOOMED composes but does treat them as a release
    candidate

Signed-off-by: Robert Marshall rmarshall@redhat.com

rebased onto ec51d09

6 years ago

@mohanboddu do we still need this? Or are we using something else now to sync rc's?

Pull-Request has been closed by humaton

3 years ago
Metadata