summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 07b66647372fdbb0d4b6f014debde707c4a3015f (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
 # Maintainer: Moses Narrow <moe_narrow@use.startmail.com>
# Maintainer: Rudi [KittyCash] <rudi@skycoinmail.com>
_projectname=skycoin
pkgname=skywire
_pkgname=${pkgname}
_githuborg=${_projectname}
pkgdesc="Skywire Mainnet Node implementation. Skycoin.com"
_pkggopath="github.com/${_githuborg}/${_pkgname}"
pkgver=0.4.0 #manually verioning because git describe isnt reflecting the version correctly
#pkgver='autogenerated'
pkgrel=1
#pkgrel=1
arch=( 'i686' 'x86_64' 'aarch64' 'armv8' 'armv7' 'armv7l' 'armv7h' 'armv6h' 'armhf' 'armel' 'arm' )
url="https://${_pkggopath}"
license=()
makedepends=('git' 'go' 'musl' 'kernel-headers-musl') #disable signature check pending fixes#  'skycoin-keyring')
install=skywire.install
_scripts=${_pkgname}-scripts
#scripts need at least this commit to work if current build to develop fails
#source=("git+${url}.git#commit=d156980280fdb2ddfc8765ff77cdd55c0b7e9d9c"
source=("git+${url}.git" ##branch=${BRANCH:-develop}"
"${_scripts}.tar.gz"  )
#'PKGBUILD.sig' #disable signature checking for now
#'PKGBUILD')
sha256sums=('SKIP'
            '2994b9816389300da84de6880aa531a5eedc4ad2d4da693ee371d0f61ff8a38b')
#            'SKIP'
#            'SKIP')
#validpgpkeys=('DE08F924EEE93832DABC642CA8DC761B1C0C0CFC')  # Moses Narrow <moe_narrow@use.startmail.com>
#'98F934F04F9334B81DFA3398913BBD5206B19620') #iketheadore skycoin <luxairlake@protonmail.com>

#tar -czvf skywire-scripts.tar.gz skywire-scripts
#updpkgsums

#pkgver() {
#cd "${srcdir}/${_pkgname}"
#local _version=$(git describe --abbrev=0 | tr --delete v)
#local _version=${_version//-/_}
#local _date=$(git log -1 --format="%cd" --date=short | sed s/-//g)
#local _count=$(git rev-list --count HEAD)
#local _commit=$(git rev-parse --short HEAD)
#echo "${_version}_${_date}.${_count}_${_commit}_${BRANCH:-develop}"
#}
#BUILD_OPTS=
prepare() {
#verify PKGBUILD signature
#	gpg --verify ${srcdir}/PKGBUILD.sig ${srcdir}/PKGBUILD   #disabled the signature check

# https://wiki.archlinux.org/index.php/Go_package_guidelines
mkdir -p ${srcdir}/go/src/github.com/${_githuborg}/ ${srcdir}/go/bin ${srcdir}/go/apps
ln -rTsf ${srcdir}/${_pkgname} ${srcdir}/go/src/${_pkggopath}
cd ${srcdir}/go/src/${_pkggopath}/
#echo "
#version:
#	echo "${BUILD_OPTS}"
#" >> Makefile
#BUILD_OPTS=$(make version)
}

build() {
export GOPATH=${srcdir}/go
export GOBIN=${GOPATH}/bin
export _GOAPPS=${GOPATH}/apps
export GOOS=linux
export CGO_ENABLED=1  #default anyways
#use musl-gcc for static compilation
export CC=musl-gcc

#build the golang webserver binary for hosting local package repo
_msg2 "building skycache binary"
cd ${srcdir}/${_scripts}/skycache
go build -trimpath --ldflags '-s -w -linkmode external -extldflags "-static" -buildid=' -o $GOBIN/ skycache.go

#create the skywire binaries
cd ${srcdir}/go/src/${_pkggopath}
_cmddir=${srcdir}/go/src/${_pkggopath}/cmd
#static compilation with 'musl' avoids glibc runtime deps
#which cause binary to fail if correct glibc / libc6 is not found on the system
_buildbins skychat $_GOAPPS apps/
_buildbins skysocks $_GOAPPS apps/
_buildbins skysocks-client $_GOAPPS apps/
_buildbins vpn-client $_GOAPPS apps/
_buildbins vpn-server $_GOAPPS apps/
_buildbins skywire-visor $GOBIN
_buildbins skywire-cli $GOBIN
_buildbins setup-node $GOBIN
#binary transparency
cd $GOBIN
_msg2 'binary sha256sums'
sha256sum $(ls)
cd $_GOAPPS
sha256sum $(ls)
}

#I had to speed up the build for testing but there's a risk of using old binaries.
#will change this when the commit for the build tracks a branch
_buildbins() {
_GOHERE=$2
_binpath=$3
_binname=$1
_msg2 "building ${_binname} binary"
if [[ ! -f ${_GOHERE}/${_binname} ]] ; then
	cd ${_cmddir}/${_binpath}${_binname}
  go build -trimpath --ldflags="" --ldflags '-s -w -linkmode external -extldflags "-static" -buildid=' -o $_GOHERE/ .
fi
}


package() {
  _msg2 'creating dirs'
#create directory trees or the visor might make them with weird permissions
_skydir="opt/skywire"
_skyapps="${_skydir}/apps"
_skyscripts="${_skydir}/scripts"
_systemddir="etc/systemd/system"
_skybin="${_skydir}/bin"
mkdir -p ${pkgdir}/usr/bin
mkdir -p ${pkgdir}/${_skydir}/bin
mkdir -p ${pkgdir}/${_skydir}/apps
mkdir -p ${pkgdir}/${_skydir}/ssl
mkdir -p ${pkgdir}/${_skydir}/local
mkdir -p ${pkgdir}/${_skydir}/dmsgpty
mkdir -p ${pkgdir}/${_skydir}/${_pkgname}
mkdir -p ${pkgdir}/${_skydir}/${_pkgname}-save
mkdir -p ${pkgdir}/${_skydir}/transport_logs
mkdir -p ${pkgdir}/${_skydir}/skycache
mkdir -p ${pkgdir}/${_skydir}/hypervisorkey
mkdir -p ${pkgdir}/${_skydir}/scripts

_msg2 'installing binaries'
_skywirebins=$( ls ${srcdir}/go/bin )
for i in ${_skywirebins}; do
  _install2 ${srcdir}/go/bin/${i} ${_skybin}
done
_msg2 'installing apps'
_skywireapps=$( ls ${srcdir}/go/apps )
for i in ${_skywireapps}; do
  _install2 ${srcdir}/go/apps/${i} ${_skyapps}
done
_msg2 'installing scripts'
_skywirescripts=$( ls ${srcdir}/${_scripts}/${_pkgname} )
for i in ${_skywirescripts}; do
  _install2 ${srcdir}/${_scripts}/${_pkgname}/${i} ${_skyscripts}
done
#the main scripts get installed above, the following are satellite-package or haveto do with the tls config - WIP
install -Dm755  ${srcdir}/${_scripts}/skywire-save/${_pkgname}-save.PKGBUILD  ${pkgdir}/${_skydir}/${_pkgname}-save/PKGBUILD
install -Dm755 ${srcdir}/${_scripts}/skywire-save/${_pkgname}-save.install ${pkgdir}/${_skydir}/${_pkgname}-save/${_pkgname}-save.install
install -Dm644 ${srcdir}/${_scripts}/skywire-save/${_pkgname}-save.txt ${pkgdir}/${_skydir}/${_pkgname}-save/${_pkgname}-save.install

#install the satellite PKGBUILD for distributing the hypervisor key and it's script - works with skycache to share the packages
install -Dm755  ${srcdir}/${_scripts}/hypervisorkey/hypervisorkey.PKGBUILD  ${pkgdir}/${_skydir}/hypervisorkey/PKGBUILD
install -Dm755 ${srcdir}/${_scripts}/hypervisorkey/hypervisorkey.install ${pkgdir}/${_skydir}/hypervisorkey/hypervisorkey.install
install -Dm755 ${srcdir}/${_scripts}/hypervisorkey/hypervisorkey-autoconfig.sh ${pkgdir}/${_skydir}/hypervisorkey/hypervisorkey-autoconfig.sh

#rename visor to skywire - matche the skycoin / skycoin-cli of the skycoin wallet
[[ -f ${pkgdir}/usr/bin/${_pkgname}-visor ]] && mv ${pkgdir}/usr/bin/${_pkgname}-visor ${pkgdir}/usr/bin/${_pkgname}

#install the system.d services (from the source)
#install -Dm644 ${srcdir}/go/src/${_pkggopath}/init/${_pkgname}-hypervisor.service ${pkgdir}/usr/lib/systemd/system/${_pkgname}-hypervisor.service
#install -Dm644 ${srcdir}/go/src/${_pkggopath}/init/${_pkgname}-visor.service ${pkgdir}/usr/lib/systemd/system/${_pkgname}-visor.service

#install the patched system.d services
install -Dm644 ${srcdir}/${_scripts}/systemd/${_pkgname}.service ${pkgdir}/${_systemddir}/${_pkgname}.service
install -Dm644 ${srcdir}/${_scripts}/systemd/${_pkgname}-visor.service ${pkgdir}/${_systemddir}/${_pkgname}-visor.service

#install the skycache systemd service
install -Dm644 ${srcdir}/${_scripts}/skycache/skycache.service ${pkgdir}/${_systemddir}/skycache.service

#tls key and certificate generation
#install -Dm755 ${srcdir}/${_pkgname}/static/skywire-manager-src/ssl/generate-1.sh ${pkgdir}/${_skydir}/ssl/generate.sh
install -Dm755 ${srcdir}/${_scripts}/ssl/generate.sh ${pkgdir}/${_skydir}/ssl/generate.sh
ln -rTsf ${pkgdir}/${_skydir}/ssl/generate.sh ${pkgdir}/usr/bin/${_pkgname}-tls-gen
install -Dm644 ${srcdir}/${_pkgname}/static/${_pkgname}-manager-src/ssl/certificate.cnf ${pkgdir}/${_skydir}/ssl/certificate.cnf
}

_install2() {
_binname="${1##*/}"
_binname="${_binname%%.*}"
install -Dm755 ${1} ${pkgdir}/${2}/${_binname}
ln -rTsf ${pkgdir}/${2}/${_binname} ${pkgdir}/usr/bin/${_binname}
chmod +x ${pkgdir}/usr/bin/${_binname}
}

_msg2() {
(( QUIET )) && return
local mesg=$1; shift
printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
}

_msg3() {
(( QUIET )) && return
local mesg=$1; shift
printf "${BLUE}  -->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@"
}