summarylogtreecommitdiffstats
path: root/namecoin.install
blob: fe04082bdbe01ff78c48ab889442e4a546d9d841 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
_bc_user=namecoin
_bc_group=namecoin

_datadir=/var/lib/namecoin

post_install() {
  _mkuser
  # disable Copy-On-Write (btrfs directories only)
  for _dir in $_datadir; do
    _is_btrfs "$_dir" && _disable_cow "$_dir"
  done
  mkdir -p $_datadir
  chown -R $_bc_user:$_bc_group /etc/namecoin $_datadir
  printf "%b\n" "$namecoin"
}

post_upgrade() {
  _mkuser
  mkdir -p $_datadir
  chown -R $_bc_user:$_bc_group /etc/namecoin $_datadir
  printf "%b\n" "$namecoin"
}

post_remove() {
  _rmuser
  rm -rf $_datadir
}


# ------------------------------------------------------------------------------
# helper functions for creating namecoin-core user / group
# ------------------------------------------------------------------------------

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

_rmuser() {
  echo -n "Removing namecoin user... "
  userdel -rf $_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
}

# disable btrfs CoW
_chattrify() {
  # original dir, with trailing slash stripped if it exists
  _orig_dir=$( echo "$1" | sed 's@/$@@' )

  # if original dir exists, back it up
  [[ -d "$1" ]] && mv "$1" "${_orig_dir}"_old

  # re-make original dir
  mkdir -p "$1"

  # set permissions on re-made dir
  chmod "$2" "$1"

  # disable btrfs CoW on re-made dir
  chattr +C "$1"

  # recursive copy to restore backed up dir while maintaining disabled CoW
  [[ -d "${_orig_dir}"_old ]] \
    && find "${_orig_dir}"_old -mindepth 1 -maxdepth 1 -exec cp -R '{}' "$1" \;

  # set ownership on re-made dir
  chown -R $3:$4 "$1"

  # purge backed up dir
  [[ -d "${_orig_dir}"_old ]] && rm -rf "${_orig_dir}"_old
}

_disable_cow() {
  _chattrify "$1" "700" "$_bc_user" "$_bc_group"
}


read -d '' namecoin <<'EOF'
########################################################################
########################################################################
##                                                                    ##
##  namecoin Core                                                     ##
##  ____________                                                      ##
##                                                                    ##
##  To start namecoin-core:                                           ##
##                                                                    ##
##      # systemctl start namecoin                                    ##
##                                                                    ##
##  To communicate with namecoin-core as a normal user:               ##
##                                                                    ##
##      $ mkdir -p ~/.namecoin                                        ##
##      $ cat > ~/.namecoin/namecoin.conf <<'EOF'                     ##
##      rpcconnect=127.0.0.1                                          ##
##      rpcport=8336                                                  ##
##      rpcuser=namecoin                                              ##
##      rpcpassword=secret                                            ##
##      EOF                                                           ##
##                                                                    ##
##      $ namecoin-cli getmininginfo                                  ##
##                                                                    ##
##  Config:        /etc/namecoin/namecoin.conf                        ##
##  Blockchain:    /var/lib/namecoin                                  ##
##  Documentation: /usr/share/doc/namecoin                            ##
##                                                                    ##
########################################################################
########################################################################
EOF