macos catalina, compile openvpn 2.5.2 staticly

Home   »   macos catalina, compile openvpn 2.5.2 staticly

#!/bin/zsh

export OPENVPN_COMPILE_PATH=$HOME/source
if [[ -d $OPENVPN_COMPILE_PATH ]] ; then
    rm -rf $OPENVPN_COMPILE_PATH
fi
mkdir -p $OPENVPN_COMPILE_PATH

export OPENVPN_OUTPUT_PATH=$HOME/openvpn
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


#### 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/

Leave a Reply

Your email address will not be published. Required fields are marked *