Commits

Evan Gates  committed 52d3ba2

looks like it finally works

  • Participants
  • Parent commits 377f951

Comments (0)

Files changed (1)

File extras/chat.sh

 #!/bin/sh
 
 # SERVERS should be a file with a list of "server nick" pairs with a list of
-# "fifo command" pairs for each. 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.
-# For example:
+# "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 :-)
+# For example, my $SERVERS file (nick and pass changed of course)
+#
 # <start of $SERVERS>
 # irc.oftc.net mynick
-# in /j nickserv identify mypass
-# nickserv/in /l
-# nickserv/in /l
-# in /j #somechannel
-# in /j #anotherchannel
-# #somechannel/in hello channel
+# in /j nickserv identify mypass w
+# in /j #ii
+# in /j #suckless
+# in /j #heresy
+# nickserv/in /l w
 #
-# localhost differentnick
-# &bitlbee/in identify diffpass
+# localhost mynick
+# &bitlbee/in identify mypass
 # &bitlbee/in blist
 # <EOF>
 #
-# TIP: note the "nickserv/in /l" twice, once identified nickserv tells you that
-#      you have been succesfully identifed, hence reopening the window if you
-#      have already closed it. True, this causes a race condition as nickserv
-#      may have already messages you before the first '/l'... but the waiting
-#      for a fifo loop now has a timeout :-)
+# TIP: note the use of 'w' both when identifying to nickserv and leaving
+#      nickserv. The first one is to give ii some time to connect, the second
+#      should wait until after nickserv replies to your identify, so you don't
+#      reopen a window when it does so. the "nickserv/in /l w" is at the end
+#      so I don't have to wait for that command before executing the others
 
 PREFIX="$HOME/irc"
 SERVERS="$PREFIX/servers"
 LOG="$PREFIX/log"
 
-[ -f "$LOG" ] && mv "$LOG" "$LOG.old"
+DELAY=10 # seconds to wait when we get a "w"
 
-
-pgrep -lf pcw >> "$LOG" 2>&1 && echo "WARNING: pcw already running" >> "$LOG"
+if pgrep -lf "pcw $PREFIX" >> "$LOG" 2>&1; then
+	echo "killing previous pcw" >> "$LOG"
+	pkill -f "pcw $PREFIX" 2>&1 >> "$LOG"
+fi
 pcw "$PREFIX" >> "$LOG" 2>&1 &
 
 while read line; do
 		commands="$commands;$line"
 	done
 
+	echo "starting $serv find log in $PREFIX/$serv/log"
 	while true; do
+		find "$PREFIX/$serv" | grep "in$" | xargs rm # clean stale fifos
 		IFS=";"
 		for line in $commands; do
 			[ -n "$line" ] || continue
 			fifo="${line%% *}"
 			cmd="${line#* }"
+			cmd="${cmd% w}"
+			printf "trying $cmd > $PREFIX/$serv/$fifo."
+
+			if echo "$line" | grep -q " w$"; then
+				printf " delay $DELAY seconds."
+				sleep $DELAY
+			fi
+				
 			# wait for the fifo to exist, don't want to make a normal file
 			i=0
 			while [ $i -lt 10 -a ! -p "$PREFIX/$serv/$fifo" ]; do
 				i=$((i + 1))
+				printf "."
 				sleep 1
 			done
 			if ! [ -p "$PREFIX/$serv/$fifo" ]; then
-				echo "WARNING: skipping $cmd > $PREFIX/$serv/$fifo: timed out"
+				echo "FAILED: timeout"
 				continue
 			fi
 			echo "$cmd" > "$PREFIX/$serv/$fifo"
-			echo "$cmd > $PREFIX/$serv/$fifo"
-		done >> "$LOG" 2>&1 & # background so we can start ii
+			echo "OK"
+		done >> "$PREFIX/$serv/log" 2>&1 & # background so we can start ii
 
 		ii -n "$nick" -s "$serv" -i "$PREFIX" 
 		[ $? -eq 2 ] || break # only restart ii on timeout (not default for ii)
-	done >> "$LOG" 2>&1 &
+	done >> "$PREFIX/$serv/log" 2>&1 & # instead of locking the main one...
 
 done < "$SERVERS" >> "$LOG" 2>&1