summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 61edf086a8d81fc4f5cc5611bbfec24d80d073a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Maintainer: Josias <aur at macherstube dot ch>
_pkgname=kubo
_plgname=go-ds-s3
_pkgplgname=$_pkgname-s3
pkgname=$_pkgplgname-git
pkgver=0.26.0.r0.g096f510
pkgrel=1
pkgdesc="IPFS Kubo with S3 Datastore Implementation"
arch=('x86_64')
url="https://github.com/chixodo-xyz/kubo-s3"
license=('GPL3')
groups=()
depends=(glibc)
makedepends=(go git gawk sed which)
provides=("$_pkgplgname" "ipfs")
conflicts=("$_pkgplgname" 'kubo' 'ipfs')
replaces=()
backup=()
options=()
install='prod.install'
source=('git+https://github.com/ipfs/kubo'
				'git+https://github.com/ipfs/go-ds-s3'
				'versions.txt'
				'ipfs.service')
noextract=()
b2sums=('SKIP'
				'SKIP'
				'182e0a3a925415920088fb2ba956d61fdde0bcc6d50f1844e1e29d823897ac526c1bcf7887e294423945f470514031550f2d0e1e75174eef5da8ebeeb3bb2d6c'
				'e7df78fa46537d2f54a83c8e65ca2aeb30c4b88b4ab52a4da241e22504e80d724ed2eb2a46620616a0a486575a0aeb1d49d016dc4293e1276d61b7d3f7ee2d2e')

prepare() {
	cd "$srcdir/$_pkgname"
	KuboVersion=$(git describe --tags --abbrev=0 --match="v*" --exclude="v*-rc*")
	printf "\033[34;1mPrepare Kubo %s (%s)\n\033[0m" ${KuboVersion} $(git describe --long --tags --abbrev=7 ${KuboVersion} |
		sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')
	git config advice.detachedHead false
	git checkout ${KuboVersion} -f

	if [ $? -ne 0 ]; then
		printf "\033[31;1mTag not found.\n\033[0m"
		exit -1
	fi

	GoVersion=$(grep "${KuboVersion} " ../versions.txt | awk '{ print $2 }')
	S3Version=$(grep "${KuboVersion} " ../versions.txt | awk '{ print $3 }')

	if [ -z "$GoVersion" ] || [ "$GoVersion" == "*" ]; then
		ln -sf $(which go) $srcdir/go
	else
		printf "\033[34;1mInstalling go version: %s\n\033[0m" ${GoVersion}

		GOPATH=$(go env GOPATH)
		GOROOT=$(go env GOROOT)
		go install golang.org/dl/${GoVersion}@latest
		ln -sf $GOPATH/bin/$GoVersion $srcdir/go
		$srcdir/go download
		GOVERSIONROOT=$($srcdir/go env GOROOT)
		GOVERSIONPATH=$($srcdir/go env GOPATH)

		cp $GOROOT/go.env $GOVERSIONROOT/go.env

		export GOROOT=$GOVERSIONROOT
		export GOPATH=$GOVERSIONPATH
	fi

	export GO111MODULE=on

	cd "$srcdir/$_plgname"
	if [ -z "$S3Version" ] || [ "$S3Version" == "*" ]; then
		S3Version=$(git describe --tags --abbrev=0 --match="go-ds-s3-plugin/${KuboVersion}")
	fi
	S3VersionHash=$(git rev-list -n 1 ${S3Version})
	printf "\033[34;1mPrepare go-ds-s3 plugin %s (%s)\n\033[0m" ${S3Version} $(git describe --long --tags --abbrev=7 ${S3Version} |
		sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')
	git config advice.detachedHead false
	git checkout ${S3Version} -f

	cd "$srcdir/$_pkgname"
	$srcdir/go get github.com/ipfs/go-ds-s3/plugin@${S3VersionHash}
	echo -en "\ns3ds github.com/ipfs/go-ds-s3/plugin 0" >> plugin/loader/preload_list

	printf "Set go version and kubo version\n"
	sed -i "s\GOCC ?= go\GOCC ?= ${srcdir}/go\g" Rules.mk
	sed -Ei "s/const CurrentVersionNumber = \"(.*)\"/const CurrentVersionNumber = \"\1-s3\"/g" version.go
}

pkgver() {
	cd "$srcdir/$_pkgname"
	KuboVersion=$(git describe --tags --abbrev=0 --match="v*" --exclude="v*-rc*")
	git describe --long --tags --abbrev=7 ${KuboVersion} |
		sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
	cd "$srcdir/$_pkgname"
	printf "\033[34;1mBuild Kubo\n\033[0m"
	make build || true #first build attempt will probably fail
	
	printf "Fetch dependencies\n"
	$srcdir/go mod tidy

	printf "\033[34;1mBuild Kubo with S3 Plugin\n\033[0m"
	make build

	if [ $? -ne 0 ]; then
		printf "\033[31;1mBuild failed.\n\033[0m"
		exit -1
	fi
}

check() {
	cd "$srcdir/$_pkgname"
	printf "\033[0;35mIPFS Version: $(cmd/ipfs/ipfs version)\n\033[0m"

	if [ $? -ne 0 ]; then
		printf "\033[31;1mCheck failed.\n\033[0m"
		exit -1
	fi
}

package() {
	cd "$srcdir"
	mkdir -p $pkgdir/usr/bin
	cp "${srcdir}/$_pkgname/cmd/ipfs/ipfs" "${pkgdir}/usr/bin/ipfs"
	mkdir -p $pkgdir/usr/lib/systemd/system
	cp "${srcdir}/ipfs.service" "${pkgdir}/usr/lib/systemd/system/ipfs.service"
	printf "\033[36;1mBuild to: $pkgdir/usr/bin/ipfs\n\033[0m"
}