Skip to content

Instantly share code, notes, and snippets.

@hectorddmx
Last active June 28, 2021 20:44
Show Gist options
  • Save hectorddmx/fab1a1690ab7b80b4acac617cb5be403 to your computer and use it in GitHub Desktop.
Save hectorddmx/fab1a1690ab7b80b4acac617cb5be403 to your computer and use it in GitHub Desktop.
macos catalina, compile openvpn 2.5.2 staticly
#!/bin/zsh
# https://gist.github.com/lecksfrawen/fab1a1690ab7b80b4acac617cb5be403
export OTHER_CODE_SIGN_FLAGS=--options=runtime
export OPENVPN_COMPILE_PATH=$HOME/openvpn_source
# Uncomment this if you'd like to clean up the folders before compiling
if [[ -d $OPENVPN_COMPILE_PATH ]] ; then
rm -rf $OPENVPN_COMPILE_PATH
fi
mkdir -p $OPENVPN_COMPILE_PATH
export OPENVPN_OUTPUT_PATH=$HOME/openvpn_build
# Uncomment this if you'd like to clean up the folders before compiling
if [[ -d $OPENVPN_OUTPUT_PATH ]] ; then
rm -rf $OPENVPN_OUTPUT_PATH
fi
mkdir -p $OPENVPN_OUTPUT_PATH
_install_homebrew_if_not_present() {
echo "Checking for homebrew installation"
if type brew >/dev/null 2>&1; then
echo "Homebrew already installed!"
echo "Updating homebrew..."
brew update
# echo "Updating homebrew packages"
# brew upgrade
else
echo "Homebrew not found. Installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
_install_compilation_tools() {
brew install autoconf automake libtool pkg-config
brew upgrade autoconf automake libtool pkg-config
}
_compile_ssl() {
cd $OPENVPN_COMPILE_PATH
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -xzvf openssl-1.1.1k.tar.gz
cd openssl-1.1.1k
autoreconf -i -v -f
# Staticly linked
./config -static -no-shared --prefix=$OPENVPN_OUTPUT_PATH
make -j4
make install
}
_compile_lzo() {
cd $OPENVPN_COMPILE_PATH
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz
tar -xzvf lzo-2.10.tar.gz
cd lzo-2.10
# Staticly linked
./configure --prefix=$OPENVPN_OUTPUT_PATH --enable-static
make -j4
make install
}
_compile_openvpn() {
cd $OPENVPN_COMPILE_PATH
wget https://swupdate.openvpn.org/community/releases/openvpn-2.5.2.tar.gz
tar -xzvf openvpn-2.5.2.tar.gz
cd openvpn-2.5.2
autoreconf -i -v -f
export LDFLAGS="-L$OPENVPN_OUTPUT_PATH/lib"
export CPPFLAGS="-I$OPENVPN_OUTPUT_PATH/include"
# Staticly linked
./configure \
--prefix=$OPENVPN_OUTPUT_PATH \
--enable-static \
--disable-shared \
--disable-debug \
--disable-plugins \
OPENSSL_SSL_LIBS="-L$OPENVPN_OUTPUT_PATH/lib -lssl" \
OPENSSL_SSL_CFLAGS="-I$OPENVPN_OUTPUT_PATH/include" \
OPENSSL_CRYPTO_LIBS="-L$OPENVPN_OUTPUT_PATH/lib -lcrypto" \
OPENSSL_CRYPTO_CFLAGS="-I$OPENVPN_OUTPUT_PATH/include" \
LZO_CFLAGS="-I$OPENVPN_OUTPUT_PATH/include" \
LZO_LIBS="-L$OPENVPN_OUTPUT_PATH/lib -llzo2"
make LIBS="-all-static" -j4
make install
}
# So we have git
xcode-select --install
_install_homebrew_if_not_present
_install_compilation_tools
# We compile everything step by step till we get
_compile_ssl
_compile_lzo
_compile_openvpn
# After this, we can compile this in either arm64 or intel macs and then use lipo to merge the two executables
# lipo \
# -create \
# "path/to/intel/openvpn" \
# "path/to/arm64/openvpn" \
# -output "openvpn"
#### Sources:
# OpenVPN guides
# https://www.reddit.com/r/recalbox/comments/d10176/adding_openvpn_to_recalbox_60dragonblaze/
# https://gist.github.com/Anubisss/afea82b97058e418e8030ee35e40f54f
# https://www.programmersought.com/article/30631492434/
# OpenSSL guides
# https://mac-dev-env.patrickbougie.com/openssl/
@hectorddmx
Copy link
Author

You should be able to just use the openvpn executable
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment