forked from RfidResearchGroup/proxmark3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·145 lines (127 loc) · 3.89 KB
/
setup.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
###############################
# Linux #
# Uncomment to override #
###############################
#export SerialPort="/dev/ttyACM0"
#export DebuggerPath="/usr/bin/gdb"
#export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe"
###############################
# WSL #
# Uncomment to override #
###############################
#export SerialPort="/dev/ttyS4"
#export DebuggerPath="/usr/bin/gdb"
#export JLinkServerPath="/mnt/c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
###############################
# ProxSpace #
# Uncomment to override #
###############################
#export SerialPort="COM5"
#export JLinkServerPath="C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
#Debugging on 256KB systems is not recommended
#This option does not override PLATFORM_SIZE
export DeviceMem="512"
VSCODEPATH=$(dirname "$0")
function print_config {
echo "Updating with following configuration:"
echo "SerialPort: $SerialPort"
echo "DebuggerPath: $DebuggerPath"
echo "JLinkServerPath: $JLinkServerPath"
}
function setup_serial_port {
if [ -z "$SerialPort" ]; then
pm3list=$($VSCODEPATH/../pm3 --list 2>/dev/null)
#Use first port listed
export SerialPort=$(echo $pm3list | head -n 1 | cut -c 4-)
if [ -z "$SerialPort" ]; then
echo >&2 "[!!] No serial port found, please set SerialPort manually"
exit 1
fi
fi
}
function setup_gdb_linux {
if [ -z "$DebuggerPath" ]; then
export DebuggerPath="/usr/bin/gdb"
fi
if [ ! -x "$DebuggerPath" ]; then
echo >&2 "[!!] gdb not found, please set DebuggerPath manually"
exit 1
fi
}
function setup_jlink_linux {
if [ -z "$JLinkServerPath" ]; then
export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe"
fi
if [ ! -x "$JLinkServerPath" ]; then
echo >&2 "[!!] JLinkGDBServerCLExe not found, please set JLinkServerPath manually"
exit 1
fi
}
function setup_jlink_wsl {
if [ -z "$JLinkServerPath" ]; then
export JLinkServerPath="/mnt/c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
fi
if [ ! -x "$JLinkServerPath" ]; then
echo >&2 "[!!] JLinkGDBServerCL.exe not found, please set JLinkServerPath manually"
exit 1
fi
}
function setup_jlink_ps {
if [ -z "$JLinkServerPath" ]; then
export JLinkServerPath="c:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
fi
jlinkpath=$(cygpath "$JLinkServerPath")
if [ ! -x "$jlinkpath" ]; then
echo >&2 "[!!] JLinkGDBServerCL.exe not found, please set JLinkServerPath manually"
exit 1
fi
}
function setup_wsl {
setup_serial_port
setup_gdb_linux
setup_jlink_wsl
print_config
envsubst '${SerialPort} ${DebuggerPath} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_wsl.json" > "$VSCODEPATH/launch.json"
}
function setup_linux {
setup_serial_port
setup_gdb_linux
setup_jlink_linux
print_config
envsubst '${SerialPort} ${DebuggerPath} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_linux.json" > "$VSCODEPATH/launch.json"
}
function setup_ps {
setup_serial_port
setup_jlink_ps
export DebuggerPath="Using ProxSpace gbd"
print_config
envsubst '${SerialPort} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_ps.json" > "$VSCODEPATH/launch.json"
}
if [ -f "$VSCODEPATH/launch.json" ]; then
read -p "Existing configuration found, do you want to override it? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm "$VSCODEPATH/launch.json.bak" 2> /dev/null
mv "$VSCODEPATH/launch.json" "$VSCODEPATH/launch.json.bak" 2> /dev/null
else
echo >&2 "[!!] user abort"
exit 1
fi
fi
HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then
if uname -a|grep -q Microsoft; then
setup_wsl
else
setup_linux
fi
elif [ "$HOSTOS" = "DARWIN" ]; then
echo >&2 "[!!] MacOS not supported, sorry!"
exit 1
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
setup_ps
else
echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS"
exit 1
fi