From 76537b041c4aae17ed4b30580f3a41d2248a91f2 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 17 Oct 2015 13:53:08 +0200
Subject: [PATCH] On server, replace screen/irssi with tmux/weechat/bitlbee.

---
 bin/weechat-wrapper.sh            |  8 ++++++++
 dotfiles_user_server/bashrc       |  3 +++
 dotfiles_user_server/weechatrc    | 10 ++++++++++
 jessie_start_server.sh            | 22 +++++++++++++++-------
 mails/server_postinstall_finished |  6 ++++++
 mails/weechat_restart_reminder    |  5 +++++
 systemfiles/weechat.service       | 12 ++++++++++++
 7 files changed, 59 insertions(+), 7 deletions(-)
 create mode 100755 bin/weechat-wrapper.sh
 create mode 100644 dotfiles_user_server/weechatrc
 create mode 100644 mails/weechat_restart_reminder
 create mode 100644 systemfiles/weechat.service

diff --git a/bin/weechat-wrapper.sh b/bin/weechat-wrapper.sh
new file mode 100755
index 0000000..333c9d1
--- /dev/null
+++ b/bin/weechat-wrapper.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Enforce ~/.weechatrc as sole persistent weechat config file.
+~/config/bin/simplemail.sh ~/config/mails/weechat_restart_reminder
+rm -rf ~/.weechat/
+WEECHATCONF=`tr '\n' ';' < ~/.weechatrc`
+weechat -r "$WEECHATCONF"
+rm -rf ~/.weechat/
diff --git a/dotfiles_user_server/bashrc b/dotfiles_user_server/bashrc
index 2f21e27..8037b1b 100644
--- a/dotfiles_user_server/bashrc
+++ b/dotfiles_user_server/bashrc
@@ -3,6 +3,9 @@
 # Fancy colors for ls.
 alias ls="ls --color=auto"
 
+# Wrapper for weechat to force local config file on it anew on each run.
+alias weechat="~/config/bin/weechat-wrapper.sh"
+
 # Blue prompt with time.
 PS1="\[\e[1;34m\][\\t \\u@\\h \\w]$\[\e[m\] "
 PS2="\[\e[1;34m\]>\[\e[m\] "
diff --git a/dotfiles_user_server/weechatrc b/dotfiles_user_server/weechatrc
new file mode 100644
index 0000000..3b7fe91
--- /dev/null
+++ b/dotfiles_user_server/weechatrc
@@ -0,0 +1,10 @@
+/set logger.file.path ~/weechatlogs
+/set logger.file.flush_delay 0
+/script install otr.py
+/set weechat.bar.status.items "[time],[buffer_last_number],[buffer_plugin],buffer_number+:+buffer_name+(buffer_modes)+{buffer_nicklist_count}+buffer_zoom+buffer_filter,[lag],[hotlist],completion,scroll,[otr]"
+/server add localhost localhost
+/connect localhost
+/server del freenode
+/server add freenode irc.freenode.net -nicks=plomlompom,plomlomp0m,ploml0mp0m,pl0ml0mp0m -realname="Christian Heller" 
+#/server add freenode irc.freenode.net -nicks=plomlompom,plomlomp0m,ploml0mp0m,pl0ml0mp0m -realname="Christian Heller" -autojoin=#nodrama.de,#twitter.de,#freie-gesellschaft,#dumme-gesellschaft
+/connect freenode
diff --git a/jessie_start_server.sh b/jessie_start_server.sh
index a764ef5..e58f760 100755
--- a/jessie_start_server.sh
+++ b/jessie_start_server.sh
@@ -103,16 +103,24 @@ service postfix restart
 apt-get -y install cron
 su plom -c "echo '0 18 * * 0 ~/config/bin/simplemail.sh ~/config/mails/update_reminder' | crontab -"
 
-# Set up screen.
-apt-get -y install screen
+# Set up tmux.
+apt-get -y install tmux
 
-# Set up ping.
-apt-get -y install iputils-ping
+# Set up weechat, OTR, bitlbee.
+apt-get install weechat-plugins python-potr bitlbee
+cp config/systemfiles/weechat /etc/systemd/system/weechat.service
+systemctl enable /etc/systemd/system/weechat.service
 
+# Set up screen.
+#apt-get -y install screen
+#
+# Set up ping.
+#apt-get -y install iputils-ping
+#
 # Set up irssi.
-apt-get -y install irssi
-cp config/systemfiles/irssi.service /etc/systemd/system/irssi.service
-systemctl enable /etc/systemd/system/irssi.service
+#apt-get -y install irssi
+#cp config/systemfiles/irssi.service /etc/systemd/system/irssi.service
+#systemctl enable /etc/systemd/system/irssi.service
 
 # Clean up.
 rm jessie_start_server.sh
diff --git a/mails/server_postinstall_finished b/mails/server_postinstall_finished
index 45b82c1..d5d9741 100644
--- a/mails/server_postinstall_finished
+++ b/mails/server_postinstall_finished
@@ -11,3 +11,9 @@ perform the following tasks:
 - run (as root) config/setup_opendkim.sh $selector to set up system for DKIM key
   signing, with a second parameter $keyfile if a key already exists; without
   second parameter, this will generate a new key and print the DNS record to add
+
+- in the tmux weechat/bitlbee session (run "tmux attach"), switch to the
+  &bitlbee channel, register with a password ("register", "/oper . [password]"),
+  and set up Jabber account with password ("account add jabber
+  plomlompom@jabber.ccc.de", "/oper . [password]"), then activate it ("account
+  on")
diff --git a/mails/weechat_restart_reminder b/mails/weechat_restart_reminder
new file mode 100644
index 0000000..3aecea2
--- /dev/null
+++ b/mails/weechat_restart_reminder
@@ -0,0 +1,5 @@
+[SYSADMIN] weechat restarted, re-identify!
+
+Your weechat was restarted, so don't forget to re-identify on freenode to
+nickserv via "/msg nickserv identify [password]", and on bitlbee by joining
+&bitlbee, "identify", "/oper . [password]", and "account on".
diff --git a/systemfiles/weechat.service b/systemfiles/weechat.service
new file mode 100644
index 0000000..fbf4b78
--- /dev/null
+++ b/systemfiles/weechat.service
@@ -0,0 +1,12 @@
+# /etc/systemd/system/weechat.service
+
+[Unit]
+Description=tmux weechat
+
+[Service]
+Type=forking
+User=plom
+ExecStart=/usr/bin/tmux new-session -d '~/config/bin/weechat-wrapper.sh'
+
+[Install]
+WantedBy=multi-user.target
-- 
2.30.2