Skip to content
Snippets Groups Projects
build_core.sh 4.97 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/bash
    
    RED='\033[0;31m'
    GREEN='\033[0;32m'
    NC='\033[0m'
    
    function quit {
        echo -e "${RED}Task failed. $1 ${NC}"
        exit 1
    }
    
    function showtitle {
        echo -e "\n\n${GREEN}--- $1 ...${NC}\n"
    }
    
    # -------- install golang ---------------
    showtitle "Installing golang"
    
    
    cyberta's avatar
    cyberta committed
    if [[ "$OSTYPE" == "linux-gnu"* ]]; then
    
    cyberta's avatar
    cyberta committed
            GO_VERSION=go1.17.10.linux-amd64
            EXPECTED_FP=87fc728c9c731e2f74e4a999ef53cf07302d7ed3504b0839027bd9c10edaa3fd
    
    cyberta's avatar
    cyberta committed
    elif [[ "$OSTYPE" == "darwin"* ]]; then
            # Mac OSX
    
    cyberta's avatar
    cyberta committed
            GO_VERSION=go1.17.10.darwin-arm64
            EXPECTED_FP=84979d5985c70cee6f303050a7e811440aad7f304efdf28665b200f096b01945
    
    cyberta's avatar
    cyberta committed
    else
            echo "$OSTYPE is currently not supported."
            exit 1
    fi
    
    
    
    if [[ $(ls -A ${GO_VERSION}.tar.gz) ]]
    then
        echo "Reusing downloaded golang bundle"
    else
        echo "Installing go lang bundle ${GO_VERSION}.tar.gz from https://golang.org/dl/$GO_VERSION.tar.gz"
    
        curl -L -o "${GO_VERSION}.tar.gz" "https://golang.org/dl/${GO_VERSION}.tar.gz"
    
    cyberta's avatar
    cyberta committed
        if [[ "$OSTYPE" == "linux-gnu"* ]]; then
          ACTUAL_FP=`sha256sum $GO_VERSION.tar.gz | cut -d " " -f1`
        else
          ACTUAL_FP=`shasum -a 512256 $GO_VERSION.tar.gz | cut -d " " -f1`
        fi
    
    
        if [[ ! $ACTUAL_FP == $EXPECTED_FP ]]
        then
            quit "Download seems to be corrupted. Cancelling build."
        fi
    fi
    
    if [[ -d ./golang ]]
    then
        if [[ $(ls -A ./golang/*) ]]
        then
            rm -r ./golang/*
        fi
    else
        mkdir ./golang
    fi
    tar -C ./golang -xzf $GO_VERSION.tar.gz || quit "Could not untar $GO_VERSION.tar.gz"
    
    
    # -------- update submodules ---------------
    showtitle "Updating submodules"
    git submodule sync --recursive || quit "git submodule sync --recursive"
    git submodule update --init --recursive || quit "git submodule update --init --recursive"
    
    
    # -------- init environment variables ---------------
    cd ./golang
    export GOPATH=`pwd`
    
    cyberta's avatar
    cyberta committed
    export GO_LANG=`pwd`/go/bin
    
    export GO_COMPILED=`pwd`/bin
    export PATH="${GO_LANG}:${GO_COMPILED}:${PATH}"
    
    cd ..
    
    # -------- init gomobile ---------------
    showtitle "Getting gomobile"
    
    ./golang/go/bin/go install golang.org/x/mobile/cmd/gomobile || quit "./golang/go/bin/go install golang.org/x/mobile/cmd/gomobile"
    
    
    showtitle "initiating gomobile"
    ./golang/bin/gomobile init || quit "./golang/bin/gomobile init"
    
    
    # -------- prepare snowflake ---------------
    showtitle "Checking out snowflake repository"
    cd ./IPtProxy/snowflake
    
    cyberta's avatar
    cyberta committed
    git checkout --force --quiet ead5a960 || quit "Failed to checkout snowflake at commit ead5a960"
    
    git submodule update --init --recursive || quit "Failed to update snowflake submodules"
    cd ..
    
    showtitle "Applying patches to snowflake"
    patch --directory=snowflake --strip=1 < snowflake.patch || quit 
    cd ..
    
    
    cyberta's avatar
    cyberta committed
    showtitle "Applying patch to IPtProxy"
    patch --directory=IPtProxy --strip=1 < IPtProxy.patch || quit
    
    
    # -------- preparing obfsvpn ---------------
    showtitle "Applying patch to obfsvpn"
    patch --directory=obfsvpn --strip=1 < obfsvpn.patch || quit
    
    
    cyberta's avatar
    cyberta committed
    # -------- preparing shapeshifter ---------------
    showtitle "Applying patch to shapeshifter"
    patch --directory=shapeshifter --strip=1 < shapeshifter.patch || quit
    
    
    # -------- preparing vpn-hole ---------------
    showtitle "Applying patch to vpn-hole"
    patch --directory=vpn-hole --strip=1 < vpn-hole.patch || quit
    
    
    cyberta's avatar
    cyberta committed
    
    
    if [[ -d ./lib ]]
    then
        if [[ $(ls -A ./lib/*) ]]
        then
            rm -r ./lib/*
        fi
    else
        mkdir ./lib
    fi
    
    
    
    showtitle "Building Bitmask core as full aar"
    
    gomobile bind -target='android' -o ./lib/bitmaskcore.aar -v org.0xacab/leap/bitmaskcore/shapeshifter org.0xacab/leap/bitmaskcore/obfsvpn/client org.0xacab/leap/bitmaskcore/IPtProxy/IPtProxy.go org.0xacab/leap/vpn-hole
    
    
    showtitle "Building Bitmask web core as full aar including pgpverify"
    
    gomobile bind -target='android' -o ./lib/bitmaskcore_web.aar -v org.0xacab/leap/bitmaskcore/pgpverify org.0xacab/leap/bitmaskcore/shapeshifter org.0xacab/leap/bitmaskcore/obfsvpn/client org.0xacab/leap/bitmaskcore/IPtProxy/IPtProxy.go org.0xacab/leap/vpn-hole
    
    
    showtitle "Building Bitmask core for armv7"
    
    gomobile bind -target='android/arm' -o ./lib/bitmaskcore_arm.aar -v org.0xacab/leap/bitmaskcore/shapeshifter org.0xacab/leap/bitmaskcore/obfsvpn/client org.0xacab/leap/bitmaskcore/IPtProxy/IPtProxy.go org.0xacab/leap/vpn-hole
    
    
    showtitle "Building Bitmask core for x86"
    
    gomobile bind -target='android/386' -o ./lib/bitmaskcore_x86.aar -v org.0xacab/leap/bitmaskcore/shapeshifter org.0xacab/leap/bitmaskcore/obfsvpn/client org.0xacab/leap/bitmaskcore/IPtProxy/IPtProxy.go org.0xacab/leap/vpn-hole
    
    
    showtitle "Building Bitmask core for arm64"
    
    gomobile bind -target='android/arm64' -o ./lib/bitmaskcore_arm64.aar -v org.0xacab/leap/bitmaskcore/shapeshifter org.0xacab/leap/bitmaskcore/obfsvpn/client org.0xacab/leap/bitmaskcore/IPtProxy/IPtProxy.go org.0xacab/leap/vpn-hole
    
    
    showtitle "Building Bitmask core for x86_64"
    
    gomobile bind -target='android/amd64' -o ./lib/bitmaskcore_x86_64.aar -v org.0xacab/leap/bitmaskcore/shapeshifter org.0xacab/leap/bitmaskcore/obfsvpn/client org.0xacab/leap/bitmaskcore/IPtProxy/IPtProxy.go org.0xacab/leap/vpn-hole