fix-package-structure.sh
1 #!/bin/bash 2 3 # Exit on error 4 set -e 5 6 # Set colors for better output 7 GREEN="\033[0;32m" 8 BLUE="\033[0;34m" 9 YELLOW="\033[0;33m" 10 RED="\033[0;31m" 11 RESET="\033[0m" 12 13 echo -e "${BLUE}" 14 echo -e "╔════════════════════════════════════════════════════════════════╗" 15 echo -e "║ ║" 16 echo -e "║ KeepSync Package Structure Fixer ║" 17 echo -e "║ ║" 18 echo -e "╚════════════════════════════════════════════════════════════════╝" 19 echo -e "${RESET}" 20 21 # Set directories 22 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 23 PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" 24 25 # Create missing directories if they don't exist 26 echo -e "${YELLOW}Creating missing directories...${RESET}" 27 28 # Ensure internal directory structure exists 29 mkdir -p "${PROJECT_ROOT}/internal/cloud/provider/v2/adapters" 30 mkdir -p "${PROJECT_ROOT}/internal/cloud/provider/v2/cache" 31 mkdir -p "${PROJECT_ROOT}/internal/cloud/provider/v2/chunking" 32 mkdir -p "${PROJECT_ROOT}/internal/cloud/provider/v2/retention" 33 mkdir -p "${PROJECT_ROOT}/internal/cloud/provider/v2/wrappers" 34 mkdir -p "${PROJECT_ROOT}/internal/security/tpm/core" 35 mkdir -p "${PROJECT_ROOT}/internal/security/tpm/hardware" 36 mkdir -p "${PROJECT_ROOT}/internal/security/tpm/interfaces" 37 mkdir -p "${PROJECT_ROOT}/internal/security/tpm/mock" 38 mkdir -p "${PROJECT_ROOT}/internal/multifile/chunker" 39 mkdir -p "${PROJECT_ROOT}/internal/multifile/metadata" 40 mkdir -p "${PROJECT_ROOT}/internal/multifile/processor" 41 mkdir -p "${PROJECT_ROOT}/internal/multifile/store" 42 43 # Ensure cmd directory structure exists 44 mkdir -p "${PROJECT_ROOT}/cmd/keepsync-cli/cmd" 45 mkdir -p "${PROJECT_ROOT}/cmd/keepsync-cli/services" 46 mkdir -p "${PROJECT_ROOT}/cmd/keepsync-cli-standalone/sync" 47 mkdir -p "${PROJECT_ROOT}/cmd/keepsync-cli-standalone/tpm" 48 mkdir -p "${PROJECT_ROOT}/cmd/keepsync-cli-standalone/fuse" 49 50 # Ensure build and distribution directories exist 51 mkdir -p "${PROJECT_ROOT}/bin" 52 mkdir -p "${PROJECT_ROOT}/dist" 53 mkdir -p "${PROJECT_ROOT}/test-data/temp" 54 55 # Fix package declarations in Go files 56 echo -e "${YELLOW}Fixing package declarations in Go files...${RESET}" 57 58 # Function to fix package declarations in a directory 59 fix_package_declarations() { 60 local dir=$1 61 local expected_package=$2 62 63 # Find all Go files in the directory 64 local go_files=$(find "${dir}" -maxdepth 1 -name "*.go") 65 66 for file in $go_files; do 67 # Get the current package declaration 68 local current_package=$(grep -m 1 "^package " "${file}" | awk '{print $2}') 69 70 # If the package declaration doesn't match the expected one, fix it 71 if [ "${current_package}" != "${expected_package}" ]; then 72 echo -e "${YELLOW}Fixing package declaration in ${file}${RESET}" 73 sed -i "s/^package ${current_package}/package ${expected_package}/" "${file}" 74 fi 75 done 76 } 77 78 # Fix package declarations in key directories 79 fix_package_declarations "${PROJECT_ROOT}/internal/cloud/provider/v2/adapters" "adapters" 80 fix_package_declarations "${PROJECT_ROOT}/internal/cloud/provider/v2/cache" "cache" 81 fix_package_declarations "${PROJECT_ROOT}/internal/cloud/provider/v2/chunking" "chunking" 82 fix_package_declarations "${PROJECT_ROOT}/internal/cloud/provider/v2/retention" "retention" 83 fix_package_declarations "${PROJECT_ROOT}/internal/cloud/provider/v2/wrappers" "wrappers" 84 fix_package_declarations "${PROJECT_ROOT}/internal/security/tpm/core" "core" 85 fix_package_declarations "${PROJECT_ROOT}/internal/security/tpm/hardware" "hardware" 86 fix_package_declarations "${PROJECT_ROOT}/internal/security/tpm/interfaces" "interfaces" 87 fix_package_declarations "${PROJECT_ROOT}/internal/security/tpm/mock" "mock" 88 fix_package_declarations "${PROJECT_ROOT}/cmd/keepsync-cli-standalone/sync" "sync" 89 fix_package_declarations "${PROJECT_ROOT}/cmd/keepsync-cli-standalone/tpm" "tpm" 90 fix_package_declarations "${PROJECT_ROOT}/cmd/keepsync-cli-standalone/fuse" "fuse" 91 92 echo -e "${GREEN}Package structure fixed successfully.${RESET}" 93 echo -e "${GREEN}You can now proceed with building the project.${RESET}" 94 95 exit 0