-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_sd_bin.sh
More file actions
executable file
·99 lines (78 loc) · 2.61 KB
/
clean_sd_bin.sh
File metadata and controls
executable file
·99 lines (78 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Remove OpenChord.bin from SD card after flashing
# Usage: ./clean_sd_bin.sh [SD_CARD_MOUNT_POINT]
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_NAME="OpenChord.bin"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Determine SD card mount point
SD_MOUNT=""
if [ -n "$1" ]; then
SD_MOUNT="$1"
if [ ! -d "$SD_MOUNT" ]; then
print_error "Mount point does not exist: $SD_MOUNT"
exit 1
fi
else
# Auto-detect (same logic as flash_sd.sh)
if [[ "$OSTYPE" == "darwin"* ]]; then
SD_CARDS=($(df -h | grep -E '^/dev/disk[0-9]+s[0-9]+' | awk '{print $9}' | grep -v '/Volumes/Time Machine' | grep -v '/Volumes/Backups' | grep -v '/Volumes/Macintosh HD' || true))
if [ ${#SD_CARDS[@]} -eq 0 ]; then
print_error "No SD cards found. Please mount an SD card first."
ls -1 /Volumes/ 2>/dev/null || true
exit 1
elif [ ${#SD_CARDS[@]} -eq 1 ]; then
SD_MOUNT="${SD_CARDS[0]}"
else
print_info "Multiple drives found:"
for i in "${!SD_CARDS[@]}"; do
echo " $((i+1)). ${SD_CARDS[$i]}"
done
read -p "Select SD card number (1-${#SD_CARDS[@]}): " SELECTION
if [ "$SELECTION" -ge 1 ] && [ "$SELECTION" -le ${#SD_CARDS[@]} ]; then
SD_MOUNT="${SD_CARDS[$((SELECTION-1))]}"
else
print_error "Invalid selection"
exit 1
fi
fi
else
SD_CARDS=($(df -h | grep -E '/media/|/mnt/' | awk '{print $6}' || true))
if [ ${#SD_CARDS[@]} -eq 0 ]; then
print_error "No SD cards found."
exit 1
elif [ ${#SD_CARDS[@]} -eq 1 ]; then
SD_MOUNT="${SD_CARDS[0]}"
else
print_info "Multiple drives found:"
for i in "${!SD_CARDS[@]}"; do
echo " $((i+1)). ${SD_CARDS[$i]}"
done
read -p "Select SD card number: " SELECTION
SD_MOUNT="${SD_CARDS[$((SELECTION-1))]}"
fi
fi
fi
TARGET_FILE="$SD_MOUNT/$TARGET_NAME"
if [ -f "$TARGET_FILE" ]; then
print_info "Found: $TARGET_FILE"
rm "$TARGET_FILE"
print_info "✓ Removed $TARGET_NAME from SD card"
print_info "Device will now boot normally without trying to re-flash"
else
print_warn "No $TARGET_NAME file found on SD card"
print_info "Nothing to clean up"
fi