upgrades; move SUDO and verbosity control to lib

This commit is contained in:
Twenty Panda 2024-03-15 13:17:01 +07:00 committed by p
parent bf6ece0f52
commit 8347d9e040
2 changed files with 13 additions and 19 deletions

View file

@ -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

View file

@ -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' ')