ChCh Öffnungsstatus: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Florz (Diskussion | Beiträge) Script findet das alte Topic jetzt zuverlässiger |
||
Zeile 19: | Zeile 19: | ||
IRC_CHANNEL="#chaoschemnitz" | IRC_CHANNEL="#chaoschemnitz" | ||
IRC_SERVER="irc.freenode.net" | IRC_SERVER="irc.freenode.net" | ||
PASSWORD="xxxxxxxxxxxxxxxxxxxxxxx" | |||
ON_MSG="Wir haben geöffnet." | ON_MSG="Wir haben geöffnet." | ||
OFF_MSG="Wir schließen jetzt." | OFF_MSG="Wir schließen jetzt." | ||
Zeile 34: | Zeile 35: | ||
CAT=/bin/cat | CAT=/bin/cat | ||
CUT=/usr/bin/cut | CUT=/usr/bin/cut | ||
TAIL=/usr/bin/tail | TAIL=/usr/bin/tail | ||
GREP=/bin/grep | GREP=/bin/grep | ||
SED=/bin/sed | SED=/bin/sed | ||
Zeile 40: | Zeile 41: | ||
MV=/bin/mv | MV=/bin/mv | ||
PS=/bin/ps | PS=/bin/ps | ||
SLEEP=/bin/sleep | SLEEP=/bin/sleep | ||
II=/usr/bin/ii | II=/usr/bin/ii | ||
################# | |||
################# | |||
IRC_CHAN_IN=$IRC_PREFIX/$IRC_SERVER/$IRC_CHANNEL/in | IRC_CHAN_IN=$IRC_PREFIX/$IRC_SERVER/$IRC_CHANNEL/in | ||
Zeile 50: | Zeile 50: | ||
IRC_SRV_OUT=$IRC_PREFIX/$IRC_SERVER/out | IRC_SRV_OUT=$IRC_PREFIX/$IRC_SERVER/out | ||
II_RUNNING=$($PS awx | $GREP "ii" | $GREP "\-n $IRC_USER") | II_RUNNING=$($PS awx | $GREP "ii" | $GREP "\-n $IRC_USER") | ||
II_RESTARTED=0 | |||
RING=$($CAT /proc/tty/driver/serial | $GREP "$PORT" | $GREP -o "RI") | RING=$($CAT /proc/tty/driver/serial | $GREP "$PORT" | $GREP -o "RI") | ||
Zeile 66: | Zeile 67: | ||
exit 1 | exit 1 | ||
fi | fi | ||
II_RESTARTED=1 | |||
fi | fi | ||
Zeile 73: | Zeile 75: | ||
fi | fi | ||
if [ ! -e $IRC_CHAN_OUT ]; then | if [ ! -e $IRC_CHAN_OUT ] || [ $II_RESTARTED -eq 1 ] ; then | ||
TMP=$JOIN_TIMEOUT | TMP=$JOIN_TIMEOUT | ||
while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do | while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do | ||
Zeile 90: | Zeile 92: | ||
exit 1 | exit 1 | ||
fi | fi | ||
sleep 10 | |||
$ECHO -e "/j ChanServ op $IRC_CHANNEL\n" > $IRC_SRV_IN | |||
fi | fi | ||
Zeile 96: | Zeile 101: | ||
$TAIL -n 300 $IRC_SRV_OUT > ${IRC_SRV_OUT}_tmp | $TAIL -n 300 $IRC_SRV_OUT > ${IRC_SRV_OUT}_tmp | ||
$MV ${IRC_SRV_OUT}_tmp $IRC_SRV_OUT | $MV ${IRC_SRV_OUT}_tmp $IRC_SRV_OUT | ||
CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $GREP -v "[[:alnum:]]*!~[[:alnum:]]*@" | $TAIL -n1 | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I") | #CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $GREP -v "[[:alnum:]]*!~[[:alnum:]]*@" | $TAIL -n1 | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I") | ||
CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I" | $GREP -ve "^[^![:space:]]\+![^@[:space:]]\+@\S\+\s\+[0-9]\+" | $TAIL -n1 ) | |||
CURRENT_STATUS=$($ECHO $CURRENT_TOPIC | $GREP -oe "$ON_TOPIC$\|$OFF_TOPIC$") | CURRENT_STATUS=$($ECHO $CURRENT_TOPIC | $GREP -oe "$ON_TOPIC$\|$OFF_TOPIC$") | ||
if [ ! -z "$CURRENT_STATUS" ]; then | if [ ! -z "$CURRENT_STATUS" ]; then |
Version vom 17. Februar 2014, 16:12 Uhr
Dieses Script wird einmal in der Minute gestartet und prüft das Ring-Signal der seriellen Schnittstelle. Wenn unsere Außenbeleuchtung eingeschaltet wird, gibt es dies im IRC bekannt. Ebenso gibt es das Ausschalten bekannt.
-| |+ ______ ______ Zuleitung | | .-|______|-o-->|--o-|______|-. R1=R2=1k LED-Leucht- | o--' R1 | D1 | R3 | R3=10k reklame o-|--. ______ | | +C1- | C1=47µ (ChCh) | | o-|______|-' o----||----o--Pin 5 (GND) | | | R2 '----------|--Pin 9 (RI) | | '----------------------------'
Der Schriftzug besteht aus einer blauen LED-Lichterkette, die von einer gelochten Kunststoffkonstruktion in Form gehalten wird. Das Netzteil liefert 24V Wechselspannung, welche jedoch im Stecker der Lichterkette (Zusätzlicher Stecker zwischen Netzteil und Zuleitung der Lichterkette) teilweise gleichgerichtet wird. Die oben dargestellte Schaltung halbiert und glättet die Spannung, so dass diese direkt am Seriellen Anschluss eines PCs ausgewertet werden kann.
#! /bin/bash # USER CONFIG # IRC_USER="chch" IRC_CHANNEL="#chaoschemnitz" IRC_SERVER="irc.freenode.net" PASSWORD="xxxxxxxxxxxxxxxxxxxxxxx" ON_MSG="Wir haben geöffnet." OFF_MSG="Wir schließen jetzt." ON_TOPIC=" | Status: geöffnet" OFF_TOPIC=" | Status: geschlossen" STATUS_FILE="/home/chch-status/status" ############### # SYSTEM CONFIG # II_START_TIMEOUT=10 JOIN_TIMEOUT=10 IRC_PREFIX=/var/irc PORT="port:000003F8" CAT=/bin/cat CUT=/usr/bin/cut TAIL=/usr/bin/tail GREP=/bin/grep SED=/bin/sed ECHO=/bin/echo MV=/bin/mv PS=/bin/ps SLEEP=/bin/sleep II=/usr/bin/ii ################# IRC_CHAN_IN=$IRC_PREFIX/$IRC_SERVER/$IRC_CHANNEL/in IRC_CHAN_OUT=$IRC_PREFIX/$IRC_SERVER/$IRC_CHANNEL/out IRC_SRV_IN=$IRC_PREFIX/$IRC_SERVER/in IRC_SRV_OUT=$IRC_PREFIX/$IRC_SERVER/out II_RUNNING=$($PS awx | $GREP "ii" | $GREP "\-n $IRC_USER") II_RESTARTED=0 RING=$($CAT /proc/tty/driver/serial | $GREP "$PORT" | $GREP -o "RI") # RESTART II if [ -z "$II_RUNNING" ]; then $II -n $IRC_USER -i $IRC_PREFIX -k $PASSWORD & while [ $II_START_TIMEOUT -ge 0 -a ! -e $IRC_SRV_IN ]; do II_START_TIMEOUT=$(($II_START_TIMEOUT-1)) $SLEEP 1 done if [ $II_START_TIMEOUT -lt 0 -a ! -e $IRC_SRV_IN ]; then exit 1 fi $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN if [ $? -ne 0 ]; then exit 1 fi II_RESTARTED=1 fi $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN if [ $? -ne 0 ]; then exit 1 fi if [ ! -e $IRC_CHAN_OUT ] || [ $II_RESTARTED -eq 1 ] ; then TMP=$JOIN_TIMEOUT while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do JOIN_TIMEOUT=$(($JOIN_TIMEOUT-1)) $SLEEP 1 done if [ $JOIN_TIMEOUT -lt 0 -a ! -e $IRC_CHAN_OUT ]; then $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN fi JOIN_TIMEOUT=$TMP while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do JOIN_TIMEOUT=$(($JOIN_TIMEOUT-1)) $SLEEP 1 done if [ $JOIN_TIMEOUT -lt 0 -a ! -e $IRC_CHAN_OUT ]; then exit 1 fi sleep 10 $ECHO -e "/j ChanServ op $IRC_CHANNEL\n" > $IRC_SRV_IN fi # FIND OUR LAST STATUS MESSAGE PREV_MSG=$($CAT $IRC_CHAN_OUT | $CUT -d":" -f2 | $GREP -e "^[0-9]\{2\} <$IRC_USER> $ON_MSG\$\|^[0-9]\{2\} <$IRC_USER> $OFF_MSG\$" | $TAIL -n1 | $GREP -oe "$ON_MSG\|$OFF_MSG") $TAIL -n 300 $IRC_SRV_OUT > ${IRC_SRV_OUT}_tmp $MV ${IRC_SRV_OUT}_tmp $IRC_SRV_OUT #CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $GREP -v "[[:alnum:]]*!~[[:alnum:]]*@" | $TAIL -n1 | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I") CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I" | $GREP -ve "^[^![:space:]]\+![^@[:space:]]\+@\S\+\s\+[0-9]\+" | $TAIL -n1 ) CURRENT_STATUS=$($ECHO $CURRENT_TOPIC | $GREP -oe "$ON_TOPIC$\|$OFF_TOPIC$") if [ ! -z "$CURRENT_STATUS" ]; then CURRENT_TOPIC=$($ECHO $CURRENT_TOPIC | $SED -e "s/$CURRENT_STATUS//") fi # CHOOSE CORRECT MESSAGE AND TOPIC if [ -z "$RING" ]; then MSG="$OFF_MSG" TOPIC="$OFF_TOPIC" else MSG="$ON_MSG" TOPIC="$ON_TOPIC" fi $ECHO -e $TOPIC | $CUT -d: -f2 | $SED -e "s/^[[:space:]]*//" > $STATUS_FILE if [ ! -z "$CURRENT_TOPIC" ]; then # SEND MESSAGE IF IT DIFFERS FROM PREVIOUS STATUS if [ "$MSG" != "$PREV_MSG" ]; then $ECHO -e "$MSG\n" > $IRC_CHAN_IN fi # SET TOPIC IF IT DIFFERS FROM PREVIOUS ONE if [ "$TOPIC" != "$CURRENT_STATUS" ]; then $ECHO -e "/t $CURRENT_TOPIC$TOPIC\n" > $IRC_CHAN_IN fi if [ $? -ne 0 ]; then exit 1 fi else exit 1 fi