<commit_before>#
# Cookbook Name:: electrum-server
# Recipe:: basic server
#
# Copyright (C) 2012 <NAME> <<EMAIL>>
#

include_recipe "python::pip"
include_recipe "python::virtualenv"

# install dependencies

if platform?("debian")
  package "libdb4.8-dev"
  package "libdb4.8++-dev"
  package "libboost-all-dev"
  package "libssl-dev"
end

if platform?("ubuntu")
  apt_repository "bitcoin" do
      uri "http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu"
      distribution node['lsb']['codename']
      components ["main"]
      keyserver "keyserver.ubuntu.com"
      key "C70EF1F0305A1ADB9986DBD8D46F45428842CE5E"
      not_if "dpkg -l | grep libdb4.8++ &> /dev/null"
  end
  package "libdb4.8-dev"
  package "libdb4.8++-dev"
  package "libboost-all-dev"
  package "libssl-dev"
end

python_pip "jsonrpclib" do
  virtualenv "#{node['electrum']['prefix']}"
  action :install
end

# fetch electrum sources

git "#{node['electrum']['prefix']}/src/electrum" do
  repository "https://github.com/spesmilo/electrum-server.git"
  reference "master"
  action :sync
end

# build patched bitcoind

git "#{node['electrum']['prefix']}/src/bitcoin" do
  repository "git://github.com/bitcoin/bitcoin.git"
  reference node['electrum']['bitcoin_tag']
  action :sync
end

bash "build_bitcoind" do
  not_if "stat #{node['electrum']['prefix']}/bin/bitcoind"
  user "root"
  cwd "#{node['electrum']['prefix']}/src/bitcoin"
  code <<-EOF
    patch -N -p1 < #{node['electrum']['prefix']}/src/electrum/patch/patch
    cd src && make -f makefile.unix USE_UPNP= USE_IPV6=1 && cp ./bitcoind #{node['electrum']['prefix']}/bin/bitcoind
  EOF
end

# setup system user

user_account node['electrum']['user'] do
  comment   'Bitcoin user'
  home      "/home/#{node['electrum']['user']}"
  system_user false
  shell '/bin/false'
end

# load bitcoin.conf configuration from databag and override

bitcoin_config = data_bag_item('electrum', 'bitcoin')['config']
node.override['electrum']['bitcoin'] = bitcoin_config

# configure bitcoind

directory "/home/#{node['electrum']['user']}/.bitcoin/" do
  owner node['electrum']['user']
  group node['electrum']['user']<commit_msg>don't generate keypair for user<commit_after>#
# Cookbook Name:: electrum-server
# Recipe:: basic server
#
# Copyright (C) 2012 <NAME> <<EMAIL>>
#

include_recipe "python::pip"
include_recipe "python::virtualenv"

# install dependencies

if platform?("debian")
  package "libdb4.8-dev"
  package "libdb4.8++-dev"
  package "libboost-all-dev"
  package "libssl-dev"
end

if platform?("ubuntu")
  apt_repository "bitcoin" do
      uri "http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu"
      distribution node['lsb']['codename']
      components ["main"]
      keyserver "keyserver.ubuntu.com"
      key "C70EF1F0305A1ADB9986DBD8D46F45428842CE5E"
      not_if "dpkg -l | grep libdb4.8++ &> /dev/null"
  end
  package "libdb4.8-dev"
  package "libdb4.8++-dev"
  package "libboost-all-dev"
  package "libssl-dev"
end

python_pip "jsonrpclib" do
  virtualenv "#{node['electrum']['prefix']}"
  action :install
end

# fetch electrum sources

git "#{node['electrum']['prefix']}/src/electrum" do
  repository "https://github.com/spesmilo/electrum-server.git"
  reference "master"
  action :sync
end

# build patched bitcoind

git "#{node['electrum']['prefix']}/src/bitcoin" do
  repository "git://github.com/bitcoin/bitcoin.git"
  reference node['electrum']['bitcoin_tag']
  action :sync
end

bash "build_bitcoind" do
  not_if "stat #{node['electrum']['prefix']}/bin/bitcoind"
  user "root"
  cwd "#{node['electrum']['prefix']}/src/bitcoin"
  code <<-EOF
    patch -N -p1 < #{node['electrum']['prefix']}/src/electrum/patch/patch
    cd src && make -f makefile.unix USE_UPNP= USE_IPV6=1 && cp ./bitcoind #{node['electrum']['prefix']}/bin/bitcoind
  EOF
end

# setup system user

user_account node['electrum']['user'] do
  comment   'Bitcoin user'
  home      "/home/#{node['electrum']['user']}"
  system_user false
  shell '/bin/false'
  ssh_keygen false
end

# load bitcoin.conf configuration from databag and override

bitcoin_config = data_bag_item('electrum', 'bitcoin')['config']
node.override['electrum']['bitcoin'] = bitcoin_config

# configure bitcoind

directory "/home/#{node['electrum']['user']}/.bitcoin/" do
  owner node['electrum']['user']
  group node['electrum']['user']
{'fraction_non_alphanumeric': 0.1680964525852075, 'fraction_numerical': 0.01901228843032692, 'mean_word_length': 4.698811096433289, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2049510', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1525, 'n_words': 323}