You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.4 KiB
82 lines
1.4 KiB
#!/bin/bash
|
|
# Get DMR-IDs from CALLSIGN or CALLSIGN from DMR-ID or vice versa
|
|
# Author: Dominic Reich, OE7DRT
|
|
# File: ~/bin/call
|
|
#
|
|
# Last modified: 2020-04-12 13:26:36+0200
|
|
#
|
|
# Inspired from this beautiful article:
|
|
# https://pretzelhands.com/posts/command-line-flags
|
|
#
|
|
# Good DX and vy 73 de OE7DRT
|
|
|
|
command -v w3m > /dev/null 2>&1 || { echo >&2 "w3m not found"; exit 1; }
|
|
|
|
print_usage () {
|
|
echo >&2 "usage: `basename $0` [dmr_id | callsign]"
|
|
exit 1
|
|
}
|
|
|
|
if [ $# -ne 1 ]
|
|
then
|
|
print_usage
|
|
fi
|
|
|
|
getID () {
|
|
CALL=`echo $1 | tr a-z A-Z`
|
|
FILE=/tmp/$CALL
|
|
URL="https://qrz.com/db/$CALL"
|
|
w3m "https://ham-digital.org/dmr-userreg.php?callsign=$CALL" > $FILE
|
|
c=`grep $CALL $FILE | wc -l | xargs`
|
|
|
|
while [ $c -gt 0 ]
|
|
do
|
|
OUT=`grep $CALL $FILE | head -n $c | tail -n 1 | awk '{ print $4,$5,$2,$3 }'`
|
|
echo "$OUT $URL"
|
|
((c--))
|
|
done
|
|
rm $FILE
|
|
}
|
|
|
|
getCALLSIGN () {
|
|
ID=$1
|
|
FILE=/tmp/$ID
|
|
w3m "https://ham-digital.org/dmr-userreg.php?usrid=$ID" > $FILE
|
|
CALL=`grep $ID $FILE | awk '{ print $4 }'`
|
|
rm $FILE
|
|
if [ -z $CALL ]
|
|
then
|
|
exit 1
|
|
fi
|
|
getID $CALL
|
|
}
|
|
|
|
checkID () {
|
|
if [[ ! $1 =~ ^[0-9]{7}$ ]]
|
|
then
|
|
echo >&2 "no valid dmr_id supplied"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
if [ "$1" -eq "$1" ] 2>/dev/null
|
|
then
|
|
ID="$1"
|
|
checkID $ID
|
|
else
|
|
CALL="$1"
|
|
fi
|
|
|
|
if [ ! -z $ID ]
|
|
then
|
|
getCALLSIGN $ID
|
|
exit 0
|
|
elif [ ! -z $CALL ]
|
|
then
|
|
getID $CALL
|
|
exit 0
|
|
else
|
|
print_usage
|
|
fi
|
|
|