# Template file for 'gitea'
pkgname=gitea
version=1.10.1
revision=1
build_style=go
go_import_path=code.gitea.io/gitea
# This could be done with build options, but these are built in with the
# following justification.
#   * bindata: running with things not all in the binary is not a
#     supported distribution format by the gitea upstream developers.
#     That mode is only supported for development of gitea within the
#     source tree
#   * sqlite: this is likely the database that everyone will use.  Only
#     particularly large installations will want to go through the
#     effort of setting up a real database server.
#   * pam: PAM allows for authentication to varied external sources.
#     Internal authentication supports the local database, OpenID, and
#     LDAP, but basic other auth sources such as Kerberos and more
#     exotic authenticators require PAM support to be useable.
#   * tidb: This is an alternate database engine for users who would
#     rather not use SQLite3 for some reason.  It is also potentially
#     more resiliant to corrupted writes.
go_build_tags="bindata sqlite pam tidb"
go_ldflags=" -X main.Version=${version}"
hostmakedepends="go-bindata git"
makedepends="sqlite-devel pam-devel"
depends="git"
short_desc="Git with a cup of Tea"
maintainer="Michael Aldridge <maldridge@voidlinux.org>"
license="MIT"
homepage="https://gitea.io"
changelog="https://github.com/go-gitea/gitea/blob/master/CHANGELOG.md"
distfiles="https://github.com/go-gitea/gitea/archive/v${version}.tar.gz"
checksum=01a158128803e3e310d6e8816f49a8f1c6ef82d7c29c3fc9dbdefddad7b0bfdf
nocross="https://api.travis-ci.org/v3/job/616733825/log.txt"

system_accounts="_gitea"
_gitea_homedir="/var/lib/gitea"
_gitea_shell="/bin/bash" # Proper shell needed for ssh support
make_dirs="/var/lib/gitea 0755 _gitea _gitea
 /var/log/gitea 0755 _gitea root"
conf_files="/etc/gitea.conf"

pre_build() {
	make generate
}

pre_install() {
	sed -i \
		'/RUN_USER/s:git:_gitea:
		s:666:660:
		/RUN_MODE/s:dev:prod:
		/DB_TYPE/s:mysql:sqlite3:
		s:ROOT =:& /var/lib/gitea/repositories:
		s:tmp/local-repo:/var/lib/gitea/&:
		s:tmp/local-wiki:/var/lib/gitea/&:
		/TEMP_PATH/s:data/tmp/uploads:/var/lib/gitea/tmp/uploads:
		/LFS_CONTENT/s:data/lfs:/var/lib/gitea/lfs:
		s:data/gitea.db:/var/lib/gitea/&:
		s:indexers/issues.bleve:/var/lib/gitea/&:
		s:data/avatars:/var/lib/gitea/&:
		s:SSH_ROOT_PATH =:& /var/lib/gitea:
		s:STATIC_ROOT_PATH =:& /var/lib/gitea:
		s:^ROOT_PATH =:& /var/log/gitea:' custom/conf/app.ini.sample
}

post_install() {
	vlicense LICENSE
	vsv gitea
	sed -e '/^\[U2F\]$/,/^$/d' -i custom/conf/app.ini.sample
	vinstall custom/conf/app.ini.sample 0640 /etc gitea.conf
}
