/ scripts / beta-integration-setup.sh
beta-integration-setup.sh
  1  #!/usr/bin/env bash
  2  # beta-integration-setup.sh
  3  #
  4  # This script sets up a clean build environment for the beta integration.
  5  # It creates a dedicated branch, verifies dependencies, and prepares the build environment.
  6  #
  7  # Usage: ./scripts/beta-integration-setup.sh [options]
  8  #
  9  # Options:
 10  #   --branch=NAME   Specify the branch name (default: beta-integration)
 11  #   --dry-run       Show what would be done without making changes
 12  #   --help          Show this help message
 13  #
 14  # Example: ./scripts/beta-integration-setup.sh --branch=beta-v0.8.0
 15  
 16  set -e
 17  
 18  # Default options
 19  BRANCH_NAME="beta-integration"
 20  DRY_RUN=false
 21  SHOW_HELP=false
 22  
 23  # Parse options
 24  for arg in "$@"; do
 25      case $arg in
 26          --branch=*)
 27              BRANCH_NAME="${arg#*=}"
 28              shift
 29              ;;
 30          --dry-run)
 31              DRY_RUN=true
 32              shift
 33              ;;
 34          --help)
 35              SHOW_HELP=true
 36              shift
 37              ;;
 38          *)
 39              echo "Unknown option: $arg"
 40              exit 1
 41              ;;
 42      esac
 43  done
 44  
 45  # Show help message
 46  if [[ "$SHOW_HELP" == "true" ]]; then
 47      echo "Usage: $0 [options]"
 48      echo ""
 49      echo "Options:"
 50      echo "  --branch=NAME   Specify the branch name (default: beta-integration)"
 51      echo "  --dry-run       Show what would be done without making changes"
 52      echo "  --help          Show this help message"
 53      echo ""
 54      echo "Example: $0 --branch=beta-v0.8.0"
 55      exit 0
 56  fi
 57  
 58  # Colors for output
 59  RED='\033[0;31m'
 60  GREEN='\033[0;32m'
 61  YELLOW='\033[0;33m'
 62  BLUE='\033[0;34m'
 63  NC='\033[0m' # No Color
 64  
 65  echo -e "${BLUE}Setting up clean build environment for beta integration...${NC}"
 66  
 67  # Function to execute or simulate a command
 68  function execute_or_simulate() {
 69      if [[ "$DRY_RUN" == "false" ]]; then
 70          eval "$1"
 71          echo -e "${GREEN}Executed: $1${NC}"
 72      else
 73          echo -e "${YELLOW}Would execute: $1${NC}"
 74      fi
 75  }
 76  
 77  # Step 1: Create a dedicated branch for beta integration
 78  echo -e "${BLUE}Step 1: Creating a dedicated branch for beta integration...${NC}"
 79  execute_or_simulate "git checkout -b $BRANCH_NAME"
 80  
 81  # Step 2: Verify Go version
 82  echo -e "${BLUE}Step 2: Verifying Go version...${NC}"
 83  GO_VERSION=$(go version 2>/dev/null || echo "Go not installed")
 84  if [[ "$GO_VERSION" == *"go1.21"* || "$GO_VERSION" == *"go1.22"* ]]; then
 85      echo -e "${GREEN}Go version is compatible: $GO_VERSION${NC}"
 86  else
 87      echo -e "${RED}Go version may not be compatible: $GO_VERSION${NC}"
 88      echo -e "${YELLOW}Please install Go 1.21 or later.${NC}"
 89      if [[ "$DRY_RUN" == "false" ]]; then
 90          exit 1
 91      fi
 92  fi
 93  
 94  # Step 3: Verify dependencies
 95  echo -e "${BLUE}Step 3: Verifying dependencies...${NC}"
 96  execute_or_simulate "./scripts/integrated-build.sh deps"
 97  
 98  # Step 4: Clean the build environment
 99  echo -e "${BLUE}Step 4: Cleaning the build environment...${NC}"
100  execute_or_simulate "./scripts/integrated-build.sh clean"
101  
102  # Step 5: Verify that the project builds
103  echo -e "${BLUE}Step 5: Verifying that the project builds...${NC}"
104  execute_or_simulate "./scripts/integrated-build.sh build"
105  
106  # Step 6: Run tests to ensure everything is working
107  echo -e "${BLUE}Step 6: Running tests to ensure everything is working...${NC}"
108  execute_or_simulate "./scripts/integrated-build.sh test"
109  
110  # Step 7: Create a build directory for the beta
111  echo -e "${BLUE}Step 7: Creating a build directory for the beta...${NC}"
112  execute_or_simulate "mkdir -p ./beta-build"
113  
114  # Step 8: Create a configuration file for the beta build
115  echo -e "${BLUE}Step 8: Creating a configuration file for the beta build...${NC}"
116  if [[ "$DRY_RUN" == "false" ]]; then
117      cat > ./beta-build/config.json << EOF
118  {
119    "version": "0.8.0-beta",
120    "build_date": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
121    "features": {
122      "tpm": true,
123      "quantum_resistant": true,
124      "s3_provider": true,
125      "webdav_provider": true,
126      "sftp_provider": true,
127      "fuse": true,
128      "daemon": true
129    },
130    "build_options": {
131      "debug": false,
132      "race_detector": false,
133      "static_linking": true,
134      "compression": true
135    }
136  }
137  EOF
138      echo -e "${GREEN}Created beta build configuration file: ./beta-build/config.json${NC}"
139  else
140      echo -e "${YELLOW}Would create beta build configuration file: ./beta-build/config.json${NC}"
141  fi
142  
143  # Step 9: Create a build script for the beta
144  echo -e "${BLUE}Step 9: Creating a build script for the beta...${NC}"
145  if [[ "$DRY_RUN" == "false" ]]; then
146      cat > ./scripts/build-beta.sh << EOF
147  #!/usr/bin/env bash
148  # build-beta.sh
149  #
150  # This script builds the beta version of KeepSync with all features enabled.
151  #
152  # Usage: ./scripts/build-beta.sh [options]
153  #
154  # Options:
155  #   --debug         Enable debug mode
156  #   --race          Enable race detector
157  #   --help          Show this help message
158  #
159  # Example: ./scripts/build-beta.sh --debug
160  
161  set -e
162  
163  # Default options
164  DEBUG=false
165  RACE=false
166  SHOW_HELP=false
167  
168  # Parse options
169  for arg in "\$@"; do
170      case \$arg in
171          --debug)
172              DEBUG=true
173              shift
174              ;;
175          --race)
176              RACE=true
177              shift
178              ;;
179          --help)
180              SHOW_HELP=true
181              shift
182              ;;
183          *)
184              echo "Unknown option: \$arg"
185              exit 1
186              ;;
187      esac
188  done
189  
190  # Show help message
191  if [[ "\$SHOW_HELP" == "true" ]]; then
192      echo "Usage: \$0 [options]"
193      echo ""
194      echo "Options:"
195      echo "  --debug         Enable debug mode"
196      echo "  --race          Enable race detector"
197      echo "  --help          Show this help message"
198      echo ""
199      echo "Example: \$0 --debug"
200      exit 0
201  fi
202  
203  # Colors for output
204  RED='\033[0;31m'
205  GREEN='\033[0;32m'
206  YELLOW='\033[0;33m'
207  BLUE='\033[0;34m'
208  NC='\033[0m' # No Color
209  
210  echo -e "\${BLUE}Building beta version of KeepSync...\${NC}"
211  
212  # Set build options
213  BUILD_OPTS=""
214  if [[ "\$DEBUG" == "true" ]]; then
215      BUILD_OPTS="\$BUILD_OPTS -tags debug"
216      echo -e "\${YELLOW}Debug mode enabled\${NC}"
217  fi
218  
219  if [[ "\$RACE" == "true" ]]; then
220      BUILD_OPTS="\$BUILD_OPTS -race"
221      echo -e "\${YELLOW}Race detector enabled\${NC}"
222  fi
223  
224  # Update build configuration
225  if [[ "\$DEBUG" == "true" ]]; then
226      sed -i 's/"debug": false/"debug": true/' ./beta-build/config.json
227  fi
228  
229  if [[ "\$RACE" == "true" ]]; then
230      sed -i 's/"race_detector": false/"race_detector": true/' ./beta-build/config.json
231  fi
232  
233  # Build the binary
234  echo -e "\${BLUE}Building binary...\${NC}"
235  go build \$BUILD_OPTS -o ./beta-build/keepsync-beta ./cmd/keepsync-cli-standalone
236  
237  # Verify the binary
238  echo -e "\${BLUE}Verifying binary...\${NC}"
239  ./beta-build/keepsync-beta version
240  
241  echo -e "\${GREEN}Beta build complete: ./beta-build/keepsync-beta\${NC}"
242  echo -e "\${BLUE}Next steps:\${NC}"
243  echo "1. Run the binary with ./beta-build/keepsync-beta"
244  echo "2. Test the features"
245  echo "3. Package the binary for distribution"
246  EOF
247      chmod +x ./scripts/build-beta.sh
248      echo -e "${GREEN}Created beta build script: ./scripts/build-beta.sh${NC}"
249  else
250      echo -e "${YELLOW}Would create beta build script: ./scripts/build-beta.sh${NC}"
251  fi
252  
253  # Step 10: Create a test script for the beta
254  echo -e "${BLUE}Step 10: Creating a test script for the beta...${NC}"
255  if [[ "$DRY_RUN" == "false" ]]; then
256      cat > ./scripts/test-beta.sh << EOF
257  #!/usr/bin/env bash
258  # test-beta.sh
259  #
260  # This script tests the beta version of KeepSync.
261  #
262  # Usage: ./scripts/test-beta.sh [options]
263  #
264  # Options:
265  #   --binary=PATH   Specify the binary path (default: ./beta-build/keepsync-beta)
266  #   --help          Show this help message
267  #
268  # Example: ./scripts/test-beta.sh --binary=./my-beta-build/keepsync
269  
270  set -e
271  
272  # Default options
273  BINARY="./beta-build/keepsync-beta"
274  SHOW_HELP=false
275  
276  # Parse options
277  for arg in "\$@"; do
278      case \$arg in
279          --binary=*)
280              BINARY="\${arg#*=}"
281              shift
282              ;;
283          --help)
284              SHOW_HELP=true
285              shift
286              ;;
287          *)
288              echo "Unknown option: \$arg"
289              exit 1
290              ;;
291      esac
292  done
293  
294  # Show help message
295  if [[ "\$SHOW_HELP" == "true" ]]; then
296      echo "Usage: \$0 [options]"
297      echo ""
298      echo "Options:"
299      echo "  --binary=PATH   Specify the binary path (default: ./beta-build/keepsync-beta)"
300      echo "  --help          Show this help message"
301      echo ""
302      echo "Example: \$0 --binary=./my-beta-build/keepsync"
303      exit 0
304  fi
305  
306  # Colors for output
307  RED='\033[0;31m'
308  GREEN='\033[0;32m'
309  YELLOW='\033[0;33m'
310  BLUE='\033[0;34m'
311  NC='\033[0m' # No Color
312  
313  echo -e "\${BLUE}Testing beta version of KeepSync...\${NC}"
314  
315  # Check if the binary exists
316  if [[ ! -f "\$BINARY" ]]; then
317      echo -e "\${RED}Binary not found: \$BINARY\${NC}"
318      echo -e "\${YELLOW}Please build the binary first with ./scripts/build-beta.sh\${NC}"
319      exit 1
320  fi
321  
322  # Make the binary executable
323  chmod +x "\$BINARY"
324  
325  # Test 1: Version check
326  echo -e "\${BLUE}Test 1: Version check\${NC}"
327  VERSION_OUTPUT=\$("\$BINARY" version)
328  if [[ "\$VERSION_OUTPUT" == *"0.8.0-beta"* ]]; then
329      echo -e "\${GREEN}Version check passed\${NC}"
330  else
331      echo -e "\${RED}Version check failed\${NC}"
332      echo "\$VERSION_OUTPUT"
333      exit 1
334  fi
335  
336  # Test 2: TPM status check
337  echo -e "\${BLUE}Test 2: TPM status check\${NC}"
338  TPM_OUTPUT=\$("\$BINARY" tpm status 2>&1 || true)
339  if [[ "\$TPM_OUTPUT" == *"TPM"* ]]; then
340      echo -e "\${GREEN}TPM status check passed\${NC}"
341  else
342      echo -e "\${RED}TPM status check failed\${NC}"
343      echo "\$TPM_OUTPUT"
344      exit 1
345  fi
346  
347  # Test 3: Quantum-resistant encryption check
348  echo -e "\${BLUE}Test 3: Quantum-resistant encryption check\${NC}"
349  QUANTUM_OUTPUT=\$("\$BINARY" quantum status 2>&1 || true)
350  if [[ "\$QUANTUM_OUTPUT" == *"quantum"* || "\$QUANTUM_OUTPUT" == *"Quantum"* ]]; then
351      echo -e "\${GREEN}Quantum-resistant encryption check passed\${NC}"
352  else
353      echo -e "\${RED}Quantum-resistant encryption check failed\${NC}"
354      echo "\$QUANTUM_OUTPUT"
355      exit 1
356  fi
357  
358  # Test 4: S3 provider check
359  echo -e "\${BLUE}Test 4: S3 provider check\${NC}"
360  S3_OUTPUT=\$("\$BINARY" help 2>&1 | grep -i "s3" || true)
361  if [[ -n "\$S3_OUTPUT" ]]; then
362      echo -e "\${GREEN}S3 provider check passed\${NC}"
363  else
364      echo -e "\${RED}S3 provider check failed\${NC}"
365      exit 1
366  fi
367  
368  # Test 5: WebDAV provider check
369  echo -e "\${BLUE}Test 5: WebDAV provider check\${NC}"
370  WEBDAV_OUTPUT=\$("\$BINARY" help 2>&1 | grep -i "webdav" || true)
371  if [[ -n "\$WEBDAV_OUTPUT" ]]; then
372      echo -e "\${GREEN}WebDAV provider check passed\${NC}"
373  else
374      echo -e "\${RED}WebDAV provider check failed\${NC}"
375      exit 1
376  fi
377  
378  # Test 6: SFTP provider check
379  echo -e "\${BLUE}Test 6: SFTP provider check\${NC}"
380  SFTP_OUTPUT=\$("\$BINARY" help 2>&1 | grep -i "sftp" || true)
381  if [[ -n "\$SFTP_OUTPUT" ]]; then
382      echo -e "\${GREEN}SFTP provider check passed\${NC}"
383  else
384      echo -e "\${RED}SFTP provider check failed\${NC}"
385      exit 1
386  fi
387  
388  echo -e "\${GREEN}All tests passed!\${NC}"
389  echo -e "\${BLUE}Next steps:\${NC}"
390  echo "1. Run more comprehensive tests"
391  echo "2. Package the binary for distribution"
392  echo "3. Deploy the beta build"
393  EOF
394      chmod +x ./scripts/test-beta.sh
395      echo -e "${GREEN}Created beta test script: ./scripts/test-beta.sh${NC}"
396  else
397      echo -e "${YELLOW}Would create beta test script: ./scripts/test-beta.sh${NC}"
398  fi
399  
400  echo -e "${GREEN}Build environment setup complete.${NC}"
401  echo -e "${BLUE}Next steps:${NC}"
402  echo "1. Begin implementing the core provider infrastructure"
403  echo "2. Run ./scripts/build-beta.sh to build the beta version"
404  echo "3. Run ./scripts/test-beta.sh to test the beta version"