summarylogtreecommitdiffstats
path: root/bitcoin.install
blob: a24221ce4ceee4afe72d11dac4f16f6fe17b11b3 (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
_bc_user=bitcoin
_bc_group=bitcoin

post_install() {
  _mkuser
  _dir="/var/lib/bitcoind"
  _cnf="/etc/bitcoin"
  if test -d "$_dir"; then
    # disable Copy-On-Write (btrfs directories only)
    # This avoids lots of known db-corruption issues
    _is_btrfs "$_dir" && chattr +C "$_dir"
  else
    mkdir -m 750 "$_dir"
  fi
  chown -R $_bc_user:$_bc_group "$_dir" "$_cnf"
  chmod 775 "$_cnf"
  printf "%b\n" "$bitcoin"
}

post_upgrade() {
  _mkuser
  printf "%b\n" "$bitcoin"
}


# ------------------------------------------------------------------------------
# helper functions for creating bitcoin user / group
# ------------------------------------------------------------------------------

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

# ------------------------------------------------------------------------------
# helper functions for disabling btrfs Copy-On-Write (CoW)
# https://wiki.archlinux.org/index.php/Btrfs#Copy-On-Write_.28CoW.29
# ------------------------------------------------------------------------------

# check if dir is btrfs
_is_btrfs() {
  if [[ $(findmnt --target $1 --output FSTYPE --noheadings) == 'btrfs' ]]; then
    return 0
  else
    return 1
  fi
}