summaryrefslogtreecommitdiff
path: root/pkg/windows/openvpn-build.sh
blob: 3f470f55b701fdb3b1333bf21437ed238ab23865 (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
#!/bin/bash

# render openvpn prepared for installer
# ================================================
#
# requires
#  - a linux host with mingw installed
#  - a rw directory mounted to /var/build
#  returns nonzero exit code when failed
#
# clone openvpn-build repository
# runs cross-compile build
# - downloads openvpn dependencies
# - compiles
# copy files to executables so they can be installed
# cleans up (remove read-write copy)

# the location where the openvpn binaries are placed
absolute_executable_path=/var/build/executables
temporary_build_path=/var/build/openvpn

# cleanup the temporary build path for subsequent executes
function cleanup() {
  rm -r ${temporary_build_path} 2>/dev/null
}
# build openvpn source
function buildSource() {
  pushd ${temporary_build_path}/openvpn-build/generic
  CHOST=i686-w64-mingw32 \
  CBUILD=i686-pc-linux-gnu \
  ./build \
  || die 'build openvpn from source failed'
  cp -r image/openvpn ${absolute_executable_path}/openvpn
  popd
}
# fetch tap-windows.exe as defined in the openvpn vars
function fetchTapWindows() {
  pushd ${temporary_build_path}/openvpn-build
  source windows-nsis/build-complete.vars
  wget ${TAP_WINDOWS_INSTALLER_URL} -O ${absolute_executable_path}/openvpn/tap-windows.exe || die 'tap-windows.exe could not be fetched'
  popd
}
# prepare read-write copy
function prepareBuildPath() {
  cleanup
  mkdir -p ${temporary_build_path}
  pushd ${temporary_build_path}
  git clone https://github.com/OpenVPN/openvpn-build || die 'openvpn-build could not be cloned'
  popd
}
# display failure message and emit non-zero exit code
function die() {
  echo "die:" $@
  exit 1
}
function main() {
  prepareBuildPath
  buildSource
  fetchTapWindows
  cleanup
}
main $@