Username: Password: Remember me
# Maintainer (as of 1.1.1): Mark Haferkamp <chakralinux.org@refola.com>
# Contributor ([desktop] repo to CCR): Justin berthault <justin.berthault@zaclys.net>
# Contributors from package's [desktop] era: https://code.chakralinux.org/chakra/packages/desktop/commits/497b2449f7c2beb43441338567b86698abb1db77/syncthing/PKGBUILD
 
# NOTE: check() fails about half the time for Syncthing 1.1.2+. If you
# have any ideas why, please comment at
# https://ccr.chakralinux.org/packages.php?ID=8365 .  So far, I've
# figured out that the 'go-pie' package always fails, but 'go' only
# fails half the time. The failure is always on testing
# github.com/syncthing/syncthing/lib/model.
 
# WORKAROUND: Manually retry from `check()` and manually install.
# 1. `cd` to your CCR build directory
#    (e.g., `cd /tmp/ccrbuild-$UID/syncthing/syncthing`).
# 2. Repeatedly run `makepkg --noprepare --check` until it succeeds.
#    This restarts building from `check()`.
# 3. Run `makepkg --install`. This manually installs it.
 
pkgname='syncthing'
pkgver="1.2.0"
pkgrel="1"
pkgdesc="Open Source Continuous File Synchronization"
arch=('x86_64')
url="https://syncthing.net"
license=('MPLv2')
depends=('glibc')
makedepends=('git' 'go' 'inetutils')
source=("https://github.com/syncthing/syncthing/releases/download/v${pkgver}/syncthing-source-v${pkgver}.tar.gz")
sha256sums=('0339877effdcf3bf8aa7d4d1e50b878992792e4752ff778f27788bf71eccecd0')
 
prepare() {
  # TODO: Make idempotent to avoid this failure when retrying build after check() randomly fails:
  # mv: cannot overwrite non-directory 'src/github.com/syncthing/syncthing/syncthing' with directory 'syncthing'
  install -d "src/github.com/syncthing"
  mv "${pkgbase}" "src/github.com/syncthing/${pkgbase}"
}
 
build() {
  export GOPATH="${srcdir}" GOROOT_FINAL="/usr/bin"
  cd "${srcdir}/src/github.com/syncthing/${pkgbase}"
  go run build.go -no-upgrade -version "v${pkgver}" build
}
 
check() {
  export GOPATH="${srcdir}" GOROOT_FINAL="/usr/bin"
  cd "${srcdir}/src/github.com/syncthing/${pkgbase}"
  if [ "${CARCH}" == "x86_64" ] ; then
    go run build.go -no-upgrade test
  fi
}
 
package() {
  install="$pkgname.install"
 
  cd "${srcdir}/src/github.com/syncthing/${pkgbase}"
  install -Dm755 "${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
  install -Dm644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
  install -Dm644 "etc/linux-systemd/system/${pkgname}-resume.service" \
          "${pkgdir}/usr/lib/systemd/system/${pkgname}-resume.service"
  install -Dm644 "etc/linux-systemd/system/${pkgname}@.service" \
          "${pkgdir}/usr/lib/systemd/system/${pkgname}@.service"
  install -Dm644 "etc/linux-systemd/user/${pkgname}.service" \
          "${pkgdir}/usr/lib/systemd/user/${pkgname}.service"
 
  # license
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
 
  # ufw preset
  install -Dm644 etc/firewall-ufw/syncthing \
          "$pkgdir/etc/ufw/applications.d/ufw-syncthing"
 
  # man pages
  cd "${srcdir}/src/github.com/syncthing/${pkgname}/man"
  for file in $(find . -name '*.1' -print); do
    install -Dm644 "$file" "${pkgdir}/usr/share/man/man1/$file"
  done
  for file in $(find . -name '*.5' -print); do
    install -Dm644 "$file" "${pkgdir}/usr/share/man/man5/$file"
  done
  for file in $(find . -name '*.7' -print); do
    install -Dm644 "$file" "${pkgdir}/usr/share/man/man7/$file"
  done
}