1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:39:42 +00:00

Use more robust scripts

This commit is contained in:
Tw93
2025-11-19 09:45:14 +08:00
parent 0154c272fb
commit f8f9d7db7d
7 changed files with 57 additions and 20 deletions

Binary file not shown.

View File

@@ -256,7 +256,7 @@ safe_clean() {
# Hard-coded protection for critical apps (cannot be disabled by user)
case "$path" in
*clash*|*Clash*|*surge*|*Surge*|*mihomo*)
*clash* | *Clash* | *surge* | *Surge* | *mihomo*)
skip=true
((skipped_count++))
;;
@@ -1488,7 +1488,7 @@ perform_cleanup() {
# This prevents deleting backups that are currently in progress
local file_mtime=$(stat -f%m "$inprogress_file" 2> /dev/null || echo "0")
local current_time=$(date +%s)
local hours_old=$(( (current_time - file_mtime) / 3600 ))
local hours_old=$(((current_time - file_mtime) / 3600))
if [[ $hours_old -lt 24 ]]; then
continue # Skip - backup might still be in progress
@@ -1544,7 +1544,7 @@ perform_cleanup() {
# Safety check: only delete .inProgress backups older than 24 hours
local file_mtime=$(stat -f%m "$inprogress_file" 2> /dev/null || echo "0")
local current_time=$(date +%s)
local hours_old=$(( (current_time - file_mtime) / 3600 ))
local hours_old=$(((current_time - file_mtime) / 3600))
if [[ $hours_old -lt 24 ]]; then
continue # Skip - backup might still be in progress

View File

@@ -1270,10 +1270,10 @@ readonly DATA_PROTECTED_BUNDLES=(
"com.usebruno.app" # Bruno (API client)
# Network Proxy & VPN Tools (protect all variants)
"*clash*" # All Clash variants (ClashX, ClashX Pro, Clash Verge, etc)
"*Clash*" # Capitalized variants
"com.nssurge.surge-mac" # Surge
"mihomo*" # Mihomo Party and variants
"*clash*" # All Clash variants (ClashX, ClashX Pro, Clash Verge, etc)
"*Clash*" # Capitalized variants
"com.nssurge.surge-mac" # Surge
"mihomo*" # Mihomo Party and variants
# ============================================================================
# Development Tools - Git & Version Control

View File

@@ -6,15 +6,31 @@ set -euo pipefail
cd "$(dirname "$0")/.."
# Check if Go is installed
if ! command -v go > /dev/null 2>&1; then
echo "Error: Go not installed"
echo "Install: brew install go"
exit 1
fi
echo "Building analyze-go for multiple architectures..."
# Get version info
VERSION=$(git describe --tags --always --dirty 2> /dev/null || echo "dev")
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS="-s -w -X main.Version=$VERSION -X main.BuildTime=$BUILD_TIME"
echo " Version: $VERSION"
echo " Build time: $BUILD_TIME"
echo ""
# Build for arm64 (Apple Silicon)
echo " → Building for arm64..."
GOARCH=arm64 go build -ldflags="-s -w" -o bin/analyze-go-arm64 ./cmd/analyze
GOARCH=arm64 go build -ldflags="$LDFLAGS" -trimpath -o bin/analyze-go-arm64 ./cmd/analyze
# Build for amd64 (Intel)
echo " → Building for amd64..."
GOARCH=amd64 go build -ldflags="-s -w" -o bin/analyze-go-amd64 ./cmd/analyze
GOARCH=amd64 go build -ldflags="$LDFLAGS" -trimpath -o bin/analyze-go-amd64 ./cmd/analyze
# Create Universal Binary
echo " → Creating Universal Binary..."

View File

@@ -52,10 +52,10 @@ fi
# 3. Unit tests (if available)
echo -e "${YELLOW}3. Running tests...${NC}"
if command -v bats > /dev/null 2>&1 && [ -d "tests" ]; then
if bats tests/*.bats 2> /dev/null; then
if bats tests/*.bats; then
echo -e "${GREEN}✓ Tests passed${NC}\n"
else
echo -e "${RED}✗ Tests failed${NC}\n"
echo -e "${RED}✗ Tests failed (see output above)${NC}\n"
exit 1
fi
else
@@ -88,7 +88,7 @@ fi
# Check 3: Log rotation once per session
((TOTAL_CHECKS++))
if grep -q "rotate_log_once" lib/common.sh && ! grep -q "rotate_log()" lib/common.sh | grep -v "rotate_log_once"; then
if grep -q "rotate_log_once" lib/common.sh && ! grep "rotate_log()" lib/common.sh | grep -v "rotate_log_once" > /dev/null 2>&1; then
echo -e "${GREEN} ✓ Log rotation optimized (once per session)${NC}"
((OPTIMIZATION_SCORE++))
else

View File

@@ -37,24 +37,37 @@ if ! command -v shfmt > /dev/null 2>&1; then
exit 1
fi
# Find all shell scripts
# Find all shell scripts (excluding temp directories and build artifacts)
cd "$PROJECT_ROOT"
# Build list of files to format (exclude .git, node_modules, tmp directories)
FILES=$(find . -type f \( -name "*.sh" -o -name "mole" \) \
-not -path "./.git/*" \
-not -path "*/node_modules/*" \
-not -path "*/tests/tmp-*/*" \
-not -path "*/.*" \
2> /dev/null)
if [[ -z "$FILES" ]]; then
echo "No shell scripts found"
exit 0
fi
# shfmt options: -i 4 (4 spaces), -ci (indent switch cases), -sr (space after redirect)
if [[ "$CHECK_ONLY" == "true" ]]; then
echo "Checking formatting..."
if shfmt -i 4 -ci -sr -d . > /dev/null 2>&1; then
if echo "$FILES" | xargs shfmt -i 4 -ci -sr -d > /dev/null 2>&1; then
echo "✓ All scripts properly formatted"
exit 0
else
echo "✗ Some scripts need formatting:"
shfmt -i 4 -ci -sr -d .
echo "$FILES" | xargs shfmt -i 4 -ci -sr -d
echo ""
echo "Run './scripts/format.sh' to fix"
exit 1
fi
else
echo "Formatting scripts..."
shfmt -i 4 -ci -sr -w .
echo "$FILES" | xargs shfmt -i 4 -ci -sr -w
echo "✓ Done"
fi

View File

@@ -246,19 +246,27 @@ create_raycast_commands() {
log_success "Scripts ready in: $dir"
done
echo ""
if open "raycast://extensions/script-commands" > /dev/null 2>&1; then
log_step "Raycast settings opened. Run 'Reload Script Directories'."
log_step "Raycast settings opened."
else
log_warn "Could not auto-open Raycast. Open it manually to reload scripts."
log_warn "Could not auto-open Raycast."
fi
echo ""
echo "Next steps to activate Raycast commands:"
echo " 1. Open Raycast (⌘ Space)"
echo " 2. Search for 'Reload Script Directories'"
echo " 3. Press Enter to load new commands"
}
uuid() {
if command -v uuidgen > /dev/null 2>&1; then
uuidgen
else
# Fallback pseudo UUID
openssl rand -hex 16 | sed 's/\(..\)/\1/g' | cut -c1-32
# Fallback pseudo UUID in format: 8-4-4-4-12
local hex=$(openssl rand -hex 16)
echo "${hex:0:8}-${hex:8:4}-${hex:12:4}-${hex:16:4}-${hex:20:12}"
fi
}