FS#45194 - [bitcoin-daemon] Various PKGBUILD improvements

Attached to Project: Community Packages
Opened by Johannes Ernst (jernst) - Wednesday, 03 June 2015, 21:14 GMT
Last edited by Eli Schwartz (eschwartz) - Thursday, 11 January 2018, 03:09 GMT
Task Type Feature Request
Category Packages
Status Closed
Assigned To Christian Rebischke (Shibumi)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Here's a patch that automates a few more of the steps for users to get the daemon running:

* it creates the bitcoin user/group, with home directory /var/lib/bitcoin
* it installs the systemd service file from the Wiki
* it installs the config file in /etc/bitcoin/ and symlinks from .bitcoin

I picked uid=gid=197 (not taken yet per https://wiki.archlinux.org/index.php/DeveloperWiki:UID_/_GID_Database ). If you accept my patch, we need to add a line to that wiki page and remove the FIXME line in the PKGBUILD.


commit 98b08d1789e2f3d5dbd0b4a4c655e086557aecda
Author: Johannes Ernst <jernst@indiecomputing.com>
Date: Fri May 15 21:03:58 2015 +0000

Create bitcoin user/group, add system service file, conf file in /etc

diff --git a/PKGBUILD b/PKGBUILD
index ece1f57..17892e7 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,15 +1,19 @@
# $Id$
# Maintainer: Timothy Redaelli <timothy.redaelli@gmail.com>
# Contributor: shahid <helllamer@gmail.com>
+# Contributor: Johannes Ernst <johannes.ernst@gmail.com>
+
+# FIXME: claim uid=gid=197 on https://wiki.archlinux.org/index.php/DeveloperWiki:UID_/_GID_Database

pkgbase=bitcoin
pkgname=('bitcoin-daemon' 'bitcoin-cli' 'bitcoin-qt')
pkgver=0.10.1
-pkgrel=1
+pkgrel=2
arch=('i686' 'x86_64')
url="http://www.bitcoin.org/"
makedepends=('boost' 'automoc4' 'qrencode' 'miniupnpc' 'protobuf')
license=('MIT')
+backup=('/etc/bitcoin/bitcoin.conf')
source=(http://bitcoin.org/bin/bitcoin-core-$pkgver/bitcoin-$pkgver.tar.gz
https://raw.github.com/bitcoin/bitcoin/v$pkgver/contrib/debian/bitcoin-qt.desktop
https://raw.github.com/bitcoin/bitcoin/v$pkgver/share/pixmaps/bitcoin128.png
@@ -58,9 +62,12 @@ package_bitcoin-qt() {
package_bitcoin-daemon() {
pkgdesc="Bitcoin is a peer-to-peer network based digital currency - daemon"
depends=(boost-libs miniupnpc openssl)
+ install=bitcoin-daemon.install

cd "$pkgbase-$pkgver"
install -Dm755 src/bitcoind "$pkgdir"/usr/bin/bitcoind
+ mkdir -p -m750 "$pkgdir/var/lib/bitcoin/.bitcoin"
+ chown 197:197 "$pkgdir/var/lib/bitcoin/.bitcoin"
install -Dm644 "$srcdir"/bitcoin.conf \
"$pkgdir/usr/share/doc/$pkgname/examples/bitcoin.conf"
install -Dm644 "$srcdir"/bitcoind.1 \
@@ -68,6 +75,12 @@ package_bitcoin-daemon() {
install -Dm644 "$srcdir"/bitcoin.conf.5 \
"$pkgdir"/usr/share/man/man5/bitcoin.conf.5
install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
+ install -Dm644 "$startdir"/bitcoind.service \
+ "$pkgdir"/usr/lib/systemd/system/bitcoind.service
+ mkdir -p -m755 "$pkgdir/etc/bitcoin/"
+ install -m640 "$srcdir"/bitcoin.conf \
+ "$pkgdir/etc/bitcoin/bitcoin.conf"
+ ln -s /etc/bitcoin/bitcoin.conf "$pkgdir/var/lib/bitcoin/.bitcoin/bitcoin.conf"
}

package_bitcoin-cli() {
diff --git a/bitcoin-daemon.install b/bitcoin-daemon.install
new file mode 100644
index 0000000..1092524
--- /dev/null
+++ b/bitcoin-daemon.install
@@ -0,0 +1,15 @@
+post_install() {
+ getent group bitcoin &>/dev/null || groupadd -r -g 197 bitcoin >/dev/null
+ getent passwd bitcoin &>/dev/null || useradd -r -u 197 -g bitcoin -d /var/lib/bitcoin -s /bin/false -c bitcoin bitcoin >/dev/null
+ chown -R bitcoin:bitcoin /var/lib/bitcoin
+ echo Before starting bitcoind.service, you must edit /etc/bitcoin/bitcoin.conf
+ echo and set 'rpcuser' and a hard-to-guess 'rpcpassword'.
+ true
+}
+
+post_remove() {
+ getent passwd bitcoin &>/dev/null && userdel bitcoin >/dev/null
+ getent group bitcoin &>/dev/null && groupdel bitcoin >/dev/null
+ true
+}
+
diff --git a/bitcoind.service b/bitcoind.service
new file mode 100644
index 0000000..92701e0
--- /dev/null
+++ b/bitcoind.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Bitcoin daemon service
+After=network.target
+
+[Service]
+Type=simple
+User=bitcoin
+ExecStart=/usr/bin/bitcoind
+
+[Install]
+WantedBy=multi-user.target
This task depends upon

Closed by  Eli Schwartz (eschwartz)
Thursday, 11 January 2018, 03:09 GMT
Reason for closing:  Fixed
Additional comments about closing:  bitcoin 0.15.1-4
Comment by Timothy Redaelli (tredaelli) - Thursday, 04 June 2015, 16:52 GMT
This patch as-is is not acceptable, since it violates any advices present here: https://www.archlinux.org/todo/usergroup-management/
I'll consider to rework it and add it on next version bump
Comment by Johannes Ernst (jernst) - Thursday, 04 June 2015, 18:11 GMT
If I understand the policy correctly, all that's needed then is to remove post_remove() from the .install file?
Comment by Johannes Ernst (jernst) - Friday, 08 January 2016, 18:32 GMT
What can we do to get this merged?
Comment by Eli Schwartz (eschwartz) - Sunday, 17 September 2017, 19:47 GMT
  • Assignment removed
tredaelli has retired, so pinging arojas as he seems to be updating this.

@jernst, the best thing to do would be to create the user/group and home directory via sysusers.d(5) and tmpfiles.d(5)
See e.g. https://www.archlinux.org/todo/pacman-hooks-systemd-sysuserstmpfiles/

Question: Is it absolutely necessary for a hardcoded uid/gid or was that just a workaround for packaging /var/lib/bitcoin in the package (which should now be done via tmpfiles.d)?

Aside: please submit patches as attachments rather than inline text, the bugtracker mangles whitespace when displaying comments. :D
Comment by Eli Schwartz (eschwartz) - Sunday, 17 September 2017, 19:53 GMT
Also, the source code contains a service file in contrib/init/bitcoind.service -- not sure why they wrote it as a forking service with a pidfile though...

Courtesy of  FS#52325 
Comment by Antonio Rojas (arojas) - Sunday, 17 September 2017, 21:46 GMT
Also, user creation should be managed with sysusers files now.
Comment by Christian Rebischke (Shibumi) - Wednesday, 10 January 2018, 17:27 GMT
This patch is from 2015.. I will close this issue. If you want to propose a new patch make sure that it reflects the current state.
Comment by Eli Schwartz (eschwartz) - Wednesday, 10 January 2018, 17:39 GMT
This feature request is not about a patch. This feature request is about automating the process of setting up the bitcoin daemon.

The fact that it included an implementation patch as a a suggestion, should not be taken to mean that we should close the feature request as soon as the patch is stale. This discourages people from offering to help implement changes... -_-

As per the original request, it would be nice if the package provided:

1) The contrib service file.
2) A basic conf file.
3) A sysusers/tmpfiles description of the daemon user.

Currently, none of those things are true. Please either implement them, or reject them as something you feel the package *should* not do.

Loading...