2021-11-30 16:56:24 +04:00
#!/bin/bash
. $( dirname $0 ) /commons.sh
if [ -f .env ] ; then
. .env
fi
RELEASE = 1
OS =
NETWORKEXTENSION =
2022-04-28 14:05:14 +04:00
WORKINGDIR = ` pwd `
2021-11-30 16:56:24 +04:00
helpFunction( ) {
print G "Usage:"
2022-12-12 16:16:12 +04:00
print N " \t $0 <macos|ios|> [-d|--debug] [-n|--networkextension] "
2021-11-30 16:56:24 +04:00
print N ""
print N "By default, the project is compiled in release mode. Use -d or --debug for a debug build."
print N "Use -n or --networkextension to force the network-extension component for MacOS too."
print N ""
print N "If MVPN_IOS_ADJUST_TOKEN env is found, this will be used at compilation time."
print N ""
print G "Config variables:"
print N "\tQT_MACOS_BIN=</path/of/the/qt/bin/folder/for/macos>"
print N "\tQT_IOS_BIN=</path/of/the/qt/bin/folder/for/ios>"
print N ""
exit 0
}
print N "This script compiles AmneziaVPN for MacOS/iOS"
print N ""
while [ [ $# -gt 0 ] ] ; do
key = " $1 "
case $key in
-d | --debug)
RELEASE =
shift
; ;
-n | --networkextension)
NETWORKEXTENSION = 1
shift
; ;
-h | --help)
helpFunction
; ;
*)
if [ [ " $OS " ] ] ; then
helpFunction
fi
OS = $1
shift
; ;
esac
done
fetch( ) {
if command -v "wget" & >/dev/null; then
wget -nc -O " $2 " " $1 "
return
fi
if command -v "curl" & >/dev/null; then
curl " $1 " -o " $2 " -s -L
return
fi
2022-04-29 18:02:38 +04:00
killProcess "You must have 'wget' or 'curl' installed."
2021-11-30 16:56:24 +04:00
}
sha256( ) {
if command -v "sha256sum" & >/dev/null; then
sha256sum " $1 "
return 0
fi
if command -v "openssl" & >/dev/null; then
openssl dgst -sha256 " $1 "
return 0
fi
2022-04-29 18:02:38 +04:00
killProcess "You must have 'sha256sum' or 'openssl' installed."
2021-11-30 16:56:24 +04:00
}
if [ [ " $OS " != "macos" ] ] && [ [ " $OS " != "ios" ] ] && [ [ " $OS " != "macostest" ] ] ; then
helpFunction
fi
if [ [ " $OS " = = "ios" ] ] ; then
# Network-extension is the default for IOS
NETWORKEXTENSION = 1
fi
if ! [ -d "ios" ] || ! [ -d "macos" ] ; then
2022-04-29 18:02:38 +04:00
killProcess "This script must be executed at the root of the repository."
2021-11-30 16:56:24 +04:00
fi
QMAKE = qmake
if [ " $OS " = "macos" ] && ! [ " $QT_MACOS_BIN " = "" ] ; then
QMAKE = $QT_MACOS_BIN /qmake
elif [ " $OS " = "macostest" ] && ! [ " $QT_MACOS_BIN " = "" ] ; then
QMAKE = $QT_MACOS_BIN /qmake
elif [ " $OS " = "ios" ] && ! [ " $QT_IOS_BIN " = "" ] ; then
QMAKE = $QT_IOS_BIN /qmake
fi
2022-04-29 18:02:38 +04:00
$QMAKE -v & >/dev/null || killProcess "qmake doesn't exist or it fails"
2021-11-30 16:56:24 +04:00
2022-04-28 14:05:14 +04:00
print Y "Retrieve the wireguard-go version... "
if [ " $OS " = "macos" ] ; then
( cd macos/gobridge && go list -m golang.zx2c4.com/wireguard | sed -n 's/.*v\([0-9.]*\).*/#define WIREGUARD_GO_VERSION "\1"/p' ) > macos/gobridge/wireguard-go-version.h
elif [ " $OS " = "ios" ] ; then
if [ ! -f 3rd/wireguard-apple/Sources/WireGuardKitGo/wireguard-go-version.h ] ; then
print Y "Creating wireguard-go-version.h file"
touch 3rd/wireguard-apple/Sources/WireGuardKitGo/wireguard-go-version.h
cat <<EOF >> $WORKINGDIR /3rd/wireguard-apple/Sources/WireGuardKitGo/wireguard-go-version.h
#define WIREGUARD_GO_VERSION "0.0.0"
EOF
fi
( cd 3rd/wireguard-apple/Sources/WireGuardKitGo && go list -m golang.zx2c4.com/wireguard | sed -n 's/.*v\([0-9.]*\).*/#define WIREGUARD_GO_VERSION "\1"/p' ) > 3rd/wireguard-apple/Sources/WireGuardKitGo/wireguard-go-version.h
fi
2021-11-30 16:56:24 +04:00
print G "done."
printn Y "Cleaning the existing project... "
2022-04-29 18:02:38 +04:00
rm -rf AmneziaVPN.xcodeproj/ || killProcess "Failed to remove things"
2021-11-30 16:56:24 +04:00
print G "done."
printn Y "Extract the project version... "
SHORTVERSION = $( cat version.pri | grep VERSION | grep defined | cut -d= -f2 | tr -d \ )
2021-12-23 15:38:02 +04:00
FULLVERSION = $( cat versionfull.pri | grep BUILDVERSION | grep defined | cut -d= -f2 | tr -d \ )
2021-11-30 16:56:24 +04:00
print G " $SHORTVERSION - $FULLVERSION "
MACOS_FLAGS = "
QTPLUGIN += qsvg
CONFIG-= static
CONFIG += balrog
"
MACOSTEST_FLAGS = "
QTPLUGIN += qsvg
CONFIG-= static
CONFIG += DUMMY
"
IOS_FLAGS = "
Q_OS_IOS = 1
"
2021-12-01 20:02:54 +04:00
printn Y "Mode: "
if [ [ " $RELEASE " ] ] ; then
print G "release"
MODE = "CONFIG-=debug CONFIG+=release CONFIG-=debug_and_release"
else
print G "debug"
MODE = "CONFIG+=debug CONFIG-=release CONFIG-=debug_and_release"
fi
2021-11-30 16:56:24 +04:00
OSRUBY = $OS
printn Y "OS: "
print G " $OS "
if [ " $OS " = "macos" ] ; then
PLATFORM = $MACOS_FLAGS
elif [ " $OS " = "macostest" ] ; then
OSRUBY = macos
PLATFORM = $MACOSTEST_FLAGS
elif [ " $OS " = "ios" ] ; then
PLATFORM = $IOS_FLAGS
else
2022-04-29 18:02:38 +04:00
killProcess "Why are we here?"
2021-11-30 16:56:24 +04:00
fi
VPNMODE =
printn Y "VPN mode: "
if [ [ " $NETWORKEXTENSION " ] ] ; then
print G network-extension
VPNMODE = "CONFIG+=networkextension"
else
print G daemon
fi
printn Y "Web-Extension: "
WEMODE =
if [ " $OS " = "macos" ] ; then
print G web-extension
WEMODE = "CONFIG+=webextension"
else
print G none
fi
2021-12-08 15:55:36 +04:00
if [ " $OS " = "ios" ] ; then
print Y "Prepare to build OpenVPNAdapter..."
prepare_to_build_vpn
print Y "Building OpenVPNAdapter..."
compile_openvpn_adapter
else
print Y "No OpenVPNAdapter will be built"
2021-12-21 23:17:22 +04:00
fi
if [ " $OS " = "ios" ] ; then
print Y "Prepare to build ShadowSocks..."
prepare_to_build_ss
print Y "Patching the ShadowSocks project..."
patch_ss
ruby ../../scripts/ss_project_patcher.rb "ShadowSocks.xcodeproj"
print G "done."
print Y "Building ShadowSocks Framework..."
compile_ss_frameworks
else
print Y "No ShadowSocket Library will be built"
fi
2021-12-08 15:55:36 +04:00
2021-12-31 10:57:58 +04:00
if [ " $OS " = "ios" ] ; then
print Y "Prepare to build CocoaAsyncSocket..."
prepare_to_build_cas
print Y "Building CocoaAsyncSocket Framework..."
compile_cocoa_async_socket
else
print Y "No CocoaAsyncSocket will be built"
fi
if [ " $OS " = "ios" ] ; then
print Y "Prepare to build Tun2Socks..."
print Y "Building Tun2Socks Framework..."
compile_tun2socks
else
print Y "No Tun2Socks will be built"
fi
2022-12-12 16:16:12 +04:00
print Y "Creating the Xcode project via qmake..."
2021-11-30 16:56:24 +04:00
$QMAKE \
VERSION = $SHORTVERSION \
BUILD_ID = $FULLVERSION \
-spec macx-xcode \
$MODE \
$VPNMODE \
$WEMODE \
$PLATFORM \
2022-04-29 18:02:38 +04:00
./client.pro || killProcess "Compilation failed"
2021-11-30 16:56:24 +04:00
print Y "Patching the xcode project..."
2022-12-12 16:16:12 +04:00
ruby scripts/xcode_patcher.rb "AmneziaVPN.xcodeproj" " $SHORTVERSION " " $FULLVERSION " " $OSRUBY " " $NETWORKEXTENSION " || killProcess "Failed to merge xcode with wireguard"
2021-11-30 16:56:24 +04:00
print G "done."
2021-12-21 23:17:22 +04:00
if command -v "sed" & >/dev/null; then
sed -i '' '/<key>BuildSystemType<\/key>/d' AmneziaVPN.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
sed -i '' '/<string>Original<\/string>/d' AmneziaVPN.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
fi
2021-11-30 16:56:24 +04:00
print G "All done!"
2022-12-12 16:16:12 +04:00
print Y "Opening project in Xcode..."
open AmneziaVPN.xcodeproj