diff --git a/install.sh b/install.sh index 17c6d4b..34b030a 100644 --- a/install.sh +++ b/install.sh @@ -1,37 +1,46 @@ #!/bin/bash -INSTALL_DIR="/usr/local/bin" +ARCHITECTURES=("linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64" "windows/amd64") PROJECT_NAME=$(basename "$(pwd)") -BASE_URL="https://git.nixc.us/colin/Oculus/raw/branch/main/dist" -# Supported architectures -ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7" "darwin/amd64" "darwin/arm64") - -OS="$(uname -s | tr '[:upper:]' '[:lower:]')" -ARCH="$(uname -m)" - -case $ARCH in - x86_64) ARCH="amd64" ;; - arm64 | aarch64) ARCH="arm64" ;; - arm*) ARCH="arm/v7" ;; - *) echo "Unsupported architecture: $ARCH"; exit 1 ;; -esac - -COMPONENTS=("filter" "api" "main") - -for COMPONENT in "${COMPONENTS[@]}"; do - BINARY_NAME="${PROJECT_NAME}_${COMPONENT}" - BINARY_URL="${BASE_URL}/${PROJECT_NAME}_${OS}_${ARCH}_${COMPONENT}" - echo "Downloading and installing $BINARY_NAME from $BINARY_URL..." - - # Check if we have write permission to the install directory - if [ -w "${INSTALL_DIR}" ]; then - curl -sSL "$BINARY_URL" -o "${INSTALL_DIR}/${BINARY_NAME}" - chmod +x "${INSTALL_DIR}/${BINARY_NAME}" - else - sudo curl -sSL "$BINARY_URL" -o "${INSTALL_DIR}/${BINARY_NAME}" - sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}" +prepare_build() { + mkdir -p dist build_logs + if [ ! -f go.mod ]; then + go mod init "$PROJECT_NAME" fi + go mod tidy +} - echo "Installed $BINARY_NAME to $INSTALL_DIR" -done +build_binary() { + local os=$1 + local arch=$2 + local binary_name=$3 + local output="dist/${binary_name}_${os}_${arch}" + env GOOS=$os GOARCH=$arch go build -o $output ./${binary_name}.go &> "build_logs/${binary_name}_${os}_${arch}.log" + if [ $? -ne 0 ]; then + echo "Build failed for $os/$arch" >> "build_logs/error.log" + else { + echo "Build succeeded for $os/$arch" + fi + if [ "$os" == "linux" ]; then + env GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o "${output}_static" ./${binary_name}.go &> "build_logs/${binary_name}_${os}_${arch}_static.log" + if [ $? -ne 0 ]; then + echo "Static build failed for $os/$arch" >> "build_logs/error.log" + else + echo "Static build succeeded for $os/$arch" + fi + } +} + +main() { + prepare_build + for arch in "${ARCHITECTURES[@]}"; do + IFS="/" read -r os arch <<< "$arch" + build_binary $os $arch "oculus_api" + build_binary $os $arch "oculus_filter" + build_binary $os $arch "oculus_main" + done + echo "Build process completed." +} + +main