Merge pull request #1327 from Pondorasti/patch-1
[RRG-proxmark3.git] / .vscode / setup.sh
blob70672b9241f526edfc3247de38a3619c803d72d4
1 #!/bin/bash
2 ###############################
3 # Linux #
4 # Uncomment to override #
5 ###############################
6 #export SerialPort="/dev/ttyACM0"
7 #export DebuggerPath="/usr/bin/gdb"
8 #export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe"
10 ###############################
11 # WSL #
12 # Uncomment to override #
13 ###############################
14 #export SerialPort="/dev/ttyS4"
15 #export DebuggerPath="/usr/bin/gdb"
16 #export JLinkServerPath="/mnt/c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
18 ###############################
19 # ProxSpace #
20 # Uncomment to override #
21 ###############################
22 #export SerialPort="COM5"
23 #export JLinkServerPath="C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
25 #Debugging on 256KB systems is not recommended
26 #This option does not override PLATFORM_SIZE
27 export DeviceMem="512"
30 VSCODEPATH=$(dirname "$0")
32 function print_config {
33 echo "Updating with following configuration:"
34 echo "SerialPort: $SerialPort"
35 echo "DebuggerPath: $DebuggerPath"
36 echo "JLinkServerPath: $JLinkServerPath"
39 function setup_serial_port {
40 if [ -z "$SerialPort" ]; then
41 pm3list=$($VSCODEPATH/../pm3 --list 2>/dev/null)
42 #Use first port listed
43 export SerialPort=$(echo $pm3list | head -n 1 | cut -c 4-)
44 if [ -z "$SerialPort" ]; then
45 echo >&2 "[!!] No serial port found, please set SerialPort manually"
46 exit 1
51 function setup_gdb_linux {
52 if [ -z "$DebuggerPath" ]; then
53 export DebuggerPath="/usr/bin/gdb"
55 if [ ! -x "$DebuggerPath" ]; then
56 echo >&2 "[!!] gdb not found, please set DebuggerPath manually"
57 exit 1
61 function setup_jlink_linux {
62 if [ -z "$JLinkServerPath" ]; then
63 export JLinkServerPath="/opt/SEGGER/JLink/JLinkGDBServerCLExe"
65 if [ ! -x "$JLinkServerPath" ]; then
66 echo >&2 "[!!] JLinkGDBServerCLExe not found, please set JLinkServerPath manually"
67 exit 1
72 function setup_jlink_wsl {
73 if [ -z "$JLinkServerPath" ]; then
74 export JLinkServerPath="/mnt/c/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
76 if [ ! -x "$JLinkServerPath" ]; then
77 echo >&2 "[!!] JLinkGDBServerCL.exe not found, please set JLinkServerPath manually"
78 exit 1
82 function setup_jlink_ps {
83 if [ -z "$JLinkServerPath" ]; then
84 export JLinkServerPath="c:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
86 jlinkpath=$(cygpath "$JLinkServerPath")
87 if [ ! -x "$jlinkpath" ]; then
88 echo >&2 "[!!] JLinkGDBServerCL.exe not found, please set JLinkServerPath manually"
89 exit 1
93 function setup_wsl {
94 setup_serial_port
95 setup_gdb_linux
96 setup_jlink_wsl
97 print_config
98 envsubst '${SerialPort} ${DebuggerPath} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_wsl.json" > "$VSCODEPATH/launch.json"
101 function setup_linux {
102 setup_serial_port
103 setup_gdb_linux
104 setup_jlink_linux
105 print_config
106 envsubst '${SerialPort} ${DebuggerPath} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_linux.json" > "$VSCODEPATH/launch.json"
109 function setup_ps {
110 setup_serial_port
111 setup_jlink_ps
112 export DebuggerPath="Using ProxSpace gbd"
113 print_config
114 envsubst '${SerialPort} ${JLinkServerPath} ${DeviceMem}' <"$VSCODEPATH/templates/launch_ps.json" > "$VSCODEPATH/launch.json"
117 if [ -f "$VSCODEPATH/launch.json" ]; then
118 read -p "Existing configuration found, do you want to override it? " -n 1 -r
119 if [[ $REPLY =~ ^[Yy]$ ]]
120 then
121 rm "$VSCODEPATH/launch.json.bak" 2> /dev/null
122 mv "$VSCODEPATH/launch.json" "$VSCODEPATH/launch.json.bak" 2> /dev/null
123 else
124 echo >&2 "[!!] user abort"
125 exit 1
130 HOSTOS=$(uname | awk '{print toupper($0)}')
131 if [ "$HOSTOS" = "LINUX" ]; then
132 if uname -a|grep -q Microsoft; then
133 setup_wsl
134 else
135 setup_linux
137 elif [ "$HOSTOS" = "DARWIN" ]; then
138 echo >&2 "[!!] MacOS not supported, sorry!"
139 exit 1
140 elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
141 setup_ps
142 else
143 echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS"
144 exit 1