dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

notify (2107B)


      1 #!/bin/sh
      2 #
      3 # notify.sh - use irc to send a notice
      4 #
      5 # hayden@haydenvh.com
      6 # Copyright (c) 2020 Hayden Hamilton
      7 #
      8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     11 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     12 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     13 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     14 # SOFTWARE.
     15 #
     16 # This work is free. You can redistribute it and/or modify it under the
     17 # terms of the Do What The Fuck You Want To Public License, Version 2,
     18 # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
     19 
     20 usage(){
     21 	cat << .
     22 * = required
     23 
     24 stdin* (message(s) to send)
     25 
     26 options:
     27 	--server*
     28 	--port*
     29 	--channel*
     30 	--nick*
     31 	--password
     32 	--tls
     33 .
     34 	exit 1
     35 }
     36 
     37 
     38 while [ $# != 0 ]
     39 do
     40 	num=2
     41 	case $1 in
     42 		-s|--server)             server="$2"  ;;
     43 		-p|--port)               port="$2"    ;;
     44 		-c|--channel)            channel="$2" ;;
     45 		-n|--nick)               nick="$2"    ;;
     46 		-P|--passwd|--password)  passwd="$2"  ;;
     47 		-S|--ssl|-t|--tls)       tls=y; num=1 ;;
     48 		*)                       usage        ;;
     49 	esac
     50 	shift $num
     51 done
     52 
     53 [ -z $server ] || [ -z $port ] || [ -z $channel ] || [ -z $nick ] && usage
     54 
     55 tmp=$(mktemp)
     56 msg=$(mktemp)
     57 cp /dev/stdin $msg
     58 
     59 [ -z $passwd ] && {
     60 	printf "NICK $nick\r\nUSER $nick $nick $nick $nick\r\n" > $tmp
     61 } || {
     62 	printf "NICK $nick\r\nUSER $nick $nick $nick $nick\r\nPASS $passwd\r\n" > $tmp
     63 }
     64 
     65 (
     66 	[ -z $tls ] && {
     67 		tail -f $tmp | nc $server $port
     68 	} || {
     69 		tail -f $tmp | openssl s_client -connect $server:$port
     70 	}
     71 ) | \
     72 	tee /dev/stderr | while IFS= read -r line
     73 	do
     74 		set -- $line
     75 		case "$@" in
     76 			"PING"*) printf "PONG $2\r\n" ;;
     77 			*"MOTD"*|*"Message of The Day"*)
     78 				printf "JOIN $channel\r\n"
     79 				awk -v "channel=$channel" '{printf("PRIVMSG %s %s\r\n", channel, $0)}' < $msg
     80 				printf "QUIT done\r\n"
     81 				rm $msg $tmp
     82 				exit
     83 				;;
     84 		esac
     85 	done | tee /dev/stderr >> $tmp