#199 WIP - automate sync of files post compose
Closed 7 years ago by kellin. Opened 7 years ago by kellin.
kellin/pungi-fedora automate-post-compose-sync  into  master

@@ -0,0 +1,140 @@ 

+ #!/bin/sh

+ 

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

+ # sync-release-candidate.sh

+ #

+ # synchronizes the compose to the staging area

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

+ 

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

+ # Helper Functions

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

+ show_help()

+ {

+         exit_code=0

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

In POSIX sh, == in place of = is undefined. SC2039

+                 exit_code=1

+         fi

+         echo "$0 fedora-release fedora-compose [compose-path]"

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

+         echo "    fedora-compose:    Alpha, Beta, or GA"

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

+         exit "${exit_code}"

+ }

+ 

+ display_error()

+ {

+         msg="$1"

+         echo "ERROR: ${msg}"

+         echo ""

+         show_help "ERR"

+ }

+ 

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

+ # Main Body

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

+ 

+ # define static values

+ VARIANTS="Everything \

+         Cloud \

+         CloudImages \

+         Docker \

+         Labs \

+         Server \

+         Spins \

+         Workstation \

+         metadata"

+ 

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

+ STAGE_DIRECTORY="/pub/alt/stage/"

+ 

+ # validate user and user input

+ effective_user=$(id -un)

+ 

+ [ "${effective_user}" != "ftpsync" ] && \

+         display_error "Script must run as ftpsync user"

+ 

+ # verify fedora-release arg

+ fedora_release="$1"

+ [ -z "${fedora_release}" ] && \

+         display_error "Missing Fedora release version"

+ 

+ release_directory="${COMPOSES_DIRECTORY}${fedora_release}/"

+ [ ! -d "${release_directory}" ] && \

+         display_error "${release_directory} path does not exist!"

+ 

+ 

+ # verify fedora-compose arg

+ raw_fedora_compose="$2"

+ [ -z "${raw_fedora_compose}" ] && \

+         display_error "Missing Fedora compose argument"

+ 

+ fedora_compose=

+ case "${raw_fedora_compose}" in

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

+                 fedora_compose="Alpha"

+                 ;;

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

+                 fedora_compose="Beta"

+                 ;;

+         [Gg][Aa])

+                 fedora_compose="GA"

we call final compose as RC, not GA

+                 ;;

+         *)

+                 display_error "Fedora compose choice was invalid"

+                 ;;

+ esac

+ 

+ latest_compose="$(readlink -sf ${release_directory}latest-Fedora-${fedora_release})"

+ 

+ [ ! -d "${latest_compose}" ] && \

+         display_error "${latest_compose} latest compose path does not exist!"

+ 

+ compose_path="$3"

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

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

+                 display_error "Specified compose path, but path not found ${compose_path}"

+         fi

+ else

+         compose_path="${latest_compose}"

+ fi

+ 

+ # canonicalize the path for safety

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

+ 

+ # last check, are we trying to sync something DOOMED?

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

+         display_error "Compose is DOOMED - it should not be synced"

+ fi

+ 

+ composes=$(find ${release_directory}* -maxdepth 0 -type d)

+ 

+ fedora_candidate=0

+ 

+ # build the link-dest arguments

+ link_dests="--link-dest=/pub/fedora/linux/development/${fedora_release}/Everything/"

+ destination_path=

+ for c in ${composes}; do

+         # canonicalize the path for safety

+         discovered_compose="$(readlink -sf ${c})"

+ 

+         # catch autodooms that didn't become RCs because of bad process

+         if [ $(find "${discovered_compose}/compose/"* -maxdepth 1|wc -l) -gt 1 ]; then

+                 fedora_candidate=$((fedora_candidate+1))

+                 destination_path="${STAGE_DIRECTORY}${fedora_release}_${fedora_compose}-1.${fedora_candidate}/"

+ 

+                 # doomed composes do not get synced

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

+                         link_dests="${link_dests} --link-dest=${destination_path}Everything/"

+                 fi

+ 

+                 # stop link dests on the off chance we are stopping before the latest compose

+                 [ "${discovered_compose}" == "${compose_path}" ] && break

+         fi

+ done

+ 

+ # do the work

+ for variant in ${VARIANTS}; do

+         rsync -avhH "${compose_path}/compose/${variant}/" "${destination_path}${variant}/" ${link_dests}

+         [ "$?" -ne 0 ] && echo "FAILURE on ${variant}"

Why not check exit code directly with e.g. if mycmd;, not indirectly with $?? SC2181

+ done

Request for Comments:

first draft of script to sync files post compose

not signed to prevent merging before passing first RFC

In POSIX sh, == in place of = is undefined. SC2039

Why not check exit code directly with e.g. if mycmd;, not indirectly with $?? SC2181

we call final compose as RC, not GA

Closing this PR - will be submitting a new one in the morning with more updates.

Pull-Request has been closed by kellin

7 years ago
Metadata