scripts/copy_buildsync: shellcheck pass

[mattst88]: Small fixes
Signed-off-by: Matt Turner <mattst88@gentoo.org>
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
This commit is contained in:
Robin H. Johnson 2018-11-20 23:06:48 -08:00 committed by Matt Turner
parent 9fa4c8f32c
commit a4b2ec7de2

View file

@ -56,7 +56,7 @@ Options:
-v, --verbose Run in verbose mode -v, --verbose Run in verbose mode
-d, --debug Run in debug mode -d, --debug Run in debug mode
EOF EOF
exit ${1:-1} exit "${1:-1}"
} }
# Copy artifacts for an arch to the outgoing directory. # Copy artifacts for an arch to the outgoing directory.
@ -83,7 +83,7 @@ copy_arch_to_outgoing() {
for i in "${timestamps[@]}" ; do for i in "${timestamps[@]}" ; do
#echo "Doing $i" #echo "Doing $i"
t="${outdir}/${i}" t="${outdir}/${i}"
mkdir -p ${t} 2>/dev/null mkdir -p "${t}" 2>/dev/null
rsync \ rsync \
"${RSYNC_OPTS[@]}" \ "${RSYNC_OPTS[@]}" \
--temp-dir="${tmpdir}" \ --temp-dir="${tmpdir}" \
@ -92,8 +92,8 @@ copy_arch_to_outgoing() {
--filter "S *${i}*" \ --filter "S *${i}*" \
--filter 'S **/' \ --filter 'S **/' \
--filter 'H *' \ --filter 'H *' \
${indir}/ \ "${indir}"/ \
${t} "${t}"
rc=$? rc=$?
if [ $rc -eq 0 ]; then if [ $rc -eq 0 ]; then
find "${indir}" \ find "${indir}" \
@ -102,7 +102,7 @@ copy_arch_to_outgoing() {
\( -not -path '*/\.*' \) \ \( -not -path '*/\.*' \) \
-print0 \ -print0 \
| xargs -0 --no-run-if-empty \ | xargs -0 --no-run-if-empty \
"$DEBUGP" rm "$VERBOSEP" -f $DEBUGP rm $VERBOSEP -f
else else
echo "Not deleting ${indir}/*${i}*, rsync failed!" 1>&2 echo "Not deleting ${indir}/*${i}*, rsync failed!" 1>&2
fail=1 fail=1
@ -124,7 +124,7 @@ process_arch() {
outdir="${OUTGOING_BASE}/${ARCH}" outdir="${OUTGOING_BASE}/${ARCH}"
tmpdir="${TMPDIR_BASE}/${ARCH}" tmpdir="${TMPDIR_BASE}/${ARCH}"
mkdir -p ${tmpdir} 2>/dev/null mkdir -p "${tmpdir}" 2>/dev/null
# Sync incoming->outgoing first. # Sync incoming->outgoing first.
copy_arch_to_outgoing "${ARCH}" "${indir}" "${outdir}" "${tmpdir}" copy_arch_to_outgoing "${ARCH}" "${indir}" "${outdir}" "${tmpdir}"
@ -182,23 +182,31 @@ process_arch() {
# New variant preserve code # New variant preserve code
find_variants=( '(' -iname '*.iso' -o -name 'netboot-*' -o "${EXTENSIONS[@]}" ')' ) find_variants=( '(' -iname '*.iso' -o -name 'netboot-*' -o "${EXTENSIONS[@]}" ')' )
variants=$(find 20* "${find_variants[@]}" -printf '%f\n' 2>/dev/null | sed -e 's,-20[012][0-9]\{5\}.*,,g' -r | sort -u) variants=$(find 20* "${find_variants[@]}" -printf '%f\n' 2>/dev/null | sed -e 's,-20[012][0-9]\{5\}.*,,g' -r | sort -u)
echo -n '' >"${tmpdir}"/.keep.${ARCH}.txt keepfile="${tmpdir}/.keep.${ARCH}.txt"
keepfile_tmp=$(mktemp -p "${tmpdir}" -t ".keep.${ARCH}.txt.XXXXXX")
echo -n '' >"${keepfile_tmp}"
chmod 644 "${keepfile_tmp}"
for v in $variants ; do for v in $variants ; do
# FIXME: trace the $a variable in this!
variant_path=$(find 20* -iname "${v}-20*" "${find_variants[@]}" -print 2>/dev/null | sed -e "s,.*/$a/autobuilds/,,g" | sort -k1,1 -t/ | tail -n1 ) variant_path=$(find 20* -iname "${v}-20*" "${find_variants[@]}" -print 2>/dev/null | sed -e "s,.*/$a/autobuilds/,,g" | sort -k1,1 -t/ | tail -n1 )
if [ -z "${variant_path}" -o ! -e "${variant_path}" ]; then if [ -z "${variant_path}" ] || [ ! -e "${variant_path}" ]; then
echo "$ARCH: Variant ${v} is missing" 1>&2 echo "$ARCH: Variant ${v} is missing" 1>&2
continue continue
fi fi
size=$(stat --format=%s ${variant_path}) size=$(stat --format='%s' "${variant_path}")
f="latest-${v}.txt" f="latest-${v}.txt"
echo -e "${header}" >"${f}" f_tmp=$(mktemp -p . -t ".${f}.XXXXXX")
echo -e "${variant_path} ${size}" >>${f} chmod 644 "${f_tmp}"
[[ ${variant_path} =~ tar.*$ ]] && echo -e "${variant_path} ${size}" >>${OUT_STAGE3} echo -e "${header}" >"${f_tmp}"
[[ ${variant_path} =~ iso$ ]] && echo -e "${variant_path} ${size}" >>${OUT_ISO} echo -e "${variant_path} ${size}" >>"${f_tmp}"
[[ ${variant_path} =~ tar.*$ ]] && echo -e "${variant_path} ${size}" >>"${OUT_STAGE3}" # FIXME: tempfile
[[ ${variant_path} =~ iso$ ]] && echo -e "${variant_path} ${size}" >>"${OUT_ISO}" # FIXME: tempfile
rm -f "current-$v" rm -f "current-$v"
ln -sf "${variant_path%/*}" "current-$v" ln -sf "${variant_path%/*}" "current-$v"
echo "${variant_path}" | sed -e 's,/.*,,g' -e 's,^,/,g' -e 's,$,$,g' >>"${tmpdir}"/.keep.${ARCH}.txt echo "${variant_path}" | sed -e 's,/.*,,g' -e 's,^,/,g' -e 's,$,$,g' >>"${keepfile_tmp}"
mv -f "${f_tmp}" "${f}"
done done
mv -f "${keepfile_tmp}" "${keepfile}"
# ================================================================ # ================================================================
# Cleanup # Cleanup
@ -206,17 +214,17 @@ process_arch() {
# Clean up all but latest 4 from mirror dir # Clean up all but latest 4 from mirror dir
cd "${outdir}" cd "${outdir}"
for i in $(find -regextype posix-basic -mindepth 1 -maxdepth 1 -type d -regex '.*20[012][0-9]\{5\}.*' \ for i in $(find . -regextype posix-basic -mindepth 1 -maxdepth 1 -type d -regex '.*20[012][0-9]\{5\}.*' \
| sed -e 's:^.*-\(20[^.]\+\).*$:\1:' \ | sed -e 's:^.*-\(20[^.]\+\).*$:\1:' \
| sort -ur \ | sort -ur \
| egrep -v "/${latest_iso_date}\$|/${latest_stage3_date}\$" \ | grep -E -v -e "/${latest_iso_date}\$|/${latest_stage3_date}\$" \
| egrep -v -f "${tmpdir}"/.keep.${ARCH}.txt \ | grep -E -v -f "${keepfile}" \
| tail -n +5); do | tail -n +5); do
$DEBUGP rm $VERBOSEP -rf $(pwd)/${i} $DEBUGP rm $VERBOSEP -rf "$(pwd)"/"${i}"
done done
$DEBUGP rm $VERBOSEP -rf ${tmpdir} $DEBUGP rm $VERBOSEP -rf "${tmpdir}"
else else
echo "There was some failure for $ARCH during the weekly sync. Not doing cleanup for fear of dataloss." 1>&2 echo "There was some failure for $ARCH during the weekly sync. Not doing cleanup for fear of dataloss." 1>&2