#!/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 ######################################################################## ######################################################################## echo "RETRY ERROR MESSAGE" for tosend in /home/${YOU}/.zen/SMS/PHONE/*/*.error.txt; do phonehash=$(echo "${tosend}" | cut -d '/' -f 7) && [[ $phonehash == "*" ]] && continue xzuid=$(cat "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/xzuid.txt") [[ ! $xzuid ]] && echo "ERROR $tosend" && continue $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 "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 sleep 3 done ######################################################################## ######################################################################## echo "SEARCHING FOR NEW SMS TO SEND TO USERS" for tosend in /home/${YOU}/.zen/SMS/PHONE/*/*.tosend.sh; do phonehash=$(echo "${tosend}" | cut -d '/' -f 7) && [[ $phonehash == "*" ]] && continue xzuid=$(cat "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/xzuid.txt") [[ ! $xzuid ]] && echo "ERROR $tosend" && continue $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}" ## 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 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 ######################################################################## ######################################################################## echo "SEARCHING FOR GUIDE SMS TO SEND TO GUILDE USERS" for guidesend in /home/${YOU}/.zen/SMS/GUILDES/*/OUTPUT/*.tosend.sh; do guilde=$(echo "$guidesend" | cut -d '/' -f 7) && [[ $guilde == "*" ]] && continue [[ ! -d /home/${YOU}/.zen/SMS/GUILDES/${guilde} ]] && continue 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) phonehash=$(echo $phone | sha256sum | cut -d ' ' -f1) xzuid=$(cat "/home/${YOU}/.zen/SMS/PHONE/${phonehash}/xzuid.txt") [[ ! $xzuid ]] && echo "ERROR $tosend" && continue ## PREPARE SMS cat "${guidesend}" | sed "s/_PHONE_/${phone}/g" | sed "s/_ID_/${xzuid}/g" > /tmp/guidesend.sh && chmod +x /tmp/guidesend.sh ## 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 ## REMOVING ${guidesend} from guilde SMS QUEUE mv ${guidesend} ${guidesend}.txt done ## REINIT gammu-smsd spool sudo rm /var/spool/gammu/inbox/* 2>/dev/null sudo rm /var/spool/gammu/error/* 2>/dev/null ## START GAMMU-SMSD #sudo service gammu-smsd start