# Contributor: Chloe Kudryavtsev <code@toast.bunkerlabs.net>
# Maintainer: Mike Crute <mike@crute.us>
pkgname=rclone
pkgver=1.68.2
pkgrel=5
pkgdesc="Rsync for cloud storage"
url="https://rclone.org/"
# s390x: https://github.com/cronokirby/saferith/pull/51
# loongarch64: upstream does not support -> cronokirby/saferith
arch="all !s390x !loongarch64"
license="MIT"
makedepends="go"
checkdepends="fuse"
subpackages="$pkgname-doc $pkgname-bash-completion $pkgname-fish-completion $pkgname-zsh-completion"
source="rclone-$pkgver.tar.gz::https://github.com/rclone/rclone/archive/refs/tags/v$pkgver.tar.gz"
options="!check net" # tests fail in CI due filesystem access

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

# secfixes:
#   1.68.2-r0:
#     - CVE-2024-52522
#   1.67.0-r0:
#     - CVE-2023-45288

build() {
	go build

	./rclone genautocomplete bash rclone.bash
	./rclone genautocomplete fish rclone.fish
	./rclone genautocomplete zsh rclone.zsh
}

check() {
	# backend/{ftp,sftp,swift,webdav,seafile}: uses docker(1) for tests
	# backend/{local,memory}: fails in docker envs, but not on real machines
	# fs/rc: fails on ppc64le
	# shellcheck disable=SC2046
	go test $(go list ./... | grep -v \
		-e 'backend/ftp$' \
		-e 'backend/local$' \
		-e 'backend/memory$' \
		-e 'backend/sftp$' \
		-e 'backend/swift$' \
		-e 'backend/webdav$' \
		-e 'backend/seafile$' \
		-e 'fs/rc$'
		)
}

package() {
	install -Dm755 "$builddir"/rclone \
		"$pkgdir"/usr/bin/rclone

	mkdir -p "$pkgdir"/sbin
	ln -sfv ../usr/bin/rclone "$pkgdir"/sbin/mount.rclone
	ln -sfv rclone "$pkgdir"/usr/bin/rclonefs

	install -Dm644 "$builddir"/rclone.1 \
		"$pkgdir"/usr/share/man/man1/rclone.1

	install -Dm644 "$builddir"/rclone.bash \
		"$pkgdir"/usr/share/bash-completion/completions/rclone

	install -Dm644 "$builddir"/rclone.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/rclone.fish

	install -Dm644 "$builddir"/rclone.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_rclone
	
	install -Dm644 COPYING \
		"$pkgdir"/usr/share/licenses/$pkgname/COPYING
}

sha512sums="
02baef752b8537ef5de05c51ce556ee76aee62c6835dc2f0cb6a8ebf0837d524dee1ed69136fb8319511a248d6776e36e53038138bf245f19aa66ea2aac6815c  rclone-1.68.2.tar.gz
"
