build-beta.sh
1 #!/usr/bin/env bash 2 # build-beta.sh 3 # 4 # This script builds the beta version of KeepSync with all features enabled. 5 # 6 # Usage: ./scripts/build-beta.sh [options] 7 # 8 # Options: 9 # --debug Enable debug mode 10 # --race Enable race detector 11 # --help Show this help message 12 # 13 # Example: ./scripts/build-beta.sh --debug 14 15 set -e 16 17 # Default options 18 DEBUG=false 19 RACE=false 20 SHOW_HELP=false 21 22 # Parse options 23 for arg in "$@"; do 24 case $arg in 25 --debug) 26 DEBUG=true 27 shift 28 ;; 29 --race) 30 RACE=true 31 shift 32 ;; 33 --help) 34 SHOW_HELP=true 35 shift 36 ;; 37 *) 38 echo "Unknown option: $arg" 39 exit 1 40 ;; 41 esac 42 done 43 44 # Show help message 45 if [[ "$SHOW_HELP" == "true" ]]; then 46 echo "Usage: $0 [options]" 47 echo "" 48 echo "Options:" 49 echo " --debug Enable debug mode" 50 echo " --race Enable race detector" 51 echo " --help Show this help message" 52 echo "" 53 echo "Example: $0 --debug" 54 exit 0 55 fi 56 57 # Colors for output 58 RED='\033[0;31m' 59 GREEN='\033[0;32m' 60 YELLOW='\033[0;33m' 61 BLUE='\033[0;34m' 62 NC='\033[0m' # No Color 63 64 echo -e "${BLUE}Building beta version of KeepSync...${NC}" 65 66 # Create beta build directory if it doesn't exist 67 mkdir -p ./beta-build 68 69 # Set build options 70 BUILD_OPTS="" 71 if [[ "$DEBUG" == "true" ]]; then 72 BUILD_OPTS="$BUILD_OPTS -tags debug" 73 echo -e "${YELLOW}Debug mode enabled${NC}" 74 fi 75 76 if [[ "$RACE" == "true" ]]; then 77 BUILD_OPTS="$BUILD_OPTS -race" 78 echo -e "${YELLOW}Race detector enabled${NC}" 79 fi 80 81 # Create build configuration 82 echo -e "${BLUE}Creating build configuration...${NC}" 83 cat > ./beta-build/config.json << EOF 84 { 85 "version": "0.8.0-beta", 86 "build_date": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")", 87 "features": { 88 "tpm": true, 89 "quantum_resistant": true, 90 "s3_provider": true, 91 "webdav_provider": true, 92 "sftp_provider": true, 93 "fuse": true, 94 "daemon": true 95 }, 96 "build_options": { 97 "debug": $DEBUG, 98 "race_detector": $RACE, 99 "static_linking": true, 100 "compression": true 101 } 102 } 103 EOF 104 echo -e "${GREEN}Created build configuration: ./beta-build/config.json${NC}" 105 106 # Fix import paths if needed 107 echo -e "${BLUE}Fixing import paths...${NC}" 108 if [[ -f "./scripts/fix-import-paths.sh" ]]; then 109 ./scripts/fix-import-paths.sh 110 echo -e "${GREEN}Import paths fixed${NC}" 111 else 112 echo -e "${YELLOW}Import path fixing script not found. Skipping.${NC}" 113 fi 114 115 # Build the binary 116 echo -e "${BLUE}Building binary...${NC}" 117 echo -e "${YELLOW}Note: This may fail if import paths are not correctly set up.${NC}" 118 echo -e "${YELLOW}If it fails, check the old-code-19547a0 directory for reference.${NC}" 119 120 # First, try to build with the current module path 121 if go build $BUILD_OPTS -o ./beta-build/keepsync-beta ./cmd/keepsync-cli-standalone; then 122 echo -e "${GREEN}Build successful: ./beta-build/keepsync-beta${NC}" 123 else 124 echo -e "${YELLOW}Build failed with default module path. Trying alternative approaches...${NC}" 125 126 # Try to build with the module path from go.mod 127 MODULE_PATH=$(grep "^module" go.mod | awk '{print $2}') 128 if [[ -n "$MODULE_PATH" ]]; then 129 echo -e "${BLUE}Trying to build with module path from go.mod: $MODULE_PATH${NC}" 130 if go build $BUILD_OPTS -o ./beta-build/keepsync-beta ./cmd/keepsync-cli-standalone; then 131 echo -e "${GREEN}Build successful with module path from go.mod: ./beta-build/keepsync-beta${NC}" 132 else 133 echo -e "${RED}Build failed with module path from go.mod.${NC}" 134 echo -e "${YELLOW}Please check the import paths and try again.${NC}" 135 echo -e "${YELLOW}You can use the old-code-19547a0 directory as reference.${NC}" 136 exit 1 137 fi 138 else 139 echo -e "${RED}Could not determine module path from go.mod.${NC}" 140 echo -e "${YELLOW}Please check the import paths and try again.${NC}" 141 echo -e "${YELLOW}You can use the old-code-19547a0 directory as reference.${NC}" 142 exit 1 143 fi 144 fi 145 146 # Verify the binary 147 echo -e "${BLUE}Verifying binary...${NC}" 148 if [[ -f "./beta-build/keepsync-beta" ]]; then 149 chmod +x ./beta-build/keepsync-beta 150 if ./beta-build/keepsync-beta version 2>/dev/null; then 151 echo -e "${GREEN}Binary verification successful${NC}" 152 else 153 echo -e "${YELLOW}Binary verification failed. The binary may not be working correctly.${NC}" 154 fi 155 else 156 echo -e "${RED}Binary not found: ./beta-build/keepsync-beta${NC}" 157 exit 1 158 fi 159 160 echo -e "${GREEN}Beta build complete: ./beta-build/keepsync-beta${NC}" 161 echo -e "${BLUE}Next steps:${NC}" 162 echo "1. Run the binary with ./beta-build/keepsync-beta" 163 echo "2. Test the features" 164 echo "3. Package the binary for distribution"