Initial commit

This commit is contained in:
Daniel Mason 2023-04-13 17:14:46 +12:00
parent 1ea3eb1f90
commit 3ed1186fb8
Signed by: idanoo
GPG key ID: 387387CDBC02F132
4 changed files with 179 additions and 1 deletions

42
.github/workflows/build-and-deploy.yml vendored Normal file
View file

@ -0,0 +1,42 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Publish Docker image
on:
release:
types: [published]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: idanoo/rtl-pager-discord
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

13
Dockerfile Normal file
View file

@ -0,0 +1,13 @@
FROM ubuntu:22.04
# Update softwares
RUN apt update && apt -y upgrade
# Install softwares
RUN apt install -y redis rtl-sdr multimon-ng
# Copy and set file
COPY pager.sh /pager.sh
RUN chmod +x /pager.sh
RUN ["bash", "/pager.sh"]

View file

@ -1,2 +1,10 @@
# rtl-pager-discord # rtl-pager-discord
Docker container to pull pager message into a discord channel Docker container to pull pager message into a discord channel from an RTL-SDR
```
docker run idanoo/rtl-pager-discord
ENV VARS:
- FREQUENCY
- GAIN
- DISCORD_WEBHOOK_URL

115
pager.sh Normal file
View file

@ -0,0 +1,115 @@
#!/bin/bash
# Make sure redis is booted!
echo 'Booting redis'
/etc/init.d/redis-server start
# Array of messages to skip
declare -A toSkip
toSkip+=( "this is a test" )
toSkip+=( "enabled demodulators" )
toSkip+=( "test page" )
toSkip+=( "assigned to station" )
# Array of emojis to add
declare -A emojiArr
# House
emojiArr[house]=":house:"
emojiArr[roof]=":house:"
# Car
emojiArr[mva]=":blue_car:"
emojiArr[mvc]=":blue_car:"
emojiArr[car ]=":blue_car:"
#Heli
emojiArr[westp1]=":helicopter:"
# Fire
emojiArr[fire]=":fire:"
emojiArr[stru]=":fire:"
emojiArr[smoke]=":fire:"
emojiArr[smoking]=":fire:"
emojiArr[chimney]=":fire:"
emojiArr[sprnklr]=":fire:"
# Flood
emojiArr[flood]=":ocean:"
# Wind
emojiArr[wind]=":wind_blowing_face:"
emojiArr[blow]=":wind_blowing_face:"
# Power
emojiArr[power]=":zap:"
emojiArr[electric]=":zap:"
emojiArr[spark]=":zap:"
# Ambulance
emojiArr[chest pain]=":ambulance:"
emojiArr[not alert]=":ambulance:"
emojiArr[seizure]=":ambulance:"
emojiArr[breath]=":ambulance:"
emojiArr[pain]=":ambulance:"
emojiArr[fall ]=":ambulance:"
emojiArr[orange]=":ambulance:"
emojiArr[sweats]=":ambulance:"
emojiArr[acute]=":ambulance:"
emojiArr[red 1]=":ambulance:"
emojiArr[red 2]=":ambulance:"
emojiArr[respitory]=":ambulance:"
emojiArr[bleeding]=":ambulance:"
emojiArr[purple]=":ambulance:"
# Rescue
emojiArr[resc ]=":helmet_with_cross:"
emojiArr[hazchem]=":biohazard:"
# Tree
emojiArr[tree]=":evergreen_tree:"
# Send to discord
sendMsg () {
# Clean up messages
STRIP=$(echo "$1" | sed ':a;N;$!ba;s/\n/ /g' | awk '{$1=$1};1' | sed 's/^|\(.*\)/\1/' | sed 's/<ETX>//g')
STRIPLOWER=$(echo "$STRIP" | tr '[:upper:]' '[:lower:]')
# Append emojis
for find in "${!emojiArr[@]}"; do
# Check if keyword matches
if [[ "$STRIPLOWER" == *"$find"* ]]; then
# Check if we have already added the keyword
if [[ "$STRIP" == *"${emojiArr[$find]}"* ]]; then
continue
fi
# Prepend the keyword
STRIP="${emojiArr[$find]} $STRIP"
fi
done
CACHECHECK=$(cacheCheck "$STRIP")
if [[ "$CACHECHECK" == "OK" ]]; then
# send to discord
curl -sS -H "Content-Type: application/json" -d "{\"username\":\"Pager\",\"content\":\"$STRIP\"}" $DISCORD_WEBHOOK_URL > /dev/null
fi
}
# Check if we've sent recently (5min TTL)
cacheCheck () {
redis-cli SET "pager:$(echo -n $1 | md5sum | awk '{print $1}')" "true" NX EX 300
}
# Run script!
rtl_fm -M fm -f ${FREQUENCY:=157.945M} -g ${GAIN:=40.2} -s 22050 -- | multimon-ng -t raw -a POCSAG512 -a POCSAG1200 -a FLEX -a POCSAG2400 /dev/stdin | while read -r line ; do
LINELOWER=$(echo "$line" | tr '[:upper:]' '[:lower:]')
# Skip certain messages
for find in "${!toSkip[@]}"; do
# Check if keyword matches - if so.. ignore
if [[ "$LINELOWER" == *"$find"* ]]; then
continue 2
fi
done
# Remove prefixes
if [[ "$line" == "FLEX"* ]]; then
sendMsg "${line#*ALN}"
elif [[ "$line" == "POCSAG"* ]]; then
if [[ "$line" == *"Alpha"* ]]; then
sendMsg "${line#*Alpha:}"
fi
else
sendMsg "$line"
fi
done