upgrades: the X.Y version is equivalent to the latest patch release

This commit is contained in:
Twenty Panda 2024-03-14 12:09:29 +07:00 committed by p
parent 4dc1068027
commit bc55c01cc6
2 changed files with 27 additions and 3 deletions

View file

@ -9,7 +9,7 @@ SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
version=$1
DIR=$2
v=$(echo $version | sed -E -e 's/([0-9]+\.[0-9]+).*/\1/')
v=$(echo $version | sed -E -e 's/^([0-9]+\.[0-9]+).*/\1/')
read url ref semver < $SELF_DIR/sources/$v
rm -fr $DIR/src

View file

@ -87,16 +87,40 @@ function retry() {
fi
}
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 | jq -r '.[] | .tag_name | select(startswith("v'$version'"))' | sort -r | head -1)
echo ${full_version#v}
else
echo $version
fi
}
function download() {
local version=$1
if ! test -f $DIR/forgejo-$version ; then
mkdir -p $DIR
for owner in forgejo forgejo-experimental forgejo-integration ; do
if wget -O $DIR/forgejo-$version --quiet https://codeberg.org/$owner/forgejo/releases/download/v$version/forgejo-$version-linux-amd64 ; then
full_version=$(full_version $version $owner)
if test "$full_version" = "" ; then
continue
fi
if wget -O $DIR/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/forgejo-$version ; then
if test "$version" != "$full_version" ; then
log_info "downloaded $full_version for $version"
fi
else
echo unable to download Forgejo $version
return 1
fi
chmod +x $DIR/forgejo-$version
fi
}
@ -208,7 +232,7 @@ function create_user() {
local cli="$DIR/forgejo-$version --config $work_path/app.ini --work-path $work_path"
$cli admin user create --admin --username "$FORGEJO_USER" --password "$FORGEJO_PASSWORD" --email "$FORGEJO_USER@example.com"
local scopes="--scopes all"
if echo $version | grep --quiet 1.18. ; then
if echo $version | grep --quiet 1.18 ; then
scopes=""
fi