2023-01-13 15:54:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-10-02 17:08:18 +00:00
|
|
|
DESTINATION=~/gitea-binaries
|
2022-12-02 14:08:30 +00:00
|
|
|
|
2023-11-22 15:47:27 +00:00
|
|
|
rm -rf $DESTINATION
|
2022-12-02 14:08:30 +00:00
|
|
|
mkdir -p $DESTINATION
|
|
|
|
|
2024-04-27 15:38:20 +00:00
|
|
|
while [ ${#} -gt 0 ]; do
|
|
|
|
case "$1" in
|
2024-10-02 17:08:18 +00:00
|
|
|
--git-tag | -v)
|
2024-04-27 15:38:20 +00:00
|
|
|
shift
|
|
|
|
GITEA_GIT_TAG=$1
|
|
|
|
;; # Gitea Git Tag
|
2024-10-02 17:08:18 +00:00
|
|
|
--golang-version | -g)
|
2024-04-27 15:38:20 +00:00
|
|
|
shift
|
2024-10-02 17:08:18 +00:00
|
|
|
GO_VERSION=$1
|
2024-04-27 15:38:20 +00:00
|
|
|
;; # GOLANG Version
|
2024-10-02 17:08:18 +00:00
|
|
|
--nodejs-version | -n)
|
2024-04-27 15:38:20 +00:00
|
|
|
shift
|
2024-10-02 17:08:18 +00:00
|
|
|
NODEJS_VERSION=$1
|
2024-04-27 15:38:20 +00:00
|
|
|
;; # NodeJS Version
|
2024-10-02 17:08:18 +00:00
|
|
|
--static | -s)
|
|
|
|
BUILD_STATIC=true
|
|
|
|
;; # Also Build Static Assets file
|
|
|
|
--type=* )
|
|
|
|
BUILD_TYPE="${1#*=}"
|
|
|
|
BUILD_TYPE="${BUILD_TYPE,,}"
|
|
|
|
case $BUILD_TYPE in
|
|
|
|
"gitea") BUILD_TYPE="gitea" ;;
|
|
|
|
"forgejo") BUILD_TYPE="forgejo" ;;
|
|
|
|
"")
|
|
|
|
echo "ERROR : --type= is empty!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ERROR : Vaild values for --type are -> gitea, forgejo"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2024-10-28 05:04:16 +00:00
|
|
|
--patch=* )
|
2024-11-08 10:39:47 +00:00
|
|
|
PATCH_FILES="${1#*=}"
|
2024-10-28 05:04:16 +00:00
|
|
|
case $PATCH_FILES in
|
|
|
|
"")
|
|
|
|
echo "ERROR: --patch= is empty!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
2024-11-08 10:39:47 +00:00
|
|
|
esac # Add Patches to your Gitea build. Format -> patch1.patch or patch1.patch,https://patch (Absolute path)
|
|
|
|
;;
|
|
|
|
--build-arch=* )
|
|
|
|
BUILD_ARCH="${1#*=}"
|
|
|
|
case $BUILD_ARCH in
|
|
|
|
"x86_64") BUILD_ARCH="x86_64" ;;
|
|
|
|
"aarch64") BUILD_ARCH="aarch64" ;;
|
|
|
|
"")
|
|
|
|
echo "ERROR : --build-arch= is empty!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ERROR : Vaild values for --build-arch are -> x86_64, aarch64"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac # Architect for your binary to be build. This is for Cross-compiling etc.
|
|
|
|
;;
|
2024-04-27 15:38:20 +00:00
|
|
|
*)
|
|
|
|
;;
|
2023-11-21 12:43:59 +00:00
|
|
|
esac
|
2024-04-27 15:38:20 +00:00
|
|
|
shift # Shift to next response for parsing
|
2023-11-21 12:43:59 +00:00
|
|
|
done
|
|
|
|
|
2024-10-02 17:08:18 +00:00
|
|
|
# If empty
|
|
|
|
NODEJS_VERSION=${NODEJS_VERSION:-"v20.17.0"}
|
|
|
|
GO_VERSION=${GO_VERSION:-"1.23.2"}
|
|
|
|
BUILD_TYPE=${BUILD_TYPE:-"gitea"}
|
|
|
|
|
2024-11-08 10:39:47 +00:00
|
|
|
# OS
|
|
|
|
GOOS=linux
|
|
|
|
NODEJS_DISTRO=linux
|
|
|
|
|
|
|
|
# ARCHITECT
|
|
|
|
|
|
|
|
# This Base Architect is to detect "build" build machine Architect. NOT BUILD ARCHITECT
|
|
|
|
ARCH=${ARCH:-$(uname -m)}
|
|
|
|
case $ARCH in
|
|
|
|
"x86_64")
|
|
|
|
NODEJS_ARCH=x64
|
|
|
|
BASE_GOARCH=amd64
|
|
|
|
;;
|
|
|
|
"aarch64")
|
|
|
|
NODEJS_ARCH=arm64
|
|
|
|
BASE_GOARCH=arm64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "\nPANIC: Arch %s is not supported! exit...\n" $ARCH
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# This define the architect for Build to be. AKA cross-compile stuff.
|
|
|
|
BUILD_ARCH=${BUILD_ARCH:-$(uname -m)}
|
|
|
|
case $BUILD_ARCH in
|
|
|
|
"x86_64")
|
|
|
|
GOARCH=amd64
|
|
|
|
;;
|
|
|
|
"aarch64")
|
|
|
|
GOARCH=arm64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "PANIC: Build Arch %s is not supported! exit...\n" $BUILD_ARCH
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
printf "INFO: Build Architect: %s\nINFO: Machine Architect: %s\n" $BUILD_ARCH $ARCH
|
|
|
|
|
2023-11-21 12:43:59 +00:00
|
|
|
# GITEA_GIT_TAG is being process below
|
2023-01-11 13:10:08 +00:00
|
|
|
|
2023-01-13 15:48:37 +00:00
|
|
|
# Install Dependencies
|
|
|
|
|
2024-11-08 10:39:47 +00:00
|
|
|
DISTRO=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
|
|
|
|
case $DISTRO in
|
2024-10-02 17:08:18 +00:00
|
|
|
"debian" | "ubuntu" )
|
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y \
|
|
|
|
xz-utils \
|
|
|
|
wget \
|
|
|
|
git \
|
|
|
|
tar \
|
|
|
|
g++ \
|
|
|
|
make
|
|
|
|
;;
|
|
|
|
"alpine" )
|
|
|
|
apk update
|
|
|
|
apk add \
|
|
|
|
xz \
|
|
|
|
wget \
|
|
|
|
git \
|
|
|
|
tar \
|
|
|
|
g++ \
|
|
|
|
make
|
|
|
|
;;
|
|
|
|
* )
|
2024-11-08 10:39:47 +00:00
|
|
|
echo "ERROR: the distro detected is not supported. The script will run as is."
|
2024-10-02 17:08:18 +00:00
|
|
|
;;
|
|
|
|
esac
|
2023-01-13 15:48:37 +00:00
|
|
|
|
2022-12-02 14:08:30 +00:00
|
|
|
# NodeJS
|
2024-11-08 10:39:47 +00:00
|
|
|
case $DISTRO in
|
2024-10-02 17:08:18 +00:00
|
|
|
"alpine")
|
2024-11-08 10:39:47 +00:00
|
|
|
apk add nodejs npm # NodeJS in alpine required complex build to be done. For peace of mind i'll use apk until i see better options.
|
2024-10-02 17:08:18 +00:00
|
|
|
;;
|
|
|
|
* )
|
2024-11-08 10:39:47 +00:00
|
|
|
wget https://nodejs.org/dist/$NODEJS_VERSION/node-$NODEJS_VERSION-$NODEJS_DISTRO-$NODEJS_ARCH.tar.xz -O $DESTINATION/node-$NODEJS_VERSION-$DISTRO.tar.xz
|
2024-10-02 17:21:31 +00:00
|
|
|
tar -xJvf $DESTINATION/node-$NODEJS_VERSION-$DISTRO.tar.xz -C $DESTINATION
|
2024-10-02 17:15:05 +00:00
|
|
|
export PATH=$PATH:$DESTINATION/node-$NODEJS_VERSION-$DISTRO/bin
|
2024-10-02 17:08:18 +00:00
|
|
|
;;
|
|
|
|
esac
|
2022-12-02 14:08:30 +00:00
|
|
|
|
|
|
|
# Golang
|
2024-11-08 10:39:47 +00:00
|
|
|
wget https://go.dev/dl/go$GO_VERSION.$GOOS-$BASE_GOARCH.tar.gz -O $DESTINATION/go$GO_VERSION.$GOOS-$BASE_GOARCH.tar.gz
|
|
|
|
tar -C $DESTINATION -xzf $DESTINATION/go$GO_VERSION.$GOOS-$BASE_GOARCH.tar.gz
|
2024-10-02 17:15:05 +00:00
|
|
|
export PATH=$PATH:$DESTINATION/go/bin
|
2022-12-02 14:08:30 +00:00
|
|
|
|
|
|
|
# Gitea
|
|
|
|
|
2024-10-02 17:08:18 +00:00
|
|
|
# GIT_TAG=
|
2023-01-11 13:10:08 +00:00
|
|
|
# specify the tag which gitea will build on
|
|
|
|
|
2024-10-02 17:08:18 +00:00
|
|
|
case $BUILD_TYPE in
|
|
|
|
"gitea")
|
|
|
|
echo "INFO: Building on gitea"
|
|
|
|
git clone https://github.com/go-gitea/gitea $DESTINATION/gitea-repo
|
|
|
|
;;
|
|
|
|
"forgejo")
|
|
|
|
echo "INFO: Building on forgejo"
|
|
|
|
git clone https://codeberg.org/forgejo/forgejo $DESTINATION/gitea-repo #LOL
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cd $DESTINATION/gitea-repo
|
2023-01-11 13:10:08 +00:00
|
|
|
|
2023-11-21 12:43:59 +00:00
|
|
|
if [[ -n $GITEA_GIT_TAG ]]
|
2023-01-11 13:10:08 +00:00
|
|
|
then
|
2023-11-21 12:43:59 +00:00
|
|
|
if git show-ref $GITEA_GIT_TAG --quiet; then
|
|
|
|
git checkout $GITEA_GIT_TAG
|
2023-01-11 13:10:08 +00:00
|
|
|
else
|
2024-10-30 13:08:41 +00:00
|
|
|
echo -e "\nGITEA_GIT_TAG variable doesn't match the repo tag/version. exit to prevent further issue." && exit 1
|
2023-01-11 13:10:08 +00:00
|
|
|
fi
|
|
|
|
else
|
2024-10-28 05:04:16 +00:00
|
|
|
echo -e "GITEA_GIT_TAG variable not found. will build on "main" branch."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $PATCH_FILES ]]
|
|
|
|
then
|
|
|
|
for patch in $(echo "$PATCH_FILES" | tr ',' '\n'); do
|
2024-10-30 13:08:41 +00:00
|
|
|
case $patch in
|
|
|
|
http://*|https://*)
|
|
|
|
# The random part:
|
|
|
|
# https://stackoverflow.com/questions/2793812/generate-a-random-filename-in-unix-shell
|
|
|
|
NEW_PATCH_PATH=$DESTINATION/$(head /dev/urandom | tr -cd 'a-f0-9' | head -c 32)".patch"
|
|
|
|
|
|
|
|
if wget $patch -O $NEW_PATCH_PATH; then
|
|
|
|
printf "Info: '%s' has been downloaded. Filename: %s\n" $patch $NEW_PATCH_PATH
|
|
|
|
else
|
|
|
|
printf "Info: '%s' Download failed! The task is aborted.\n" $patch
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
patch=$NEW_PATCH_PATH ;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
|
2024-10-28 05:04:16 +00:00
|
|
|
if git apply --check $patch; then
|
|
|
|
git apply $patch
|
|
|
|
printf "Info: PATCH '%s' applied successful!\n" $patch
|
|
|
|
else
|
|
|
|
printf "Error: PATCH '%s' cannot be applied! exiting...\n" $patch
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2023-01-11 13:10:08 +00:00
|
|
|
fi
|
|
|
|
|
2023-11-22 14:54:02 +00:00
|
|
|
# Sometimes VPS Provider's CPU limitation is dick
|
2024-10-02 17:08:18 +00:00
|
|
|
export LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=/var/lib/gitea/\" -X \"code.gitea.io/gitea/modules/setting.CustomConf=/etc/gitea/app.ini\""
|
|
|
|
export TAGS="bindata sqlite sqlite_unlock_notify"
|
2024-11-08 10:39:47 +00:00
|
|
|
export GOOS=$GOOS
|
|
|
|
export GOARCH=$GOARCH
|
2024-10-02 17:08:18 +00:00
|
|
|
|
|
|
|
make build
|
|
|
|
mv gitea $DESTINATION/gitea
|
2023-11-22 14:54:02 +00:00
|
|
|
|
2024-04-27 15:38:20 +00:00
|
|
|
if [[ "$BUILD_STATIC" == true ]]
|
2023-11-22 14:54:02 +00:00
|
|
|
then
|
|
|
|
mkdir -p $DESTINATION/gitea-static
|
2024-10-02 17:08:18 +00:00
|
|
|
|
|
|
|
make frontend
|
2024-10-02 17:15:05 +00:00
|
|
|
mv $DESTINATION/gitea-repo/public/* $DESTINATION/gitea-static
|
|
|
|
fi
|