proxmark3/proxmark3.sh

81 lines
2 KiB
Bash
Raw Normal View History

#!/bin/bash
FULLIMAGE="armsrc/obj/fullimage.elf"
BOOTIMAGE="bootrom/obj/bootrom.elf"
cd $(dirname "$0")
2018-08-17 00:31:12 +08:00
function wait4proxmark_Linux {
2019-03-09 18:10:22 +08:00
echo >&2 "Waiting for Proxmark to appear..."
2019-03-14 19:30:32 +08:00
while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do
2019-03-09 18:10:22 +08:00
sleep .1
done
local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1`
echo >&2 -e "Found proxmark on ${PM3}\n"
echo $PM3
}
function wait4proxmark_macOS {
2019-03-09 18:10:22 +08:00
echo >&2 "Waiting for Proxmark to appear..."
while true; do
PM3=$(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)
if [[ $PM3 != "" ]]; then
#echo >&2 -e "Found proxmark on $(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)\n"
break
fi
sleep .1
done
echo $PM3
}
function wait4proxmark_Windows {
echo >&2 "Waiting for Proxmark to appear..."
while true; do
device=$(wmic path Win32_SerialPort get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2')
if [[ $device =~ VID_9AC4\&PID_4B8F ]]; then
PM3=${device/ */}
break
fi
sleep .1
done
echo $PM3
}
SCRIPT=$(basename -- "$0")
if [ "$SCRIPT" = "proxmark3.sh" ]; then
CMD=client/proxmark3
elif [ "$SCRIPT" = "flash-all.sh" ]; then
CMD=client/flasher
ARG1="-b $BOOTIMAGE"
ARG2="$FULLIMAGE"
elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then
CMD=client/flasher
ARG2="$FULLIMAGE"
elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then
CMD=client/flasher
ARG1="-b $BOOTIMAGE"
else
echo "Script ran under unknown name, abort: $SCRIPT"
exit 1
fi
HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then
PORT=$(wait4proxmark_Linux)
elif [ "$HOSTOS" = "DARWIN" ]; then
PORT=$(wait4proxmark_macOS)
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
PORT=$(wait4proxmark_Windows)
else
echo "Host OS not recognized, abort: $HOSTOS"
exit 1
fi
if [ "$PORT" = "" ]; then
echo "No port, abort"
exit 1
fi
2019-05-03 17:25:05 +08:00
#echo Running "$CMD" "$PORT" $ARG1 $ARG2 "$@"
"$CMD" "$PORT" $ARG1 $ARG2 "$@"
exit $?