From 055af8d5c742cfca1efff76792e854ee065bd244 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 29 Oct 2016 10:16:36 +0100 Subject: [PATCH] Tidying creation of irssi config --- src/freedombone-app-irc | 200 ++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 121 deletions(-) diff --git a/src/freedombone-app-irc b/src/freedombone-app-irc index af83016a..3515fb72 100755 --- a/src/freedombone-app-irc +++ b/src/freedombone-app-irc @@ -64,6 +64,83 @@ function stop_irc_bouncer { pkill znc } +function create_irssi_config { + new_username="$1" + + read_config_param IRC_BOUNCER_PORT + read_config_param IRC_ONION_PORT + read_config_param IRC_PASSWORD + + new_name="$2" + if [ ${#new_name} -eq 0 ]; then + new_name="$new_username" + fi + + echo 'servers = (' > /home/${new_username}/.irssi/config + echo ' {' >> /home/${new_username}/.irssi/config + echo ' address = "chat.freenode.net";' >> /home/${new_username}/.irssi/config + echo ' chatnet = "Freenode";' >> /home/${new_username}/.irssi/config + echo ' port = "6667";' >> /home/${new_username}/.irssi/config + echo ' autoconnect = "no";' >> /home/${new_username}/.irssi/config + echo ' },' >> /home/${new_username}/.irssi/config + echo ' {' >> /home/${new_username}/.irssi/config + echo ' address = "irc.oftc.net";' >> /home/${new_username}/.irssi/config + echo ' chatnet = "OFTC";' >> /home/${new_username}/.irssi/config + echo ' port = "6667";' >> /home/${new_username}/.irssi/config + echo ' autoconnect = "no";' >> /home/${new_username}/.irssi/config + echo ' },' >> /home/${new_username}/.irssi/config + echo ' {' >> /home/${new_username}/.irssi/config + echo " address = \"127.0.0.1\";" >> /home/${new_username}/.irssi/config + echo ' use_ssl = "yes";' >> /home/${new_username}/.irssi/config + echo ' ssl_verify = "no";' >> /home/${new_username}/.irssi/config + if [[ ${ONION_ONLY} == 'no' ]]; then + echo " port = \"${IRC_BOUNCER_PORT}\";" >> /home/${new_username}/.irssi/config + else + IRC_ONION_HOSTNAME=$(cat ${COMPLETION_FILE} | grep "irc onion domain" | head -n 1 | awk -F ':' '{print $2}') + echo " port = \"${IRC_ONION_PORT}\";" >> /home/${new_username}/.irssi/config + fi + echo ' chatnet = "Freedombone";' >> /home/${new_username}/.irssi/config + echo ' autoconnect = "yes";' >> /home/${new_username}/.irssi/config + if [ ${IRC_PASSWORD} ]; then + echo " password = \"${IRC_PASSWORD}\";" >> /home/${new_username}/.irssi/config + fi + echo ' }' >> /home/${new_username}/.irssi/config + echo ');' >> /home/${new_username}/.irssi/config + echo '' >> /home/${new_username}/.irssi/config + echo 'chatnets = {' >> /home/${new_username}/.irssi/config + echo ' Freedombone = {' >> /home/${new_username}/.irssi/config + echo ' type = "IRC";' >> /home/${new_username}/.irssi/config + echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config + echo ' max_msgs = "4";' >> /home/${new_username}/.irssi/config + echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config + echo ' };' >> /home/${new_username}/.irssi/config + echo ' Freenode = {' >> /home/${new_username}/.irssi/config + echo ' type = "IRC";' >> /home/${new_username}/.irssi/config + echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config + echo ' max_msgs = "4";' >> /home/${new_username}/.irssi/config + echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config + echo ' };' >> /home/${new_username}/.irssi/config + echo ' OFTC = {' >> /home/${new_username}/.irssi/config + echo ' type = "IRC";' >> /home/${new_username}/.irssi/config + echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config + echo ' max_msgs = "1";' >> /home/${new_username}/.irssi/config + echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config + echo ' };' >> /home/${new_username}/.irssi/config + echo '};' >> /home/${new_username}/.irssi/config + echo '' >> /home/${new_username}/.irssi/config + echo 'channels = (' >> /home/${new_username}/.irssi/config + echo ' { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/${new_username}/.irssi/config + echo ');' >> /home/${new_username}/.irssi/config + echo '' >> /home/${new_username}/.irssi/config + echo 'settings = {' >> /home/${new_username}/.irssi/config + echo " core = { real_name = \"$new_name\"; user_name = \"$new_username\"; nick = \"$new_username\"; };" >> /home/${new_username}/.irssi/config + echo ' "fe-text" = { actlist_sort = "refnum"; };' >> /home/${new_username}/.irssi/config + echo '};' >> /home/${new_username}/.irssi/config + echo 'ignores = ( { level = "CTCPS"; } );' >> /home/${new_username}/.irssi/config + + chown -R ${new_username}:${new_username} /home/${new_username}/.irssi +} + function remove_user_irc_bouncer { remove_username="$1" @@ -198,63 +275,7 @@ function add_user_irc { mkdir /home/${new_username}/.irssi fi - echo 'servers = (' > /home/${new_username}/.irssi/config - echo ' {' >> /home/${new_username}/.irssi/config - echo ' address = "chat.freenode.net";' >> /home/${new_username}/.irssi/config - echo ' chatnet = "Freenode";' >> /home/${new_username}/.irssi/config - echo ' port = "6667";' >> /home/${new_username}/.irssi/config - echo ' autoconnect = "no";' >> /home/${new_username}/.irssi/config - echo ' },' >> /home/${new_username}/.irssi/config - echo ' {' >> /home/${new_username}/.irssi/config - echo ' address = "irc.oftc.net";' >> /home/${new_username}/.irssi/config - echo ' chatnet = "OFTC";' >> /home/${new_username}/.irssi/config - echo ' port = "6667";' >> /home/${new_username}/.irssi/config - echo ' autoconnect = "yes";' >> /home/${new_username}/.irssi/config - echo ' },' >> /home/${new_username}/.irssi/config - echo ' {' >> /home/${new_username}/.irssi/config - echo " address = \"${HOSTNAME}\";" >> /home/${new_username}/.irssi/config - echo ' chatnet = "Freedombone";' >> /home/${new_username}/.irssi/config - echo " port = \"${IRC_PORT}\";" >> /home/${new_username}/.irssi/config - echo ' use_ssl = "yes";' >> /home/${new_username}/.irssi/config - echo ' ssl_verify = "no";' >> /home/${new_username}/.irssi/config - echo ' autoconnect = "yes";' >> /home/${new_username}/.irssi/config - - echo ' }' >> /home/${new_username}/.irssi/config - echo ');' >> /home/${new_username}/.irssi/config - echo '' >> /home/${new_username}/.irssi/config - echo 'chatnets = {' >> /home/${new_username}/.irssi/config - echo ' Freedombone = {' >> /home/${new_username}/.irssi/config - echo ' type = "IRC";' >> /home/${new_username}/.irssi/config - echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config - echo ' max_msgs = "4";' >> /home/${new_username}/.irssi/config - echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config - echo ' };' >> /home/${new_username}/.irssi/config - echo ' Freenode = {' >> /home/${new_username}/.irssi/config - echo ' type = "IRC";' >> /home/${new_username}/.irssi/config - echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config - echo ' max_msgs = "4";' >> /home/${new_username}/.irssi/config - echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config - echo ' };' >> /home/${new_username}/.irssi/config - echo ' OFTC = {' >> /home/${new_username}/.irssi/config - echo ' type = "IRC";' >> /home/${new_username}/.irssi/config - echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config - echo ' max_msgs = "1";' >> /home/${new_username}/.irssi/config - echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config - echo ' };' >> /home/${new_username}/.irssi/config - echo '};' >> /home/${new_username}/.irssi/config - echo '' >> /home/${new_username}/.irssi/config - echo 'channels = (' >> /home/${new_username}/.irssi/config - echo ' { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/${new_username}/.irssi/config - echo ');' >> /home/${new_username}/.irssi/config - echo '' >> /home/${new_username}/.irssi/config - echo 'settings = {' >> /home/${new_username}/.irssi/config - echo " core = { real_name = \"$MY_NAME\"; user_name = \"$new_username\"; nick = \"$new_username\"; };" >> /home/${new_username}/.irssi/config - echo ' "fe-text" = { actlist_sort = "refnum"; };' >> /home/${new_username}/.irssi/config - echo '};' >> /home/$new_username/.irssi/config - echo 'ignores = ( { level = "CTCPS"; } );' >> /home/${new_username}/.irssi/config - - chown -R ${new_username}:${new_username} /home/${new_username}/.irssi - + create_irssi_config "${new_username}" add_user_irc_bouncer "${new_username}" "${IRC_PASSWORD}" echo '0' } @@ -542,70 +563,7 @@ function install_irc_client { mkdir /home/${MY_USERNAME}/.irssi fi - echo 'servers = (' > /home/${MY_USERNAME}/.irssi/config - echo ' {' >> /home/${MY_USERNAME}/.irssi/config - echo ' address = "chat.freenode.net";' >> /home/${MY_USERNAME}/.irssi/config - echo ' chatnet = "Freenode";' >> /home/${MY_USERNAME}/.irssi/config - echo ' port = "6667";' >> /home/${MY_USERNAME}/.irssi/config - echo ' autoconnect = "no";' >> /home/${MY_USERNAME}/.irssi/config - echo ' },' >> /home/${MY_USERNAME}/.irssi/config - echo ' {' >> /home/${MY_USERNAME}/.irssi/config - echo ' address = "irc.oftc.net";' >> /home/${MY_USERNAME}/.irssi/config - echo ' chatnet = "OFTC";' >> /home/${MY_USERNAME}/.irssi/config - echo ' port = "6667";' >> /home/${MY_USERNAME}/.irssi/config - echo ' autoconnect = "no";' >> /home/${MY_USERNAME}/.irssi/config - echo ' },' >> /home/${MY_USERNAME}/.irssi/config - echo ' {' >> /home/${MY_USERNAME}/.irssi/config - echo " address = \"127.0.0.1\";" >> /home/${MY_USERNAME}/.irssi/config - echo ' use_ssl = "yes";' >> /home/${MY_USERNAME}/.irssi/config - echo ' ssl_verify = "no";' >> /home/${MY_USERNAME}/.irssi/config - if [[ ${ONION_ONLY} == 'no' ]]; then - echo " port = \"${IRC_BOUNCER_PORT}\";" >> /home/${MY_USERNAME}/.irssi/config - else - IRC_ONION_HOSTNAME=$(cat ${COMPLETION_FILE} | grep "irc onion domain" | head -n 1 | awk -F ':' '{print $2}') - echo " port = \"${IRC_ONION_PORT}\";" >> /home/${MY_USERNAME}/.irssi/config - fi - echo ' chatnet = "Freedombone";' >> /home/${MY_USERNAME}/.irssi/config - echo ' autoconnect = "yes";' >> /home/${MY_USERNAME}/.irssi/config - if [ ${IRC_PASSWORD} ]; then - echo " password = \"${IRC_PASSWORD}\";" >> /home/${MY_USERNAME}/.irssi/config - fi - echo ' }' >> /home/${MY_USERNAME}/.irssi/config - echo ');' >> /home/${MY_USERNAME}/.irssi/config - echo '' >> /home/${MY_USERNAME}/.irssi/config - echo 'chatnets = {' >> /home/${MY_USERNAME}/.irssi/config - echo ' Freedombone = {' >> /home/${MY_USERNAME}/.irssi/config - echo ' type = "IRC";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_kicks = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_msgs = "4";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_whois = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' };' >> /home/${MY_USERNAME}/.irssi/config - echo ' Freenode = {' >> /home/${MY_USERNAME}/.irssi/config - echo ' type = "IRC";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_kicks = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_msgs = "4";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_whois = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' };' >> /home/${MY_USERNAME}/.irssi/config - echo ' OFTC = {' >> /home/${MY_USERNAME}/.irssi/config - echo ' type = "IRC";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_kicks = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_msgs = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' max_whois = "1";' >> /home/${MY_USERNAME}/.irssi/config - echo ' };' >> /home/${MY_USERNAME}/.irssi/config - echo '};' >> /home/${MY_USERNAME}/.irssi/config - echo '' >> /home/${MY_USERNAME}/.irssi/config - echo 'channels = (' >> /home/${MY_USERNAME}/.irssi/config - echo ' { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/${MY_USERNAME}/.irssi/config - echo ');' >> /home/${MY_USERNAME}/.irssi/config - echo '' >> /home/${MY_USERNAME}/.irssi/config - echo 'settings = {' >> /home/${MY_USERNAME}/.irssi/config - echo " core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/${MY_USERNAME}/.irssi/config - echo ' "fe-text" = { actlist_sort = "refnum"; };' >> /home/${MY_USERNAME}/.irssi/config - echo '};' >> /home/${MY_USERNAME}/.irssi/config - echo 'ignores = ( { level = "CTCPS"; } );' >> /home/${MY_USERNAME}/.irssi/config - - chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.irssi - + create_irssi_config "${MY_USERNAME}" "$MY_NAME" install_completed irc_client }