bio-dynamie/sms_send_tosend.sh

93 lines
4.6 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: GPL (http://www.google.com/search?q=GPL)
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
########################################################################
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || er+=" ipfs daemon not running"
[[ ! -f /home/${YOU}/.zen/secret.dunikey ]] && echo "Crypto is missing... please install 'astrXbian' TestNet" && exit 1
G1PUB=$(cat /home/${YOU}/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
ME="${0##*/}"
countMErunning=$(ps auxf --sort=+utime | grep -w "$ME" | grep -v -E 'color=auto|grep' | wc -l)
[[ $countMErunning -gt 2 ]] && echo "$ME already running. EXIT." && exit 0
## STOP GAMMU-SMSD
sudo service gammu-smsd stop
2021-07-11 16:17:25 +02:00
########################################################################
2021-07-11 16:52:57 +02:00
########################################################################
echo "RETRY ERROR MESSAGE"
2021-07-12 12:06:15 +02:00
for tosend in /home/${YOU}/.zen/SMS/PHONE/*/*.error.txt; do
2021-07-11 16:52:57 +02:00
phonehash=$(echo "${tosend}" | cut -d '/' -f 7) && [[ $phonehash == "*" ]] && continue
xzuid=$(cat "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/xzuid.txt")
[[ ! $xzuid ]] && echo "ERROR $tosend" && continue
2021-07-14 00:05:40 +02:00
$MY_PATH/sms/natools.py decrypt -f pubsec -k "/home/${YOU}/.zen/secret.dunikey" -i "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/passwd.encrypt" -o "/tmp/${phonehash}.phone"
2021-07-11 16:52:57 +02:00
phone=$(cat /tmp/${phonehash}.phone)
echo "SENDING ${phone}"
## PREPARE SMS
cat "${tosend}" | sed "s/_PHONE_/${phone}/g" | sed "s/_ID_/${xzuid}/g" > /tmp/tosend.sh && chmod +x /tmp/tosend.sh
## SEND SMS & ARCHIVE RESULT (error?)
bash -x /tmp/tosend.sh && mv ${tosend} ${tosend}.txt && rm /tmp/tosend.sh || tosend=$(echo ${tosend} | sed 's/\.error\.txt//g') && mv ${tosend} ${tosend}.error.txt
2021-07-11 16:52:57 +02:00
sleep 3
done
########################################################################
########################################################################
2021-07-12 12:58:43 +02:00
echo "SEARCHING FOR NEW SMS TO SEND TO USERS"
for tosend in /home/${YOU}/.zen/SMS/PHONE/*/*.tosend.sh; do
2021-07-11 16:17:25 +02:00
phonehash=$(echo "${tosend}" | cut -d '/' -f 7) && [[ $phonehash == "*" ]] && continue
xzuid=$(cat "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/xzuid.txt")
[[ ! $xzuid ]] && echo "ERROR $tosend" && continue
2021-07-14 00:05:40 +02:00
$MY_PATH/sms/natools.py decrypt -f pubsec -k "/home/${YOU}/.zen/secret.dunikey" -i "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/passwd.encrypt" -o "/tmp/${phonehash}.phone"
phone=$(cat /tmp/${phonehash}.phone)
echo "${phone}"
2021-07-11 16:17:25 +02:00
## PREPARE SMS
2021-07-10 02:23:23 +02:00
cat "${tosend}" | sed "s/_PHONE_/${phone}/g" | sed "s/_ID_/${xzuid}/g" > /tmp/tosend.sh && chmod +x /tmp/tosend.sh
2021-07-11 16:17:25 +02:00
## SEND SMS & ARCHIVE SMS IN /SMS/PHONE/${phonehash}/ (.txt OR .error.txt)
bash -x /tmp/tosend.sh && mv ${tosend} ${tosend}.txt || mv ${tosend} ${tosend}.error.txt
rm /tmp/tosend.sh
sleep 3
done
2021-07-11 16:17:25 +02:00
########################################################################
2021-07-11 16:52:57 +02:00
########################################################################
echo "SEARCHING FOR GUIDE SMS TO SEND TO GUILDE USERS"
for guidesend in /home/${YOU}/.zen/SMS/GUILDES/*/OUTPUT/*.tosend.sh; do
2021-07-08 05:18:51 +02:00
guilde=$(echo "$guidesend" | cut -d '/' -f 7) && [[ $guilde == "*" ]] && continue
[[ ! -d /home/${YOU}/.zen/SMS/GUILDES/${guilde} ]] && continue
2021-07-11 16:17:25 +02:00
smsfile=$(echo "$guidesend" | cut -d '/' -f 9)
for phonelink in /home/${YOU}/.zen/SMS/GUILDES/${guilde}/MEMBERS/*; do
[[ ! -L $phonelink ]] && continue
phone=$(echo "$phonelink" | cut -d '/' -f 9)
2021-07-11 16:17:25 +02:00
phonehash=$(echo $phone | sha256sum | cut -d ' ' -f1)
xzuid=$(cat "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/xzuid.txt")
[[ ! $xzuid ]] && echo "ERROR $tosend" && continue
## PREPARE SMS
2021-07-10 02:23:23 +02:00
cat "${guidesend}" | sed "s/_PHONE_/${phone}/g" | sed "s/_ID_/${xzuid}/g" > /tmp/guidesend.sh && chmod +x /tmp/guidesend.sh
2021-07-11 16:17:25 +02:00
## SEND SMS & ARCHIVE SMS IN /SMS/PHONE/${phonehash}/ (.txt OR .error.txt)
bash -x /tmp/guidesend.sh && cp ${guidesend} /home/${YOU}/.zen/SMS/PHONE/${phonehash}/${smsfile}_${guilde}.txt || mv ${guidesend} /home/${YOU}/.zen/SMS/PHONE/${phonehash}/${smsfile}_${guilde}.error.txt
rm /tmp/guidesend.sh
sleep 3
done
2021-07-11 16:17:25 +02:00
## REMOVING ${guidesend} from guilde SMS QUEUE
mv ${guidesend} ${guidesend}.txt
done
2021-07-11 16:17:25 +02:00
2021-07-08 05:14:12 +02:00
## REINIT gammu-smsd spool
2021-07-08 05:18:51 +02:00
sudo rm /var/spool/gammu/inbox/* 2>/dev/null
sudo rm /var/spool/gammu/error/* 2>/dev/null
## START GAMMU-SMSD
2021-07-14 23:45:20 +02:00
#sudo service gammu-smsd start