summarylogtreecommitdiffstats
path: root/bitcoin.install
blob: c064b3b61e5e2a679d86ba402b1ec93f619d3e35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
post_install() {
  _mkuser
  _mkssl
  chown -R bitcoin:bitcoin /etc/bitcoin /srv/bitcoin
  printf "%b\n" "$bitcoin"
}

post_upgrade() {
  _mkuser
  chown -R bitcoin:bitcoin /etc/bitcoin /srv/bitcoin
  printf "%b\n" "$bitcoin"
}

post_remove() {
  _rmuser
  rm -rf /srv/bitcoin
}

_mkuser() {
  getent passwd bitcoin &>/dev/null || {
    echo -n "Creating bitcoin user... "
    grep -E "^bitcoin:" /etc/group >/dev/null || groupadd bitcoin
    useradd -m -d /etc/bitcoin -g bitcoin -s /usr/bin/nologin bitcoin 2>/dev/null
    echo "done"
  }
}

_rmuser() {
  echo -n "Removing bitcoin user... "
  userdel -rf bitcoin 2>/dev/null
  echo "done"
}

_mkssl() {
  echo -n "Enabling SSL..." # https://en.bitcoin.it/wiki/Enabling_SSL_on_original_client_daemon
  mkdir -p /{etc,srv}/bitcoin
  openssl genrsa -out /etc/bitcoin/server.pem 2048
  expect <<EOF | perl -ne 'print if /-----BEGIN\sCERTIFICATE-----/../-----END\sCERTIFICATE-----/' > /etc/bitcoin/server.cert
    spawn openssl req -new -x509 -nodes -sha1 -days 3650 -key /etc/bitcoin/server.pem
    expect "Country*" {
      send "\r"
    }
    expect "State*" {
      send "\r"
    }
    expect "Locality*" {
      send "\r"
    }
    expect "Organization*" {
      send "\r"
    }
    expect "Organizational*" {
      send "\r"
    }
    expect "Common*" {
      send "\r"
    }
    expect "Email*" {
      send "\r"
    }
    expect eof
EOF
  echo "done"
}

read -d '' bitcoin <<'EOF'
########################################################################
########################################################################
##                                                                    ##
##  BitcoinXT                                                         ##
##  _________                                                         ##
##                                                                    ##
##  To start bitcoinxt:                                               ##
##                                                                    ##
##      # systemctl start bitcoin                                     ##
##                                                                    ##
##  To communicate with bitcoinxt as a normal user:                   ##
##                                                                    ##
##      $ mkdir -p ~/.bitcoin                                         ##
##      $ cat > ~/.bitcoin/bitcoin.conf <<'EOF'                       ##
##      rpcconnect=127.0.0.1                                          ##
##      rpcport=8332                                                  ##
##      rpcuser=bitcoin                                               ##
##      rpcpassword=secret                                            ##
##      rpcssl=1                                                      ##
##      EOF                                                           ##
##                                                                    ##
##      $ bitcoin-cli getmininginfo                                   ##
##                                                                    ##
##  Config:        /etc/bitcoin/bitcoin.conf                          ##
##  Blockchain:    /srv/bitcoin                                       ##
##  Documentation: /usr/share/doc/bitcoin                             ##
##                                                                    ##
########################################################################
########################################################################
EOF