From 8347d9e0401beb811cffa11680b5bd7196bd5027 Mon Sep 17 00:00:00 2001 From: Twenty Panda Date: Fri, 15 Mar 2024 13:17:01 +0700 Subject: [PATCH] upgrades; move SUDO and verbosity control to lib --- forgejo/upgrades/test-upgrade.sh | 22 +++++----------------- lib/lib.sh | 10 ++++++++-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/forgejo/upgrades/test-upgrade.sh b/forgejo/upgrades/test-upgrade.sh index b0a104e..7967454 100755 --- a/forgejo/upgrades/test-upgrade.sh +++ b/forgejo/upgrades/test-upgrade.sh @@ -11,25 +11,21 @@ # Everything happens in /tmp/forgejo-upgrades # +SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $SELF_DIR/../../lib/lib.sh + # # Forgejo releases for which a branch exists (7.0/forgejo etc.) # RELEASE_NUMBERS="7.0" PREFIX=============== -HOST_PORT=$(hostname -I | cut -f1 -d' '):3000 +HOST_PORT=$IP:3000 STORAGE_PATHS="attachments avatars lfs packages repo-archive repo-avatars" STORAGE_FUN="attachments avatars lfs packages repo_archive repo_avatars" DIR=/tmp/forgejo-upgrades export DOT_FORGEJO_CURL=$DIR/forgejo-curl export DOT=$DOT_FORGEJO_CURL # for backward compatibility with forgejo-curl.sh 1.0.0 -if ${VERBOSE:-false} ; then - set -ex - PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' -else - set -e -fi -SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" : ${FORGEJO_USER:=root} : ${FORGEJO_REPO:=fixture} : ${FORGEJO_PASSWORD:=admin1234} @@ -37,18 +33,11 @@ RELEASE_NUMBERS_AND_DEV="$(for r in $RELEASE_NUMBERS ; do echo -n $r $r-dev ; do source $SELF_DIR/fixtures.sh -function maybe_sudo() { - if test $(id -u) != 0 ; then - SUDO=sudo - fi -} - function log_info() { echo "$PREFIX $@" } function dependencies() { - maybe_sudo if ! test -f /usr/local/bin/forgejo-curl.sh ; then $SUDO curl --fail -sS https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh -o /usr/local/bin/forgejo-curl.sh @@ -56,7 +45,6 @@ function dependencies() { fi if ! which curl daemon jq git-lfs > /dev/null ; then - export DEBIAN_FRONTEND=noninteractive $SUDO apt-get update -qq $SUDO apt-get install -y -qq curl daemon git-lfs jq sqlite3 gettext-base fi @@ -367,7 +355,7 @@ function run() { mkdir -p $DIR > $DIR/$fun.out tail --follow $DIR/$fun.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" & - pid=$! + local pid=$! if ! VERBOSE=true ${BASH_SOURCE[0]} $fun "$@" >& $DIR/$fun.out ; then kill $pid cat $DIR/$fun.out diff --git a/lib/lib.sh b/lib/lib.sh index f5155c0..4bacc59 100644 --- a/lib/lib.sh +++ b/lib/lib.sh @@ -2,7 +2,13 @@ # Copyright 2024 The Forgejo Authors # SPDX-License-Identifier: MIT -set -e +if ${VERBOSE:-false} ; then + set -ex + PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' +else + set -e +fi + set -o pipefail export DEBIAN_FRONTEND=noninteractive @@ -11,4 +17,4 @@ if test $(id -u) != 0 ; then SUDO=sudo fi -PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' +IP=$(hostname -I | cut -f1 -d' ')