diff --git a/models/gitea-branch/files/PKGBUILD b/models/gitea-branch/files/PKGBUILD new file mode 100644 index 0000000..4280000 --- /dev/null +++ b/models/gitea-branch/files/PKGBUILD @@ -0,0 +1,30 @@ +# Maintainer: user + +_giteaurl= +_giteauser= +_gitearepo= +_gitcommit= + +pkgname= +pkgver=0 +pkgrel=0 +pkgdesc='Desc' +arch=('any') +url="${_giteaurl}/${_giteauser}/${_gitearepo}" +#license=('GPL3') +#depends=() +makedepends=('git') +#optdepends=() +#install="${pkgname}.install" +#provides=() +#backup=() +source=("git+${_giteaurl}/${_giteauser}/${_gitearepo}.git#commit=${_gitcommit}") +sha256sums=('SKIP') + +build() { + cd "${_gitearepo}" +} + +package() { + cd "${_gitearepo}" +} diff --git a/models/gitea-branch/settings b/models/gitea-branch/settings new file mode 100644 index 0000000..89badd9 --- /dev/null +++ b/models/gitea-branch/settings @@ -0,0 +1,12 @@ +plugin=gitea-branch +target=local-test +giteaurl= +giteauser= +gitearepo= +gitbranch= +gitcommit= +pkgrev=0 +pkgver=0 +version=0 +pkgrel=1 +#aursshkey= diff --git a/plugins/gitea-branch b/plugins/gitea-branch new file mode 100644 index 0000000..17ce417 --- /dev/null +++ b/plugins/gitea-branch @@ -0,0 +1,76 @@ +#!/bin/bash + +plugin_isupdatable() { + return 0 +} + +plugin_isbumpable() { + return 0 +} + +plugin_ispushabletoaur() { + return 0 +} + +plugin_getpkgfiles() { + echo "${PKGDIR}/${PKGNAME}/files" +} + +plugin_bump() { + local -r PKGREL=$(readSetting "${PKGBUILD}" "pkgrel" 0) + sed -i "s/pkgrel=.*/pkgrel=$((PKGREL+1))/" "${PKGBUILD}" +} + +plugin_getlatestversion() { + local -r GITEABASEURL=$(readSetting "${PKGSETTINGS}" "giteaurl" "") + local -r GITEAUSER=$(readSetting "${PKGSETTINGS}" "giteauser" "") + local -r GITEAREPO=$(readSetting "${PKGSETTINGS}" "gitearepo" "") + local -r GITBRANCH=$(readSetting "${PKGSETTINGS}" "gitbranch" "") + local -r GITCOMMIT=$(readSetting "${PKGSETTINGS}" "gitcommit" "") + local -r GITEAURL="${GITEABASEURL}/${GITEAUSER}/${GITEAREPO}.git" + local -r ONLINECOMMIT=$(git ls-remote "${GITEAURL}" | grep "${GITBRANCH}$" | cut -f 1) + if [[ "${ONLINECOMMIT}" == "" ]]; then + echo "Error in Gitea API" + return 1 + fi + if [[ "${GITCOMMIT}" == "${ONLINECOMMIT}" ]]; then + readSetting "${PKGSETTINGS}" "version" "0" + else + local -r PKGVERSION=$(readSetting "${PKGSETTINGS}" "pkgver" "0") + local -r PKGREVISION=$(readSetting "${PKGSETTINGS}" "pkgrev" "0") + local -r PKGNEWREVISION=$((PKGREVISION + 1)) + echo "${PKGVERSION}.r${PKGNEWREVISION}.${ONLINECOMMIT:0:7}-1" + fi +} + +plugin_update() { + local -r GITEABASEURL=$(readSetting "${PKGSETTINGS}" "giteaurl" "") + local -r GITEAUSER=$(readSetting "${PKGSETTINGS}" "giteauser" "") + local -r GITEAREPO=$(readSetting "${PKGSETTINGS}" "gitearepo" "") + local -r GITBRANCH=$(readSetting "${PKGSETTINGS}" "gitbranch" "") + local -r GITCOMMIT=$(readSetting "${PKGSETTINGS}" "gitcommit" "") + local -r GITEAURL="${GITEABASEURL}/${GITEAUSER}/${GITEAREPO}.git" + local -r ONLINECOMMIT=$(git ls-remote "${GITEAURL}" | grep "${GITBRANCH}$" | cut -f 1) + if [[ "${ONLINECOMMIT}" == "" ]]; then + echo "Error in Gitea API" + return 1 + fi + if [[ "${GITCOMMIT}" == "${ONLINECOMMIT}" ]]; then + return 0 + fi + + writeSetting "${PKGSETTINGS}" "gitcommit" "${ONLINECOMMIT}" + local -r PKGREVISION=$(readSetting "${PKGSETTINGS}" "pkgrev" "0") + writeSetting "${PKGSETTINGS}" "pkgrev" "$((PKGREVISION + 1))" + writeSetting "${PKGSETTINGS}" "pkgrel" "1" + + writeSetting "${PKGBUILD}" "_giteaurl" "${GITEABASEURL}" + writeSetting "${PKGBUILD}" "_giteauser" "${GITEAUSER}" + writeSetting "${PKGBUILD}" "_gitearepo" "${GITEAREPO}" + writeSetting "${PKGBUILD}" "_gitcommit" "${ONLINECOMMIT}" + writeSetting "${PKGBUILD}" "pkgname" "${PKGNAME}" + writeSetting "${PKGBUILD}" "pkgrel" "1" + local -r PKGVERSION=$(readSetting "${PKGSETTINGS}" "pkgver" "0") + local -r PKGNEWREVISION=$((PKGREVISION + 1)) + writeSetting "${PKGBUILD}" "pkgver" "${PKGVERSION}.r${PKGNEWREVISION}.${ONLINECOMMIT:0:7}" +} \ No newline at end of file