helper-scripts/sms/freesms
root a54759a7fc Ajout d'un test pour savoir l'on doit uiliser curl ou wget
Ajout d'un test pour savoir si which est installé
2020-04-27 22:43:12 +02:00

104 lines
2.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
function display_help() {
echo "${0} Usage :"
echo -e "\t-u --utilisateur\tSpecify the username"
echo -e "\t-p --password\tSpecify the password"
echo -e "\t-h or --help\tThis help"
echo ""
echo "Examples :"
echo -e "\tSend \"My message\" to your mobile phone :"
echo -e "\t\t${0} -u myuser -p mypassword My message"
echo -e "\tSend content from STDIN to your mobile phone :"
echo -e "\t\t${0} -u myuser -p mypassword -"
}
GET_OPT=`getopt -o hu:p: --long help,utilisateur:,password: -n "${0} parameters" -- "${@}"`
if [ ! "${?}" == "0" ] ; then
display_help
exit 1
fi
eval set -- "$GET_OPT"
while true ; do
case ${1} in
-u|--utilisateur)
NOM="${2}"
shift 2
;;
-p|--password)
PASS="${2}"
shift 2
;;
-h|--help)
display_help
shift
exit 0
;;
--)
MESSAGE="`echo ${@} | sed 's|^-- ||g'`"
shift
break
;;
*)
display_help >&2
exit 1
;;
esac
done
if [ -z "${NOM}" -o -z "${PASS}" ] ; then
echo "You need to specify Username and Password" >&2
display_help >&2
exit 1
fi
if [ "${MESSAGE}" == "-" ] ; then
if [[ ! -t 0 ]]; then
while read line ; do
MESSAGE="${MESSAGE}%0D${line}"
MESSAGE=`echo ${MESSAGE} | sed 's|^-%0D||g'`
done < <(cat -)
else
echo "STDIN is empty" >&2
exit 1
fi
fi
if [ -z "${MESSAGE}" ] ; then
echo "You need to specify the message to send" >&2
display_help >&2
exit 1
fi
if ! which which > /dev/null 2>&1 ; then
echo "which is not installed"
exit 1
elif which curl > /dev/null 2>&1 ; then
echo using curl
BIN="curl -i --insecure"
elif which wget > /dev/null 2<&1 ; then
echo using wget
BIN="wget --save-headers -qO -"
elif true ; then
echo "None of curl or wget installed" >&2
exit 1
fi
envoi=$(${BIN} "https://smsapi.free-mobile.fr/sendmsg?user=${NOM}&pass=${PASS}&msg=${MESSAGE}" 2>&1)
retour_HTTP=$(echo "${envoi}" | awk '/HTTP/ {print $2}')
case $retour_HTTP in
200)
echo "Le message a été envoyé correctement"
;;
400)
echo "le couple expéditeur/mot de passe est erroné, veuillez les vérifier dans le script";;
402)
echo "Trop de SMS ont été envoyés en trop peu de temps. Veuillez renouveler ultérieurement";;
403)
echo "Le service nest pas activé sur lespace abonné. Veuillez l'activer S.V.P";;
500)
echo " Erreur côté serveur. Veuillez réessayez ultérieurement."
esac
exit 0