-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconnect.sh
executable file
·51 lines (38 loc) · 1.13 KB
/
connect.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env sh
: "${ircdir:=$HOME/irc}"
: "${nick:=$USER}"
# server info functions
freenode() {
server='irc.freenode.net'
channels="#foo #bar"
}
oftc() {
server='irc.oftc.net'
channels="#xyz #abc"
}
# these match the functions above
networks="freenode oftc"
# some privacy please, thanks
chmod 700 "$ircdir"
chmod 600 "$ircdir"/*/ident &>/dev/null
for network in $networks; do
unset server channels port
"$network" # set the appropriate vars
while true; do
# cleanup
rm -f "$ircdir/$server/in"
# connect to netwrok -- password is set through the env var synonym to the network name
iim -i "$ircdir" -n "$nick" -k "$network" -s "$server" -p "${port:-6667}" &
pid="$!"
# wait for the connection
while ! test -p "$ircdir/$server/in"; do sleep .3; done
# auth to services
if [ -e "$ircdir/$server/ident" ]
then printf "/j nickserv identify %s\n" "$(cat "$ircdir/$server/ident")" > "$ircdir/$server/in"
fi && rm -f "$ircdir/$server/nickserv/out" # clean that up - ident passwd is in there
# join channels
printf "/j %s\n" $channels > "$ircdir/$server/in"
# if connection is lost reconnect
wait "$pid"
done &
done