shfmt -w globally

This commit is contained in:
Earl Warren 2024-08-07 08:31:33 +02:00
parent 4e207414d4
commit d5f66e4c0a
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
27 changed files with 378 additions and 375 deletions

View file

@ -2,11 +2,11 @@
# Copyright 2024 The Forgejo Authors
# SPDX-License-Identifier: MIT
LIB_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $LIB_DIR/api.sh
if ${VERBOSE:-false} ; then
if ${VERBOSE:-false}; then
set -ex
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
else
@ -17,8 +17,8 @@ set -o pipefail
export DEBIAN_FRONTEND=noninteractive
if test $(id -u) != 0 ; then
SUDO=sudo
if test $(id -u) != 0; then
SUDO=sudo
fi
IP=$(hostname -I | cut -f1 -d' ')
@ -35,7 +35,7 @@ export DOT_FORGEJO_CURL=$DIR/forgejo-curl
export DOT=$DOT_FORGEJO_CURL # for backward compatibility with forgejo-curl.sh 1.0.0
: ${FORGEJO_USER:=root}
: ${FORGEJO_PASSWORD:=admin1234}
: ${RELEASE_NUMBERS_AND_DEV:="$(for r in $RELEASE_NUMBERS ; do echo -n "$r $r-dev " ; done)"}
: ${RELEASE_NUMBERS_AND_DEV:="$(for r in $RELEASE_NUMBERS; do echo -n "$r $r-dev "; done)"}
ORGANIZATIONS=$(cat $LIB_DIR/ORGANIZATIONS)
function log_info() {
@ -44,50 +44,50 @@ function log_info() {
function dependencies() {
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
$SUDO chmod +x /usr/local/bin/forgejo-curl.sh
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
$SUDO chmod +x /usr/local/bin/forgejo-curl.sh
fi
if ! which make curl daemon git-lfs jq sqlite3 skopeo > /dev/null ; then
if ! which make curl daemon git-lfs jq sqlite3 skopeo >/dev/null; then
$SUDO apt-get update -qq
$SUDO apt-get install -y -qq make curl daemon git-lfs jq sqlite3 skopeo
fi
if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio ; then
if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio; then
$SUDO curl --fail -sS https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc
$SUDO curl --fail -sS https://dl.min.io/server/minio/release/linux-amd64/minio -o /usr/local/bin/minio
fi
if ! test -x /usr/local/bin/mc || ! test -x /usr/local/bin/minio ; then
if ! test -x /usr/local/bin/mc || ! test -x /usr/local/bin/minio; then
$SUDO chmod +x /usr/local/bin/mc
$SUDO chmod +x /usr/local/bin/minio
fi
if ! test -f /usr/local/bin/garage > /dev/null ; then
if ! test -f /usr/local/bin/garage >/dev/null; then
$SUDO curl --fail -sS https://garagehq.deuxfleurs.fr/_releases/v0.8.2/x86_64-unknown-linux-musl/garage -o /usr/local/bin/garage
fi
if ! test -x /usr/local/bin/garage > /dev/null ; then
if ! test -x /usr/local/bin/garage >/dev/null; then
$SUDO chmod +x /usr/local/bin/garage
fi
}
function build_all() {
for dev in $RELEASE_NUMBERS ; do
local forgejo=$DIR_BINARIES/forgejo-$dev-dev
if test -f $forgejo ; then
log_info $dev already exists
else
$LIB_DIR/build.sh $dev $DIR_BINARIES
log_info $dev built from sources
fi
for dev in $RELEASE_NUMBERS; do
local forgejo=$DIR_BINARIES/forgejo-$dev-dev
if test -f $forgejo; then
log_info $dev already exists
else
$LIB_DIR/build.sh $dev $DIR_BINARIES
log_info $dev built from sources
fi
done
}
function retry() {
rm -f $DIR/wait-for.out
success=false
for delay in 1 1 5 5 15 ; do
if "$@" >> $DIR/wait-for.out 2>&1 ; then
for delay in 1 1 5 5 15; do
if "$@" >>$DIR/wait-for.out 2>&1; then
success=true
break
fi
@ -95,7 +95,7 @@ function retry() {
echo waiting $delay
sleep $delay
done
if test $success = false ; then
if test $success = false; then
cat $DIR/wait-for.out
return 1
fi
@ -105,36 +105,36 @@ function full_version() {
local version=$1
local owner=$2
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]] ; then
full_version=$(curl -sS "https://codeberg.org/api/v1/repos/$owner/forgejo/releases?limit=50" | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort --reverse --version-sort | head -1)
echo ${full_version#v}
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]]; then
full_version=$(curl -sS "https://codeberg.org/api/v1/repos/$owner/forgejo/releases?limit=50" | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort --reverse --version-sort | head -1)
echo ${full_version#v}
else
echo $version
echo $version
fi
}
function download_forgejo() {
local version=$1
if ! test -f $DIR_BINARIES/forgejo-$version ; then
if ! test -f $DIR_BINARIES/forgejo-$version; then
mkdir -p $DIR_BINARIES
for owner in $ORGANIZATIONS ; do
full_version=$(full_version $version $owner)
if test "$full_version" = "" ; then
continue
fi
if wget -O $DIR_BINARIES/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$full_version/forgejo-$full_version-linux-amd64 ; then
break
fi
done
if test -s $DIR_BINARIES/forgejo-$version ; then
if test "$version" != "$full_version" ; then
log_info "downloaded Forgejo $full_version for $version"
fi
else
echo unable to download Forgejo $version
return 1
fi
for owner in $ORGANIZATIONS; do
full_version=$(full_version $version $owner)
if test "$full_version" = ""; then
continue
fi
if wget -O $DIR_BINARIES/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$full_version/forgejo-$full_version-linux-amd64; then
break
fi
done
if test -s $DIR_BINARIES/forgejo-$version; then
if test "$version" != "$full_version"; then
log_info "downloaded Forgejo $full_version for $version"
fi
else
echo unable to download Forgejo $version
return 1
fi
chmod +x $DIR_BINARIES/forgejo-$version
fi
}
@ -142,9 +142,9 @@ function download_forgejo() {
function download_gitea() {
local version=$1
if ! test -f $DIR_BINARIES/gitea-$version ; then
if ! test -f $DIR_BINARIES/gitea-$version; then
mkdir -p $DIR_BINARIES
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]] ; then
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]]; then
full_version=$(curl -sS "https://api.github.com/repos/go-gitea/gitea/releases?per_page=100" | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | grep -v -e '-rc' | sort --reverse --version-sort | head -1)
full_version=${full_version#v}
else
@ -152,8 +152,8 @@ function download_gitea() {
fi
wget -O $DIR_BINARIES/gitea-$version --quiet https://dl.gitea.com/gitea/$full_version/gitea-$full_version-linux-amd64
if test -s $DIR_BINARIES/gitea-$version ; then
if test "$version" != "$full_version" ; then
if test -s $DIR_BINARIES/gitea-$version; then
if test "$version" != "$full_version"; then
log_info "downloaded Gitea $full_version for $version"
fi
else
@ -185,18 +185,18 @@ function clobber() {
function start_gitlab_cache_load() {
local image=$1
local d=$DIR_BINARIES/gitlab
if test -d $d ; then
log_info "loading $image from $d"
skopeo copy dir:$d docker-daemon:$image
if test -d $d; then
log_info "loading $image from $d"
skopeo copy dir:$d docker-daemon:$image
fi
}
function start_gitlab_cache_save() {
local image=$1
local d=$DIR_BINARIES/gitlab
if ! test -d $d ; then
log_info "saving $image to $d"
skopeo copy docker-daemon:$image dir:$d
if ! test -d $d; then
log_info "saving $image to $d"
skopeo copy docker-daemon:$image dir:$d
fi
}
@ -208,21 +208,21 @@ function start_gitlab() {
local GITLAB_OMNIBUS_CONFIG="nginx['listen_https'] = false ; nginx['listen_port'] = 8181 ; external_url 'http://$IP:$GITLAB_PORT'; gitlab_rails['gitlab_shell_ssh_port'] = 2221; $config"
docker run --name="test-gitlab" --shm-size=128M -d \
-e GITLAB_OMNIBUS_CONFIG="$GITLAB_OMNIBUS_CONFIG" \
-p 2221:22 -p $GITLAB_PORT:8181 \
$image >& /dev/null < /dev/null
-e GITLAB_OMNIBUS_CONFIG="$GITLAB_OMNIBUS_CONFIG" \
-p 2221:22 -p $GITLAB_PORT:8181 \
$image >&/dev/null </dev/null
start_gitlab_cache_save $image
for i in $(seq 10) ; do
if test $(curl --silent http://$IP:$GITLAB_PORT -o /dev/null -w "%{http_code}") = 302 ; then
docker exec test-gitlab gitlab-rails runner "user = User.find_by_username 'root'; user.password = '$GITLAB_PASSWORD'; user.password_confirmation = '$GITLAB_PASSWORD'; user.password_automatically_set = false ; user.save!"
docker exec test-gitlab$serial gitlab-rails runner "Gitlab::CurrentSettings.current_application_settings.update(default_vcs_type: 'git')"
log_info "GitLab is ready"
return
fi
log_info "waiting for GitLab to come up $i"
sleep 30
for i in $(seq 10); do
if test $(curl --silent http://$IP:$GITLAB_PORT -o /dev/null -w "%{http_code}") = 302; then
docker exec test-gitlab gitlab-rails runner "user = User.find_by_username 'root'; user.password = '$GITLAB_PASSWORD'; user.password_confirmation = '$GITLAB_PASSWORD'; user.password_automatically_set = false ; user.save!"
docker exec test-gitlab$serial gitlab-rails runner "Gitlab::CurrentSettings.current_application_settings.update(default_vcs_type: 'git')"
log_info "GitLab is ready"
return
fi
log_info "waiting for GitLab to come up $i"
sleep 30
done
log_info "GitLab did not come up"
docker logs test-gitlab
@ -263,12 +263,12 @@ function start_forgejo_daemon() {
local base=$(work_path_base $config)
local work_path=$DIR/$base
daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/$base-pid --errlog=$DIR/$base-err.log --output=$DIR/$base-out.log -- $binary --config $work_path/app.ini --work-path $work_path
if ! retry grep --no-messages --quiet 'Starting server on' $work_path/log/forgejo.log ; then
if ! retry grep --no-messages --quiet 'Starting server on' $work_path/log/forgejo.log; then
grep '' $DIR/$base*.log
grep '' $work_path/log/*.log 2> /dev/null
grep '' $work_path/log/*.log 2>/dev/null
return 1
fi
echo "$binary --config $work_path/app.ini --work-path $work_path" '"$@"' > $work_path/forgejocli
echo "$binary --config $work_path/app.ini --work-path $work_path" '"$@"' >$work_path/forgejocli
chmod +x $work_path/forgejocli
cp -a $work_path/forgejocli $DIR/forgejocli # because setup-forgejo/forgejo-runner.sh expects it here
create_user_and_login $version $config
@ -277,18 +277,18 @@ function start_forgejo_daemon() {
function start_minio() {
mkdir -p $DIR/minio
daemon --chdir=$DIR --unsafe \
--env="PATH=$PATH" \
--env=MINIO_ROOT_USER=123456 \
--env=MINIO_ROOT_PASSWORD=12345678 \
--env=MINIO_VOLUMES=$DIR/minio \
--pidfile=$DIR/minio-pid --errlog=$DIR/minio-err.log --output=$DIR/minio-out.log -- /usr/local/bin/minio server
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678 >& /dev/null
--env="PATH=$PATH" \
--env=MINIO_ROOT_USER=123456 \
--env=MINIO_ROOT_PASSWORD=12345678 \
--env=MINIO_VOLUMES=$DIR/minio \
--pidfile=$DIR/minio-pid --errlog=$DIR/minio-err.log --output=$DIR/minio-out.log -- /usr/local/bin/minio server
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678 >&/dev/null
mc alias set testS3 http://127.0.0.1:9000 123456 12345678
}
function start_garage() {
mkdir -p $DIR/garage/{data,meta}
cat > $DIR/garage/garage.toml <<EOF
cat >$DIR/garage/garage.toml <<EOF
metadata_dir = "$DIR/garage/meta"
data_dir = "$DIR/garage/data"
db_engine = "lmdb"
@ -318,14 +318,14 @@ admin_token = "$(openssl rand -base64 32)"
EOF
daemon --chdir=$DIR --unsafe \
--env="PATH=$PATH" \
--env=RUST_LOG=garage_api=debug \
--pidfile=$DIR/garage-pid --errlog=$DIR/garage-err.log --output=$DIR/garage-out.log -- /usr/local/bin/garage -c $DIR/garage/garage.toml server
--env="PATH=$PATH" \
--env=RUST_LOG=garage_api=debug \
--pidfile=$DIR/garage-pid --errlog=$DIR/garage-err.log --output=$DIR/garage-out.log -- /usr/local/bin/garage -c $DIR/garage/garage.toml server
retry garage -c $DIR/garage/garage.toml status
garage -c $DIR/garage/garage.toml layout assign -z dc1 -c 1 $(garage -c $DIR/garage/garage.toml status | tail -1 | grep -o '[0-9a-z]*' | head -1)
ver=$(garage -c $DIR/garage/garage.toml layout show | grep -oP '(?<=Current cluster layout version: )\d+')
garage -c $DIR/garage/garage.toml layout apply --version $((ver+1))
garage -c $DIR/garage/garage.toml layout apply --version $((ver + 1))
garage -c $DIR/garage/garage.toml key info test || garage -c $DIR/garage/garage.toml key import -n test 123456 12345678
garage -c $DIR/garage/garage.toml key allow --create-bucket test
retry mc alias set testS3 http://127.0.0.1:9000 123456 12345678
@ -347,10 +347,10 @@ function start() {
function get_host_port() {
local config="$1"
if test -z "$config" ; then
echo "$IP:3000"
if test -z "$config"; then
echo "$IP:3000"
else
echo "$IP:$(sed -n -e 's/^HTTP_PORT *= *\(.*\)/\1/p' < $config)"
echo "$IP:$(sed -n -e 's/^HTTP_PORT *= *\(.*\)/\1/p' <$config)"
fi
}
@ -358,10 +358,10 @@ HOST_PORT=$(get_host_port)
function work_path_base() {
local config="$1"
if test -z "$config" ; then
echo forgejo-work-path
if test -z "$config"; then
echo forgejo-work-path
else
sed -n -e 's/^WORK_PATH *= *\(.*\)/\1/p' < $config
sed -n -e 's/^WORK_PATH *= *\(.*\)/\1/p' <$config
fi
}
@ -371,9 +371,9 @@ function reset_forgejo() {
rm -fr $work_path
mkdir -p $work_path
sed -e "s/\${IP}/$IP/g" \
-e "s|\${WORK_PATH}|$work_path|g" \
-e "s|^WORK_PATH = .*|WORK_PATH = $work_path|" \
< $config > $work_path/app.ini
-e "s|\${WORK_PATH}|$work_path|g" \
-e "s|^WORK_PATH = .*|WORK_PATH = $work_path|" \
<$config >$work_path/app.ini
}
function reset_minio() {
@ -391,19 +391,19 @@ function create_user_and_login() {
local work_path=$DIR/$(work_path_base $config)
local email="$FORGEJO_USER@example.com"
if ! $work_path/forgejocli admin user list | grep --quiet "$email" ; then
$work_path/forgejocli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email $email
if ! $work_path/forgejocli admin user list | grep --quiet "$email"; then
$work_path/forgejocli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email $email
fi
forgejo-curl.sh logout
local scopes='--scopes ["all"]'
if echo $version | grep --quiet 1.18 ; then
if echo $version | grep --quiet 1.18; then
scopes=""
fi
forgejo-curl.sh --user "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" $scopes login http://$(get_host_port $config)
local forgejo_curl=$work_path/forgejo-curl.sh
cat > $forgejo_curl <<EOF
cat >$forgejo_curl <<EOF
#!/bin/bash
export DOT_FORGEJO_CURL=$work_path/forgejo-curl
export DOT=$work_path/forgejo-curl # for backward compatibility with forgejo-curl.sh 1.0.0
@ -416,12 +416,12 @@ EOF
function stop_daemon() {
local daemon=$1
if test -f $DIR/$daemon-pid ; then
if test -f $DIR/$daemon-pid; then
local pid=$(cat $DIR/$daemon-pid)
kill -TERM $pid
pidwait $pid || true
for delay in 1 1 2 2 5 5 ; do
if ! test -f $DIR/$daemon-pid ; then
for delay in 1 1 2 2 5 5; do
if ! test -f $DIR/$daemon-pid; then
break
fi
sleep $delay
@ -441,16 +441,16 @@ function stop() {
}
function show_logs() {
if ! test -d $DIR ; then
log_info "$DIR does not exist, no logs to display"
return
if ! test -d $DIR; then
log_info "$DIR does not exist, no logs to display"
return
fi
(
cd $DIR
set +e
cd $DIR
set +e
grep --with-filename --text '' *.log
grep --with-filename --text '' */log/*.log
grep --with-filename --text '' *.out
grep --with-filename --text '' *.out
)
}
@ -460,10 +460,10 @@ function run() {
echo Start running $fun "$@"
mkdir -p $DIR
> $DIR/$fun.out
>$DIR/$fun.out
tail --follow $DIR/$fun.out |& sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
local pid=$!
if ! VERBOSE=true $SELF $fun "$@" >& $DIR/$fun.out ; then
if ! VERBOSE=true $SELF $fun "$@" >&$DIR/$fun.out; then
kill $pid
cat $DIR/$fun.out
echo Failure running $fun