diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..05d5dbe --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3c356ff --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 88f4f8a..93dd433 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # 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 \ No newline at end of file diff --git a/pager.sh b/pager.sh new file mode 100644 index 0000000..3461fee --- /dev/null +++ b/pager.sh @@ -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///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