proxywoman/build.sh

211 lines
6.7 KiB
Bash
Raw Normal View History

#!/bin/sh
2019-12-07 19:25:39 +00:00
2020-06-09 21:39:37 +00:00
#
# Basic Prep...
#
2020-06-08 23:34:55 +00:00
TIME_START=$(date +%s)
2020-06-09 20:33:32 +00:00
fcomplete() {
TIME_END=$(date +%s)
TIME_TAKEN=$(( TIME_END - TIME_START ))
echo "Done (${TIME_TAKEN}s)."
exit 0
}
# Ensure the user is in the correct directory (the directory containing this script.)
if [ "$(pwd)" != "${0%/*}" ]; then
cd "${0%/*}" || exit
fi
. ./version.properties
2020-06-09 21:39:37 +00:00
#
# Print Banner
#
printf " _____ \n";
printf " | __ \ \n";
printf " | |__) | __ _____ ___ ___ _____ _ __ ___ __ _ _ __ \n";
printf " | ___/ '__/ _ \ \/ / | | \ \ /\ / / _ \| '_ \` _ \ / _\` | '_ \ \n";
printf " | | | | | (_) > <| |_| |\ V V / (_) | | | | | | (_| | | | |\n";
printf " |_| |_| \___/_/\_\\__, | \_/\_/ \___/|_| |_| |_|\__,_|_| |_|\n";
printf " __/ | \n";
printf " |___/ \n";
printf "\n";
printf "v%s -- a Postwoman project - https://postwoman.io/\n" "$VERSION_NAME";
printf "Built by NBTX (Apollo Software) - https://apollosoftware.xyz/\n";
printf "\n";
printf "\n";
#
# Start Build Script
#
if [ $# -lt 1 ]; then
printf "Usage: %s <darwin|linux|windows> [<server|desktop>] - Builds Proxywoman for the given platform.\n" "$0"
printf "Usage: %s clean - Cleans the out/ directory.\n" "$0"
exit 3
fi
2020-06-09 20:33:32 +00:00
#
# COMMAND: clean
#
if [ "$1" = "clean" ]; then
echo "Cleaning build directory..."
rm -rf ./out/*
fcomplete
exit 0
fi
#
# COMMAND: build
#
2019-12-07 19:25:39 +00:00
# Collect parameters.
PLATFORM="$1"
2019-12-19 13:28:20 +00:00
BUILD_TYPE="$2"
# Ensure that a valid OS/platform has been selected.
if [ "$PLATFORM" != "darwin" ] && [ "$PLATFORM" != "linux" ] && [ "$PLATFORM" != "windows" ]; then
echo "Invalid platform selected ($PLATFORM). It must be one of <darwin|linux|windows>."
exit 4
fi
# Ensure that a valid build type has been selected.
if [ $# -lt 2 ]; then
BUILD_TYPE="desktop"
elif [ "$BUILD_TYPE" != "desktop" ] && [ "$BUILD_TYPE" != "server" ]; then
echo "Invalid build type selected ($BUILD_TYPE). It must be one of <server|desktop>."
exit 5
fi
2020-06-08 23:34:55 +00:00
2020-06-09 20:33:32 +00:00
# We're running a build.
2020-06-08 23:34:55 +00:00
echo "Building Proxywoman $BUILD_TYPE v$VERSION_NAME (build $VERSION_CODE) for $PLATFORM"
echo "Developed by @NBTX (Apollo Software)"
echo ""
echo ""
2019-12-19 13:28:20 +00:00
# Ensure output directory exists.
[ -d "out/" ] || mkdir "out/"
[ -d "out/$PLATFORM-$BUILD_TYPE" ] && rm -r "out/$PLATFORM-$BUILD_TYPE"
mkdir "out/$PLATFORM-$BUILD_TYPE"
OUTPUT_DIR="out/$PLATFORM-$BUILD_TYPE"
2020-06-08 23:34:55 +00:00
2019-12-19 13:28:20 +00:00
# Handle special build: server
if [ "$BUILD_TYPE" = "server" ]; then
2020-06-08 23:34:55 +00:00
echo "Executing go build..."
if [ "$PLATFORM" = "windows" ]; then
2020-06-08 23:34:55 +00:00
GOOS="$PLATFORM" go build -ldflags "-X main.VersionName=$VERSION_NAME -X main.VersionCode=$VERSION_CODE" -o "$OUTPUT_DIR/proxywoman-server.exe" server/server.go
2020-06-09 20:33:32 +00:00
mv "$OUTPUT_DIR/proxywoman-server.exe" "$OUTPUT_DIR/proxywoman-server-windows-v${VERSION_NAME}.exe"
# echo "Compressing release binary..."
# WORKING_DIR=$(pwd)
# cd "$OUTPUT_DIR" || exit 1
# zip -r "proxywoman-server-windows-v${VERSION_NAME}.zip" "proxywoman-server-windows-v${VERSION_NAME}.exe"
# cd "$WORKING_DIR" || exit 1
2019-12-19 13:28:20 +00:00
else
2020-06-08 23:34:55 +00:00
GOOS="$PLATFORM" go build -ldflags "-X main.VersionName=$VERSION_NAME -X main.VersionCode=$VERSION_CODE" -o "$OUTPUT_DIR/proxywoman-server" server/server.go
mv "$OUTPUT_DIR/proxywoman-server" "$OUTPUT_DIR/proxywoman-server-${PLATFORM}-v${VERSION_NAME}"
2020-06-09 20:33:32 +00:00
# echo "Compressing release binary..."
# WORKING_DIR=$(pwd)
# cd "$OUTPUT_DIR" || exit 1
# zip -r "proxywoman-server-${PLATFORM}-v${VERSION_NAME}.zip" "proxywoman-server-${PLATFORM}-v${VERSION_NAME}"
# cd "$WORKING_DIR" || exit 1
2019-12-19 13:28:20 +00:00
fi
exit
fi
2019-12-07 19:25:39 +00:00
2020-06-08 23:34:55 +00:00
2019-12-07 19:25:39 +00:00
# Remove all legacy icons.
[ -f icons/icon_unix.go ] && rm icons/icon_unix.go
[ -f icons/icon_win.go ] && rm icons/icon_win.go
2020-06-08 23:34:55 +00:00
2019-12-07 19:25:39 +00:00
# Build the icon for the appropriate platform.
2020-06-08 23:34:55 +00:00
echo "Generating platform icon..."
if [ "$PLATFORM" = "darwin" ] || [ "$PLATFORM" = "linux" ]; then
2019-12-07 19:25:39 +00:00
cat "icons/icon.png" | go run github.com/cratonica/2goarray Data icon >> icons/icon_unix.go
elif [ "$PLATFORM" = "windows" ]; then
2019-12-07 19:25:39 +00:00
cat "icons/icon.ico" | go run github.com/cratonica/2goarray Data icon >> icons/icon_win.go
else
echo "Unknown platform: $1"
exit 3
fi
2020-06-08 23:34:55 +00:00
# Copy binary assets.
echo "Copying binary assets..."
2019-12-19 13:28:20 +00:00
cp -r "resources/$PLATFORM/." "$OUTPUT_DIR/"
2019-12-07 19:25:39 +00:00
2020-06-08 23:34:55 +00:00
# Inject placeholders into assets.
echo "Injecting placeholders into binary assets..."
find "$OUTPUT_DIR" -type f -print0 | xargs -0 perl -pi -e "s/\\\$VERSION_NAME/$VERSION_NAME/g"
find "$OUTPUT_DIR" -type f -print0 | xargs -0 perl -pi -e "s/\\\$VERSION_CODE/$VERSION_CODE/g"
# Execute platform build.
echo "Executing go build..."
if [ "$PLATFORM" = "darwin" ]; then
2020-06-08 20:50:58 +00:00
mkdir -p "$OUTPUT_DIR/Proxywoman.app/Contents/MacOS"
mkdir -p "$OUTPUT_DIR/Proxywoman.app/Contents/MacOS/icons"
cp icons/icon.png "$OUTPUT_DIR/Proxywoman.app/Contents/MacOS/icons/"
2020-06-08 23:34:55 +00:00
GOOS="darwin" GO111MODULE=on go build -ldflags "-X main.VersionName=$VERSION_NAME -X main.VersionCode=$VERSION_CODE" -o "$OUTPUT_DIR/Proxywoman.app/Contents/MacOS/postwoman-proxy"
2020-06-09 16:52:46 +00:00
# Produce output binaries
2020-06-09 20:33:32 +00:00
mv "$OUTPUT_DIR/Proxywoman.app" "$OUTPUT_DIR/Proxywoman-macOS-v${VERSION_NAME}.app"
2020-06-09 16:52:46 +00:00
# Compressing output binaries
echo "Compressing output binaries"
2020-06-09 20:33:32 +00:00
WORKING_DIR=$(pwd)
2020-06-09 16:52:46 +00:00
cd "$OUTPUT_DIR" || exit 1
2020-06-09 20:33:32 +00:00
zip -r "Proxywoman-macOS-v${VERSION_NAME}.zip" "Proxywoman-macOS-v${VERSION_NAME}.app"
2020-06-09 16:52:46 +00:00
cd "$WORKING_DIR" || exit 1
elif [ "$PLATFORM" = "windows" ]; then
2019-12-18 18:04:25 +00:00
[ -f "rsrc.syso" ] && rm rsrc.syso
go get github.com/akavel/rsrc
2019-12-19 13:28:20 +00:00
rsrc -manifest="$OUTPUT_DIR/postwoman-proxy.manifest" -ico="icons/icon.ico" -o rsrc.syso
2020-06-08 23:34:55 +00:00
GOOS="windows" GO111MODULE=on go build -ldflags "-X main.VersionName=$VERSION_NAME -X main.VersionCode=$VERSION_CODE -H=windowsgui" -o "$OUTPUT_DIR/proxywoman.exe"
2019-12-18 18:04:25 +00:00
2020-06-08 23:34:55 +00:00
mkdir "$OUTPUT_DIR/icons"
2019-12-19 13:28:20 +00:00
cp icons/icon.png "$OUTPUT_DIR/icons/icon.png"
2019-12-18 18:04:25 +00:00
2020-06-08 23:34:55 +00:00
mkdir "$OUTPUT_DIR/data"
2019-12-18 18:04:25 +00:00
2020-06-08 23:34:55 +00:00
rm "$OUTPUT_DIR/postwoman-proxy.manifest"
2019-12-18 18:04:25 +00:00
rm rsrc.syso
2020-06-08 23:34:55 +00:00
mv "$OUTPUT_DIR/proxywoman.exe" "$OUTPUT_DIR/Proxywoman-Windows-v${VERSION_NAME}.exe"
2020-06-09 20:33:32 +00:00
# Compressing output binaries
echo "Compressing output binaries"
# WORKING_DIR=$(pwd)
# cd "$OUTPUT_DIR" || exit 1
# zip -r "Proxywoman-Windows-v${VERSION_NAME}.zip" "Proxywoman-Windows-v${VERSION_NAME}.exe"
# cd "$WORKING_DIR" || exit 1
elif [ "$PLATFORM" = "linux" ]; then
2020-06-09 20:33:32 +00:00
GOOS="linux" GO111MODULE=on go build -ldflags "-X main.VersionName=$VERSION_NAME -X main.VersionCode=$VERSION_CODE" -o "$OUTPUT_DIR/Proxywoman-Linux-v${VERSION_NAME}"
2020-06-08 23:34:55 +00:00
2020-06-09 20:33:32 +00:00
# Compressing output binaries
# echo "Compressing output binaries"
# WORKING_DIR=$(pwd)
# cd "$OUTPUT_DIR" || exit 1
# zip -r "Proxywoman-Linux-v${VERSION_NAME}.zip" "Proxywoman-Linux-v${VERSION_NAME}"
# cd "$WORKING_DIR" || exit 1
fi
2020-06-08 23:34:55 +00:00
echo ""
echo ""
2020-06-09 20:33:32 +00:00
fcomplete