Commits

Anonymous committed 70d461a

some cleanup for chat.sh and change syntax so you can specify ii arguments in servers file

Comments (0)

Files changed (1)

 #!/bin/sh
 
-# SERVERS should be a file with a list of "server nick" pairs with a list of
-# "fifo command" pairs for each. If a line ends with a "w" we wait a few
-# seconds before executing it. Each server block should be separated by a new
-# line. I do not do any error checking for you, don't screw up the format. I
-# never claimed this was pretty, just that it works for me :-)
+# SERVERS should be a file with a list of servers, each followed by the ii
+# command line for that server (except the -s because we start with the server)
+# A -i prefix argument will override the one provided here, useful if you want
+# a specific server somehwere other than the given hierarchy, but it should be
+# noted that the fifo path will still be relative to $PREFIX/$serv/. There are
+# then a list of "fifo command" pairs for each server. If a line ends with a "w"
+# we wait a few seconds before executing it (default 10). Each server block
+# should be separated by a new line. The commands for a given server are
+# performed in serial, and each block runs in parallel. I do not do any error
+# checking for you, so don't screw up the format. I never claimed this was
+# pretty, just that it works for me :-)
 # For example, my $SERVERS file (nick and pass changed of course)
 #
 # <start of $SERVERS>
-# irc.oftc.net mynick
+# irc.oftc.net -n mynick -m 12
 # in /j nickserv identify mypass w
 # in /j #ii
 # in /j #suckless
 # in /j #heresy
 # nickserv/in /l w
 #
-# localhost mynick
+# localhost -n mynick -m 12 -p 13245
 # &bitlbee/in identify mypass
 # &bitlbee/in blist w
 # <EOF>
 
 DELAY=10 # seconds to wait when we get a "w"
 
-if pgrep -lf "pcw $PREFIX" >> "$LOG" 2>&1; then
-	echo "killing previous pcw" >> "$LOG"
-	pkill -f "pcw $PREFIX" 2>&1 >> "$LOG"
-fi
+{
+	echo
+	date
+
+	if pgrep -lf "pcw $PREFIX"; then
+		echo "killing previous pcw"
+		pkill -f "pcw $PREFIX"
+	fi
+} >> "$LOG" 2>&1
+
+# not inside ^that block because it needs to be run in the background
 which pcw > /dev/null 2>&1 && pcw "$PREFIX" >> "$LOG" 2>&1 &
 
 while read line; do
+	args="$line"
 	serv="${line%% *}"
-	nick="${line#* }"
 	commands=
 	while read line; do
 		[ -n "$line" ] || break #stop on empty line
 	echo "find log in $PREFIX/$serv/log"
 	echo "commands $commands"
 
+	{
+		echo
+		date
+		echo "ii -i $PREFIX -s $args"
+	} >> "$PREFIX/$serv/log" 2>&1
+
 	while true; do
 		find "$PREFIX/$serv" | grep "in$" | xargs rm # clean stale fifos
 		IFS=";"
 			echo "OK"
 		done >> "$PREFIX/$serv/log" 2>&1 & # background so we can start ii
 
-		ii -n "$nick" -s "$serv" -i "$PREFIX" 
+		IFS=
+		ii -i "$PREFIX" -s $args
 		[ $? -eq 2 ] || break # only restart ii on timeout (not default for ii)
 	done >> "$PREFIX/$serv/log" 2>&1 & # instead of locking the main one...