You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

siduction-irc 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. #!/bin/sh
  2. # Copyright (C) 2011-2015 Alf Gaida <agaida@siduction.org>
  3. # Copyright (C) 2005-2011 Stefan Lippers-Hollmann <s.l-h@gmx.de>
  4. # Copyright (C) 2005 Michiel Lieuwe de Boer
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # override tool behaviour through distro-defaults
  15. if [ -r /etc/default/distro ]; then
  16. . /etc/default/distro
  17. fi
  18. FLL_IRC_SERVER="irc.oftc.net"
  19. FLL_IRC_PORT="6667"
  20. if [ `echo $LANG | cut -c 1-3` = "de_" ]; then
  21. FLL_IRC_CHANNEL="#siduction-de"
  22. else
  23. FLL_IRC_CHANNEL="#siduction"
  24. fi
  25. FLL_DISTRO_NAME="siduction"
  26. # define user settings
  27. NICK="siducer$(mawk 'BEGIN{print int(1000 * rand())}')"
  28. XTERM_OPT="-e"
  29. # determine system status
  30. MKTEMP="$(which mktemp)" || MKTEMP="/bin/mktemp"
  31. SSFTSH="$(which ssft.sh)" || SSFTSH="/usr/bin/ssft.sh"
  32. SU="$(which su)" || SU="/bin/su"
  33. XTERMINAL="$(which x-terminal-emulator)" || XTERMINAL="/usr/bin/x-terminal-emulator"
  34. HEXCHAT="$(which hexchat)" || HEXCHAT="/usr/bin/hexchat"
  35. IRSSI="$(which irssi)" || IRSSI="/usr/bin/irssi"
  36. KONVERSATION="$(which konversation)" || KONVERSATION="/usr/bin/konversation"
  37. KVIRC="$(which kvirc)" || KVIRC="/usr/bin/kvirc"
  38. WEECHAT="$(which weechat-curses)" || WEECHAT="/usr/bin/weechat-curses"
  39. XCHAT="$(which xchat)" || XCHAT="/usr/bin/xchat"
  40. # internal functions
  41. irc_hexchat() {
  42. if [ ! -e "/home/$USER/.config/hexchat/hexchat.conf" ]; then
  43. mkdir -p /home/$USER/.config/hexchat
  44. touch /home/$USER/.config/hexchat/hexchat.conf
  45. echo "irc_nick1 = $NICK" >> /home/$USER/.config/hexchat/hexchat.conf
  46. echo "irc_nick2 = ${NICK}_" >> /home/$USER/.config/hexchat/hexchat.conf
  47. echo "irc_nick3 = ${NICK}__" >> /home/$USER/.config/hexchat/hexchat.conf
  48. echo "irc_user_name = $NICK" >> /home/$USER/.config/hexchat/hexchat.conf
  49. echo "irc_real_name = $NICK" >> /home/$USER/.config/hexchat/hexchat.conf
  50. echo "gui_tab_layout = 2" >> /home/$USER/.config/hexchat/hexchat.conf
  51. fi
  52. exec "$HEXCHAT" --url=irc://"$FLL_IRC_SERVER":"$FLL_IRC_PORT"/"$FLL_IRC_CHANNEL"
  53. }
  54. # internal functions
  55. fll_irssi() {
  56. TERM_TYPE="utf-8"
  57. #TERM_TYPE="8bit"
  58. IRSSICFG="$($MKTEMP -dp /tmp/ .irssi-XXXXXXXXXX)"
  59. CTCPS=0
  60. if [ -e /etc/siduction-version ]; then
  61. QUITMSG="$(cat /etc/siduction-version) | http://siduction.org"
  62. else
  63. QUITMSG="http://siduction.org"
  64. fi
  65. cat <<_EOF_ >"$IRSSICFG/config"
  66. servers = (
  67. {
  68. address = "$FLL_IRC_SERVER";
  69. chatnet = "oftc";
  70. port = "$FLL_IRC_PORT";
  71. autoconnect = "yes";
  72. }
  73. );
  74. chatnets = {
  75. oftc = {
  76. type = "IRC";
  77. max_kicks = "4";
  78. max_modes = "4";
  79. max_msgs = "1";
  80. max_whois = "1";
  81. };
  82. };
  83. channels = (
  84. { name = "$FLL_IRC_CHANNEL"; chatnet = "oftc"; autojoin = "yes"; }
  85. );
  86. _EOF_
  87. # See also special siduction aliases in here, like "/IBS", "/IBV", "/IB", "/GFX", "/SND", and "/X"
  88. cat <<"_EOF_" >>"$IRSSICFG/config"
  89. aliases = {
  90. J = "join";
  91. WJOIN = "join -window";
  92. WQUERY = "query -window";
  93. LEAVE = "part";
  94. BYE = "quit";
  95. EXIT = "quit";
  96. SIGNOFF = "quit";
  97. DESCRIBE = "action";
  98. DATE = "time";
  99. HOST = "userhost";
  100. LAST = "lastlog";
  101. SAY = "msg *";
  102. WI = "whois";
  103. WII = "whois $0 $0";
  104. WW = "whowas";
  105. W = "who";
  106. N = "names";
  107. M = "msg";
  108. T = "topic";
  109. C = "clear";
  110. CL = "clear";
  111. K = "kick";
  112. KB = "kickban";
  113. KN = "knockout";
  114. BANS = "ban";
  115. B = "ban";
  116. MUB = "unban *";
  117. UB = "unban";
  118. IG = "ignore";
  119. UNIG = "unignore";
  120. SB = "scrollback";
  121. UMODE = "mode $N";
  122. WC = "window close";
  123. WN = "window new hide";
  124. SV = "say Irssi $J ($V) - http://irssi.org/";
  125. GOTO = "sb goto";
  126. CHAT = "dcc chat";
  127. RUN = "SCRIPT LOAD";
  128. UPTIME = "eval exec - expr `date +%s` - \\$F | awk '{print \"Irssi uptime: \"int(\\\\\\$1/3600/24)\"d \"int(\\\\\\$1/3600%24)\"h \"int(\\\\\\$1/60%60)\"m \"int(\\\\\\$1%60)\"s\" }'";
  129. CALC = "exec - if which bc &>/dev/null\\; then echo '$*' | bc | awk '{print \"$*=\"$$1}'\\; else echo bc was not found\\; fi";
  130. SBAR = "STATUSBAR";
  131. INVITELIST = "mode $C +I";
  132. Q = "QUERY";
  133. QUIT = "foreach window /part;/quit";
  134. INXI = "/exec -o inxi $*";
  135. X = "QUIT";
  136. };
  137. statusbar = {
  138. # formats:
  139. # when using {templates}, the template is shown only if it's argument isn't
  140. # empty unless no argument is given. for example {sb} is printed always,
  141. # but {sb $T} is printed only if $T isn't empty.
  142. items = {
  143. # start/end text in statusbars
  144. barstart = "{sbstart}";
  145. barend = "{sbend}";
  146. topicbarstart = "{topicsbstart}";
  147. topicbarend = "{topicsbend}";
  148. # treated "normally", you could change the time/user name to whatever
  149. time = "{sb $Z}";
  150. user = "{sb {sbnickmode $cumode}$N{sbmode $usermode}{sbaway $A}}";
  151. # treated specially .. window is printed with non-empty windows,
  152. # window_empty is printed with empty windows
  153. window = "{sb $winref:$itemname{sbmode $M}}";
  154. window_empty = "{sb $winref{sbservertag $tag}}";
  155. prompt = "{prompt $[.15]itemname}";
  156. prompt_empty = "{prompt $winname}";
  157. topic = " $topic";
  158. topic_empty = " Irssi v$J - http://irssi.org/help/";
  159. # all of these treated specially, they're only displayed when needed
  160. lag = "{sb Lag: $0-}";
  161. act = "{sb Act: $0-}";
  162. more = "-- more --";
  163. };
  164. # there's two type of statusbars. root statusbars are either at the top
  165. # of the screen or at the bottom of the screen. window statusbars are at
  166. # the top/bottom of each split window in screen.
  167. default = {
  168. # the "default statusbar" to be displayed at the bottom of the window.
  169. # contains all the normal items.
  170. window = {
  171. disabled = "no";
  172. # window, root
  173. type = "window";
  174. # top, bottom
  175. placement = "bottom";
  176. # number
  177. position = "1";
  178. # active, inactive, always
  179. visible = "active";
  180. # list of items in statusbar in the display order
  181. items = {
  182. barstart = { priority = "100"; };
  183. time = { };
  184. user = { };
  185. window = { };
  186. window_empty = { };
  187. lag = { priority = "-1"; };
  188. act = { priority = "10"; };
  189. more = { priority = "-1"; alignment = "right"; };
  190. barend = { priority = "100"; alignment = "right"; };
  191. };
  192. };
  193. # statusbar to use in inactive split windows
  194. window_inact = {
  195. type = "window";
  196. placement = "bottom";
  197. position = "1";
  198. visible = "inactive";
  199. items = {
  200. barstart = { priority = "100"; };
  201. window = { };
  202. window_empty = { };
  203. more = { priority = "-1"; alignment = "right"; };
  204. barend = { priority = "100"; alignment = "right"; };
  205. };
  206. };
  207. # we treat input line as yet another statusbar :) It's possible to
  208. # add other items before or after the input line item.
  209. prompt = {
  210. type = "root";
  211. placement = "bottom";
  212. # we want to be at the bottom always
  213. position = "100";
  214. visible = "always";
  215. items = {
  216. prompt = { priority = "-1"; };
  217. prompt_empty = { priority = "-1"; };
  218. # treated specially, this is the real input line.
  219. input = { priority = "10"; };
  220. };
  221. };
  222. # topicbar
  223. topic = {
  224. type = "root";
  225. placement = "top";
  226. position = "1";
  227. visible = "always";
  228. items = {
  229. topicbarstart = { priority = "100"; };
  230. topic = { };
  231. topic_empty = { };
  232. topicbarend = { priority = "100"; alignment = "right"; };
  233. };
  234. };
  235. };
  236. };
  237. _EOF_
  238. cat <<_EOF_ >>"$IRSSICFG/config"
  239. settings = {
  240. core = {
  241. real_name = "siduction user";
  242. user_name = "siducer";
  243. nick = "$NICK";
  244. quit_message = "$QUITMSG";
  245. };
  246. "irc/core" = { part_message = "$QUITMSG"; };
  247. "irc/dcc" = {
  248. dcc_upload_path = "/tmp";
  249. dcc_download_path = "/tmp";
  250. dcc_autoget = "no";
  251. dcc_autochat_masks = "*";
  252. dcc_autoget_masks = "= *";
  253. };
  254. "fe-text" = { term_type = "$TERM_TYPE"; };
  255. "fe-common/core" = { completion_char = ","; };
  256. };
  257. logs = { };
  258. windows = {
  259. 2 = {
  260. items = (
  261. {
  262. type = "CHANNEL";
  263. chat_type = "IRC";
  264. name = "$FLL_IRC_CHANNEL";
  265. tag = "oftc";
  266. }
  267. );
  268. };
  269. 1 = { immortal = "yes"; name = "(status)"; level = "ALL"; };
  270. };
  271. mainwindows = { 2 = { first_line = "1"; lines = "47"; }; };
  272. _EOF_
  273. [ "$CTCPS" -eq 0 ] && echo 'ignores = ( { level = "CTCPS"; } );' >>"$IRSSICFG/config"
  274. "$IRSSI" --home="$IRSSICFG"
  275. RETC="$?"
  276. rm -rf "$IRSSICFG"
  277. [ "$RETC" -ne 0 ] && return 127 || exit 0
  278. }
  279. # internal functions
  280. irc_konversation() {
  281. # we test if konversation was started and if not it will start as in live mode
  282. # if it was started it finds user configured nick and it will use it
  283. if [ ! -d /home/$USER/logs ]; then
  284. exec "$KONVERSATION" --server "$FLL_IRC_SERVER" --port "$FLL_IRC_PORT" --channel "$FLL_IRC_CHANNEL" --nick "$NICK"
  285. else
  286. USER_NICK=$(fgrep Nick /home/$USER/logs/oftc_#siduction.log | tail -n1 | awk '{print $13}' | cut -d . -f1)
  287. if [ "X${USER_NICK}" != "X" ] ; then
  288. sed -i "s@^Nicknames=.*@Nicknames=$USER_NICK,${USER_NICK}_,${USER_NICK}__@" /home/$USER/.kde/share/config/konversationrc
  289. else
  290. if [ "$FLL_DISTRO_MODE" = "installed" ]; then
  291. sed -i "s@^Nicknames=.*@Nicknames=$USER,${USER}_,${USER}__@" /home/$USER/.kde/share/config/konversationrc
  292. else
  293. sed -i "s@^Nicknames=.*@Nicknames=$NICK,${NICK}_,${NICK}__@" /home/$USER/.kde/share/config/konversationrc
  294. fi
  295. fi
  296. exec "$KONVERSATION" --server "$FLL_IRC_SERVER" --port "$FLL_IRC_PORT" --channel "$FLL_IRC_CHANNEL"
  297. fi
  298. }
  299. irc_kvirc() {
  300. if [ "$FLL_DISTRO_MODE" != "installed" ]; then
  301. if [ -e "/home/$USER/.config/KVIrc/config/serverdb.kvc" ]; then
  302. rm -f /home/$USER/.config/KVIrc/config/serverdb.kvc
  303. touch /home/$USER/.config/KVIrc/config/serverdb.kvc
  304. else
  305. mkdir -p /home/$USER/.config/KVIrc/config/
  306. touch /home/$USER/.config/KVIrc/config/serverdb.kvc
  307. fi
  308. cat << _EOF_ >> "/home/$USER/.config/KVIrc/config/serverdb.kvc"
  309. [OFTC]
  310. 0_Port=$FLL_IRC_PORT
  311. 0_Hostname=$FLL_IRC_SERVER
  312. 0_Nick=$NICK
  313. NServers=1
  314. 0_AutoConnect=true
  315. 0_Pass=
  316. 0_OnLoginCommand=
  317. 0_Description=main%20OFTC.net%20server
  318. 0_SSL=false
  319. 0_AutoJoinChannels=$FLL_IRC_CHANNEL
  320. 0_Id=myserver942982771597
  321. 0_RealName=$NICK
  322. 0_User=$NICK
  323. 0_AlternativeNick=${NICK}_
  324. _EOF_
  325. fi
  326. exec "$KVIRC" --nosplash
  327. }
  328. # internal functions
  329. irc_xchat() {
  330. if [ ! -e "/home/$USER/.xchat2/xchat.conf" ]; then
  331. mkdir -p /home/$USER/.xchat2
  332. touch /home/$USER/.xchat2/xchat.conf
  333. echo "irc_nick1 = $NICK" >> /home/$USER/.xchat2/xchat.conf
  334. echo "irc_nick2 = ${NICK}_" >> /home/$USER/.xchat2/xchat.conf
  335. echo "irc_nick3 = ${NICK}__" >> /home/$USER/.xchat2/xchat.conf
  336. echo "irc_user_name = $NICK" >> /home/$USER/.xchat2/xchat.conf
  337. echo "irc_real_name = $NICK" >> /home/$USER/.xchat2/xchat.conf
  338. echo "tab_layout = 0" >> /home/$USER/.xchat2/xchat.conf
  339. fi
  340. exec "$XCHAT" --url=irc://"$FLL_IRC_SERVER":"$FLL_IRC_PORT"/"$FLL_IRC_CHANNEL"
  341. }
  342. # internal functions
  343. irc_check_environ() {
  344. use_xchat=0
  345. case "${XDG_CURRENT_DESKTOP}" in
  346. "KDE")
  347. use_konversation=1
  348. ;;
  349. *)
  350. use_hexchat=1
  351. ;;
  352. esac
  353. }
  354. ##############################################################################
  355. # int main(void); #
  356. ##############################################################################
  357. # yes, this stuff is elementary
  358. if [ -z "$DISPLAY" ]; then
  359. for i in "$SSFTSH" "$SU"; do
  360. if [ ! -x "$i" ]; then
  361. echo "$i: missing, terminate abnormally" 1>&2
  362. exit 999
  363. fi
  364. done
  365. else
  366. for i in "$SSFTSH" "$XTERMINAL" "$SU"; do
  367. if [ ! -x "$i" ]; then
  368. echo "$i: missing, terminate abnormally" 1>&2
  369. exit 998
  370. fi
  371. done
  372. fi
  373. if [ "$1" = "--tty" ]; then
  374. DISPLAY=""
  375. fi
  376. # initialize ssft
  377. . "$SSFTSH"
  378. [ -n "$SSFT_FRONTEND" ] || SSFT_FRONTEND="$(ssft_choose_frontend)"
  379. # are you insane?
  380. if [ "`id -u`" = "0" ]; then
  381. echo "ROOOOOOOOOOOOT has landed!" 1>&2
  382. echo "" 1>&2
  383. echo "Don't ever call any IRC client as root" 1>&2
  384. if [ -n "$DISPLAY" ]; then
  385. ssft_display_message "ERROR" "ROOOOOOOOOOOOT has landed!\n\nDon't ever call any IRC client as root"
  386. fi
  387. exit 996
  388. fi
  389. # choose your nick
  390. if [ "$FLL_DISTRO_MODE" != "installed" ]; then
  391. SSFT_DEFAULT="$NICK"
  392. ssft_read_string "${FLL_DISTRO_NAME} IRC Chat" "Choose your nick" || exit 0
  393. NICK="$SSFT_RESULT"
  394. fi
  395. # try to start your irc client
  396. irc_check_environ
  397. if [ -z "$DISPLAY" ]; then
  398. # tty
  399. if [ -x "$IRSSI" ]; then
  400. fll_irssi
  401. exit "$?"
  402. fi
  403. [ -x "$WEECHAT" ] && exec $WEECHAT "irc://$NICK@$FLL_IRC_SERVER:$FLL_IRC_PORT/$FLL_IRC_CHANNEL"
  404. else
  405. # X11
  406. [ -x "$HEXCHAT" ] && [ "$use_hexchat" = "1" ] && irc_hexchat
  407. [ -x "$KONVERSATION" ] && [ "$use_konversation" = "1" ] && irc_konversation
  408. [ -x "$KVIRC" ] && irc_kvirc
  409. [ -x "$XCHAT" ] && irc_xchat
  410. # nasty fallback, but well - it works ;)
  411. TERMPATH=$(readlink -f /etc/alternatives/x-terminal-emulator)
  412. TERM=$(basename ${TERMPATH})
  413. if [ "x${TERM}" = "xurxvt" ]; then
  414. exec ${XTERMINAL} ${XTERM_OPT} $0 --tty
  415. else
  416. exec $XTERMINAL $XTERM_OPT "$0 --tty"
  417. fi
  418. fi
  419. # Oops...
  420. echo "ERROR: failed to start any suitable IRC Client" 1>&2
  421. for i in "$HEXCHAT" "$IRSSI" "$KONVERSATION" "$KVIRC" "$SSFTSH" "$WEECHAT" "$XCHAT"; do
  422. if [ -x "$i" ]; then
  423. echo "$i: found."
  424. else
  425. echo "$i: NOT found." 1>&2
  426. fi
  427. done