From 90dd3c784a1cc461af9efd52a5f69188e285f72d Mon Sep 17 00:00:00 2001 From: Diego Giovane Pasqualin <dpasqualin@c3sl.ufpr.br> Date: Tue, 12 Nov 2013 10:20:17 -0200 Subject: [PATCH] update_mirror.sh: Improve sanity check for repositories arguments This prevents accidental copies of packages to wrong repositories. Signed-off-by: Diego Giovane Pasqualin <dpasqualin@c3sl.ufpr.br> --- bin/update_mirror.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bin/update_mirror.sh b/bin/update_mirror.sh index c254bb10..0e331e14 100755 --- a/bin/update_mirror.sh +++ b/bin/update_mirror.sh @@ -30,6 +30,11 @@ PUBLISHSCRIPT="$(dirname $0)/le_publish.sh" PROJECT="le" HOST="http://windu.c3sl.ufpr.br/$PROJECT" +# This is the "order" of the repositories, it means that usually the +# developer will upgrade a package from unstable to testing, after that from +# testing to rc, and so on. +REPO_ORDER=( unstable testing rc stable ) + function clean() { rm -rf $TMPDIR exit 0 @@ -137,6 +142,30 @@ fi FROMREPO=$1 TOREPO=$2 +# Check repository order and validity +if ! (grep -qw $FROMREPO <<< ${REPO_ORDER[@]} && + grep -qw $TOREPO <<< ${REPO_ORDER[@]}); then + echo -n "Repositories must be one of the following: " + echo ${REPO_ORDER[@]} + exit 1 +fi + +for ((i=0; i<${#REPO_ORDER[@]}; i++)); do + if [ ${REPO_ORDER[$i]} = $FROMREPO ]; then + next=${REPO_ORDER[(($i+1))]} + if [ $next != $TOREPO ]; then + echo -n "You are trying to copy a package from $FROMREPO to" + echo " $TOREPO. Usually you'd copy it to $next first." + read -p "Are you sure you wanna do this (y/N)? " yn + if [ "$yn" != "y" ]; then + exit 0 + fi + fi + break + fi +done + +# Check whether diff argument was given DIFF=false if test "$3" = "--diff"; then DIFF=true -- GitLab