#
# Cookbook Name:: kosmos-hubot
# Recipe:: default
#
# Copyright 2015, Kosmos
#
# All rights reserved - Do Not Redistribute
#

include_recipe "kosmos-nodejs"
include_recipe "kosmos-redis"

group "hubot" do
  gid 48268
end

user "hubot" do
  comment "hubot user"
  uid 48268
  gid 48268
  shell "/bin/bash"
  home "/srv/hal8000"
end

hal8000_freenode_data_bag_item = Chef::EncryptedDataBagItem.load('credentials', 'hal8000_freenode')

application "hal8000" do
  path "/srv/hal8000"
  owner "hubot"
  group "hubot"

  action :deploy

  before_restart do
    file "#{new_resource.release_path}/external-scripts.json" do
      mode  "0640"
      owner "hubot"
      group "hubot"
      content [
	"hubot-help",
	"hubot-read-tweet",
	"hubot-redis-brain",
	"hubot-rules",
	"hubot-shipit",
	"hubot-plusplus",
	"hubot-tell",
	"hubot-seen",
	"hubot-rss-reader",
        "hubot-kosmos-kredits",
        "hubot-auth"
      ].to_json
    end
  end

  repository "https://github.com/67P/hal8000.git"
  revision   "master"

  nodejs do
    entry_point "/srv/hal8000/current/bin/hubot -a irc"
    # Use our own systemd service that depends on redis-server
    template "nodejs.systemd.service.erb"
    environment "HUBOT_IRC_SERVER"            => "irc.freenode.net",
                "HUBOT_IRC_ROOMS"             => "#5apps,#67p,#kosmos,#kosmos-dev,#remotestorage,#hackerbeach,#unhosted,#sockethub",
                "HUBOT_IRC_NICK"              => "hal8000",
                "HUBOT_IRC_NICKSERV_USERNAME" => "hal8000",
                "HUBOT_IRC_NICKSERV_PASSWORD" => hal8000_freenode_data_bag_item['nickserv_password'],
                "HUBOT_IRC_UNFLOOD"           => "100",
                "HUBOT_RSS_PRINTSUMMARY"      => "false",
                "HUBOT_RSS_IRCCOLORS"         => "true",
                # "HUBOT_LOG_LEVEL"             => "error",
                "EXPRESS_PORT"                => "8080",
                "HUBOT_RSS_HEADER"            => "Update:",
                "HUBOT_AUTH_ADMIN"            => "bkero,derbumi,galfert,gregkare,jaaan,slvrbckt,raucao",
                "OA_ASSET_FROM_ADDRESS"       => "akRWZJMETdM2U5UGKadKhv1PAj2npoGja1m",
                "OA_DEFAULT_QUANTITY"         => "100",
                "OA_ASSET_ID"                 => "AbDn6L2AUGnDreUuNkGFEqcxnsoUP4HCjm",
                "OA_SERVER_URL"               => "http://localhost:4562",
                "OA_SERVER_USERNAME"          => "kosmos",
                "OA_SERVER_PASSWORD"          => "asEjdak1yqw",
                "OA_MAX_QUANTITY"             => "5000"
  end
end

schlupp_5apps_data_bag_item = Chef::EncryptedDataBagItem.load('credentials', 'schlupp_5apps')

application "schlupp" do
  path "/srv/schlupp"
  owner "hubot"
  group "hubot"

  action :deploy

  repository "https://github.com/67P/hal8000.git"
  revision   "master"

  nodejs do
    entry_point "/srv/schlupp/current/bin/hubot -a irc"
    # Use our own systemd service that depends on redis-server
    template "nodejs.systemd.service.erb"
    environment "HUBOT_IRC_SERVER"            => "5apps.irc.grove.io",
                "HUBOT_IRC_ROOMS"             => "#5ops,#core",
                "HUBOT_IRC_NICK"              => "schlupp",
                "HUBOT_IRC_NICKSERV_PASSWORD" => schlupp_5apps_data_bag_item['nickserv_password'],
                "HUBOT_IRC_PASSWORD"          => "5apps",
                "HUBOT_IRC_UNFLOOD"           => "100",
                "HUBOT_RSS_PRINTSUMMARY"      => "false",
                "HUBOT_RSS_IRCCOLORS"         => "true",
                "HUBOT_LOG_LEVEL"             => "error",
                "EXPRESS_PORT"                => "8081",
                "HUBOT_RSS_HEADER"            => "Update:",
                "HUBOT_AUTH_ADMIN"            => "galfert,gregkare,basti",
                "HUBOT_IRC_USESSL"            => "true",
                "REDIS_URL"                   => "redis://localhost:6379/5apps",
                "HUBOT_IRC_PORT"              => "6697",
                "RS_LOGGER_USER"              => "5apps@5apps.com",
                "RS_LOGGER_TOKEN"             => schlupp_5apps_data_bag_item['rs_logger_token'],
                "RS_LOGGER_SERVER_NAME"       => "grove-5apps"
  end
end

botka_freenode_data_bag_item = Chef::EncryptedDataBagItem.load('credentials', 'botka_freenode')

application "botka_freenode" do
  path "/srv/botka_freenode"
  owner "hubot"
  group "hubot"

  action :deploy

  before_restart do
    file "#{new_resource.release_path}/external-scripts.json" do
      mode  "0640"
      owner "hubot"
      group "hubot"
      content [
        "hubot-help",
        "hubot-redis-brain",
        "hubot-remotestorage-logger"
      ].to_json
    end
  end

  repository "https://github.com/67P/hal8000.git"
  revision   "master"

  nodejs do
    entry_point "/srv/botka_freenode/current/bin/hubot -a irc"
    # Use our own systemd service that depends on redis-server
    template "nodejs.systemd.service.erb"
    environment "HUBOT_IRC_SERVER"            => "irc.freenode.net",
                "HUBOT_IRC_ROOMS"             => "#5apps,#67p,#kosmos,#kosmos-dev,#remotestorage,#hackerbeach,#unhosted,#sockethub,#opensourcedesign,#openknot",
                "HUBOT_IRC_NICK"              => "botka",
                "HUBOT_IRC_NICKSERV_USERNAME" => "botka",
                "HUBOT_IRC_NICKSERV_PASSWORD" => botka_freenode_data_bag_item['nickserv_password'],
                "HUBOT_IRC_UNFLOOD"           => "100",
                "HUBOT_RSS_PRINTSUMMARY"      => "false",
                "HUBOT_RSS_IRCCOLORS"         => "true",
                # "HUBOT_LOG_LEVEL"             => "error",
                "EXPRESS_PORT"                => "8082",
                "HUBOT_AUTH_ADMIN"            => "bkero,derbumi,galfert,gregkare,jaaan,slvrbckt,raucao",
                "RS_LOGGER_USER"              => "kosmos@5apps.com",
                "RS_LOGGER_TOKEN"             => botka_freenode_data_bag_item['rs_logger_token'],
                "RS_LOGGER_SERVER_NAME"       => "freenode",
                "RS_LOGGER_PUBLIC"            => "true"
  end
end

