blob: b0fab5facc167bb32791897e99de2d38af9aa825 (
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
|
_bs_user=bs
_bs_group=bs
post_install() {
_mkuser
# disable Copy-On-Write (btrfs directories only)
for _dir in /srv/blockchain /var/log/bs; do
_is_btrfs "$_dir" && _disable_cow "$_dir"
done
chown -R $_bs_user:$_bs_group /etc/bs /srv/blockchain /var/log/bs
printf "%b\n" "$obelisk"
}
post_upgrade() {
_mkuser
chown -R $_bs_user:$_bs_group /etc/bs /srv/blockchain /var/log/bs
printf "%b\n" "$obelisk"
}
post_remove() {
_rmuser
rm -rf /etc/bs /srv/blockchain /var/log/bs
}
# ------------------------------------------------------------------------------
# helper functions for creating libbitcoin-server user / group
# ------------------------------------------------------------------------------
_mkuser() {
getent passwd $_bs_user &>/dev/null || {
echo -n "Creating libbitcoin-server user... "
grep -E "^$_bs_group:" /etc/group >/dev/null || groupadd $_bs_group
useradd -m -d /etc/bs -g $_bs_group -s /usr/bin/nologin $_bs_user
echo "done"
}
}
_rmuser() {
echo -n "Removing libbitcoin-server user... "
userdel -rf $_bs_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" "755" "$_bs_user" "$_bs_group"
}
read -d '' obelisk <<'EOF'
########################################################################
########################################################################
## ##
## Libbitcoin Server ##
## _________________ ##
## ##
## To run: ##
## ##
## systemctl start bsinit # first run only ##
## systemctl start bs ##
## ##
## ##
## Config: /etc/bs/bs.cfg ##
## Blockchain: /srv/blockchain ##
## Documentation: /usr/share/doc/libbitcoin-server ##
## Logs: /var/log/bs ##
## ##
########################################################################
########################################################################
EOF
|