Subject: [alpine-devel] [PATCH] testing/bitcoin: update to 0.9.2.1

From: Stuart Cardall <[email-masked]>
Date: Tue, 24 Jun 2014 22:11:48 +0000

Environment patch removed as merged upstream as function SetupEnvironment()
Init script added so Bitcoin runs as user Bitcoin.
---
 testing/bitcoin/20-set-default-env.patch | 57 --------------------------------
 testing/bitcoin/APKBUILD                 | 33 ++++++++++++------
 testing/bitcoin/bitcoin.conf             | 13 ++++++++
 testing/bitcoin/bitcoin.initd            | 38 +++++++++++++++++++++
 testing/bitcoin/bitcoin.post-install     | 35 ++++++++++++++++++++
 testing/bitcoin/bitcoin.pre-install      |  5 +++
 6 files changed, 113 insertions(+), 68 deletions(-)
 delete mode 100644 testing/bitcoin/20-set-default-env.patch
 create mode 100644 testing/bitcoin/bitcoin.conf
 create mode 100644 testing/bitcoin/bitcoin.initd
 create mode 100644 testing/bitcoin/bitcoin.post-install
 create mode 100644 testing/bitcoin/bitcoin.pre-install

diff --git a/testing/bitcoin/20-set-default-env.patch b/testing/bitcoin/20-set-default-env.patch
deleted file mode 100644
index b9717ab..0000000
--- a/testing/bitcoin/20-set-default-env.patch
+++ /dev/null
@@ -1,57 +0,0 @@
---- ./src/bitcoin-cli.cpp
-+++ ./src/bitcoin-cli.cpp
-@@ -53,6 +53,16 @@
- 
- int main(int argc, char* argv[])
- {
-+    #ifndef WIN32
-+    try
-+    {
-+        boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
-+    } catch(std::runtime_error &e)
-+    {
-+        setenv("LC_ALL", "C", 1); // Force C locale
-+    }
-+    #endif
-+
-     try
-     {
-         if(!AppInitRPC(argc, argv))
---- ./src/bitcoind.cpp
-+++ ./src/bitcoind.cpp
-@@ -166,6 +166,16 @@
- 
- int main(int argc, char* argv[])
- {
-+    #ifndef WIN32
-+    try
-+    {
-+        boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
-+    } catch(std::runtime_error &e)
-+    {
-+        setenv("LC_ALL", "C", 1); // Force C locale
-+    }
-+    #endif
-+
-     bool fRet = false;
- 
-     // Connect bitcoind signal handlers
---- ./src/qt/bitcoin.cpp.orig
-+++ ./src/qt/bitcoin.cpp
-@@ -445,6 +445,16 @@
- #ifndef BITCOIN_QT_TEST
- int main(int argc, char *argv[])
- {
-+#ifndef WIN32
-+    try
-+    {
-+        boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
-+    } catch(std::runtime_error &e)
-+    {
-+        setenv("LC_ALL", "C", 1); // Force C locale
-+    }
-+#endif
-+
-     /// 1. Parse command-line options. These take precedence over anything else.
-     // Command-line options take precedence:
-     ParseParameters(argc, argv);
diff --git a/testing/bitcoin/APKBUILD b/testing/bitcoin/APKBUILD
index 57a2752..9324157 100644
--- a/testing/bitcoin/APKBUILD
+++ b/testing/bitcoin/APKBUILD
@@ -1,7 +1,8 @@
-# Maintainer: Natanael Copa <[email-masked]>
+# Contributor: Natanael Copa <[email-masked]>
+# Maintainer: Stuart Cardall <[email-masked]>
 pkgname=bitcoin
-pkgver=0.9.1
-pkgrel=2
+pkgver=0.9.2.1
+pkgrel=0
 pkgdesc="decentralized P2P electronic cash system"
 url="http://www.bitcoin.org/"
 arch="all"
@@ -11,13 +12,17 @@ depends_dev=""
 makedepends="$depends_dev boost-dev openssl-dev db-dev miniupnpc-dev
 	qt5-qtbase-dev qt5-qttools-dev protobuf-dev libqrencode-dev
 	autoconf automake libtool"
-install=""
+install="$pkgname.post-install $pkgname.pre-install"
 subpackages="$pkgname-qt $pkgname-cli"
 source="$pkgname-$pkgver.tar.gz::https://github.com/bitcoin/bitcoin/archive/v$pkgver.tar.gz
 	ssize_t.patch
-	20-set-default-env.patch
+	$pkgname.initd
+	$pkgname.conf
 	"
 
+#20-set-default-env.patch
+
+
 _builddir="$srcdir"/bitcoin-$pkgver
 prepare() {
 	local i
@@ -47,12 +52,15 @@ build() {
 package() {
 	cd "$_builddir"
 	make install DESTDIR="$pkgdir" || return 1
+	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname || return 1
+	install -m600 -D "$srcdir"/$pkgname.conf "$pkgdir"/etc/$pkgname.conf || return 1
 }
 
 qt() {
 	pkgdesc="Bitcoin with a Qt frontend & QR Code support"
 	mkdir -p "$subpkgdir"/usr/bin
 	mv "$pkgdir"/usr/bin/bitcoin-qt "$subpkgdir"/usr/bin/ || return 1
+	mv "$pkgdir"/usr/bin/test_bitcoin-qt "$subpkgdir"/usr/bin/ || return 1
 }
 
 cli() {
@@ -61,12 +69,15 @@ cli() {
 	mv "$pkgdir"/usr/bin/bitcoin-cli "$subpkgdir"/usr/bin/ || return 1
 }
 
-md5sums="7a9c14c09b04e3e37d703fbfe5c3b1e2  bitcoin-0.9.1.tar.gz
+md5sums="bd3caef17ba5bf9075ff26cd1b29cdae  bitcoin-0.9.2.1.tar.gz
 716a88e668729e89d3eb929da86f7f04  ssize_t.patch
-de733598adec12a7c0e8f2665a086f6d  20-set-default-env.patch"
-sha256sums="bf5021a426b5e38a741a5294a0ceb22daa74cda11c6dc0478c4aa48c55fdccb3  bitcoin-0.9.1.tar.gz
+56edf10681b0cd7cc33de1fd24155108  bitcoin.initd
+3e9b4a37bb46e6cd83b6824870c58484  bitcoin.conf"
+sha256sums="7cadbadd90485b7302b86ce041db576aad650f6c621d3a552d09e7231d3fcfd8  bitcoin-0.9.2.1.tar.gz
 f0a094c7b374338ad153ee06b7dd2369dad6b97b1f1bb0252da12c9aaace5321  ssize_t.patch
-d0763e09784cb09900be7e702e4bbadfc3230715d1f6afa6d70417ab64dde5ef  20-set-default-env.patch"
-sha512sums="75be422fc263f209783fc66d9fd99027d67c7460c599a23badafcf5546ce7cb21206fce04c516a1c101aeff13542b332249b3b70a70c483aa82a5048dbdc9d92  bitcoin-0.9.1.tar.gz
+df060fcee7227a2c7c4a435e24dea25b6388a6d6a98f01975c466a2c770e976a  bitcoin.initd
+b7a31bf251f1011ab6584b610acac8494612c2012e9771985228c36c08a315ac  bitcoin.conf"
+sha512sums="059be086bacfe39c0983dc4ae768349b8d9213b3cd7b60157c7606a25b8b3156e0ffb86e28711550e20b1e6f692bfed021aa1d4ec583496189fa821fc547ad92  bitcoin-0.9.2.1.tar.gz
 98aa5ad81bdb4ae961b791bc978c39117cdf2d83c2181f92bebbb0db107d9b6e86eda265fb3f93ff8a5ca8a7754d7148818b98095d57201dff9363d60b97e7dd  ssize_t.patch
-288934bea005cd6fdcf87525ce82fc0c031e0b86bba02c217c1e32536d3c51981ff187ee630f64787c6d7978d89802f8107b91fa8b2a86fbbb45cb79738e291b  20-set-default-env.patch"
+9bab044e3ddc229f8e2b2eb170361f92d234c78e21c6f1c24a5fe1d0b480db5b6728dda990752eb0820085ecdc41538e735d631ff5886c270475a5b634e3729f  bitcoin.initd
+48abce0f0a5b088c957aa5cb2bcf9bb520593caa7a20019bdf785e43f7d2459968240d4529dfa30be2fca92891bf50c1253a513530511e99d8ee471d9ff6bd95  bitcoin.conf"
diff --git a/testing/bitcoin/bitcoin.conf b/testing/bitcoin/bitcoin.conf
new file mode 100644
index 0000000..4f070b1
--- /dev/null
+++ b/testing/bitcoin/bitcoin.conf
@@ -0,0 +1,13 @@
+### Bitcoin configuration for Alpine Linux ####
+#					      #
+##### data directory is /var/lib/bitcoin ######
+##### & set in /etc/init.d/bitcoin not here ###
+#
+#proxy=127.0.0.1:9050	#use TOR Socks Proxy
+rpcallowip=127.0.0.1
+rpcuser=changeme
+rpcpassword=changeme
+rpcport=changeme
+daemon=1
+#gen=1			#generate bitcoins
+
diff --git a/testing/bitcoin/bitcoin.initd b/testing/bitcoin/bitcoin.initd
new file mode 100644
index 0000000..5f0ef76
--- /dev/null
+++ b/testing/bitcoin/bitcoin.initd
@@ -0,0 +1,38 @@
+#!/sbin/runscript
+
+# Bitcoin init.d file for Alpine Linux.
+
+name=bitcoind
+daemon=/usr/bin/$name
+config=/etc/bitcoin.conf
+user=bitcoin
+group=bitcoin
+## supercedes datadir set in $config ##
+datadir=/var/lib/bitcoin
+pidfile=/var/run/bitcoin/$name.pid
+
+depend() {
+        need net
+        after logger firewall
+}
+
+start() {
+        ebegin "Starting ${name}"
+        # enforce permissions
+	checkpath -q -d ${pidfile%/*} -o ${user}:${group}
+        checkpath -q -d ${datadir} -m 0700 -o ${user}:${group}
+        checkpath -q -f ${config} -m 0600 -o ${user}:${group}
+        start-stop-daemon --start --quiet \
+                        --pidfile ${pidfile} \
+                        --user ${user}:${group} \
+                        --exec ${daemon} -- -conf=${config} -datadir=${datadir} -pid=${pidfile}
+        eend $?
+}
+
+stop() {
+        ebegin "Stopping ${name}"
+                start-stop-daemon --stop --quiet \
+                        --pidfile ${pidfile} \
+                        --exec ${daemon}
+        eend $?
+}
diff --git a/testing/bitcoin/bitcoin.post-install b/testing/bitcoin/bitcoin.post-install
new file mode 100644
index 0000000..9d2510f
--- /dev/null
+++ b/testing/bitcoin/bitcoin.post-install
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+NORMAL="\033[1;0m"
+STRONG="\033[1;1m"
+GREEN="\033[1;32m"
+
+config=$(grep -F 'config=' /etc/init.d/bitcoin |sed 's/config=//')
+
+randgen() {
+	output=$(cat /dev/urandom | tr -dc '0-9a-zA-Z!@#$%^&*_+-' | head -c${1:-$1}) 2>/dev/null
+	echo $output
+}
+
+findRandomTcpPort(){
+	port=$(( 1024 + $(( $RANDOM % $(( 65534 - 1024 )) )) ))
+	while netstat -atn | grep -q :$port; do port=$(expr $port + 1); done; echo $port
+}
+
+GenPasswd(){
+	sed -i "/rpcuser=/ c \rpcuser=USER-"$(randgen 32)"" $config
+        sed -i "/rpcpassword=/ c \rpcpassword=PW-"$(randgen 64)"" $config
+        sed -i "/rpcport=/ c \rpcport="$(findRandomTcpPort)"" $config
+        print_green "Generated random user / password / port in:" " $config\n"
+}
+
+print_green() {
+        local prompt="${STRONG}$1${GREEN}$2${NORMAL}"
+        printf "${prompt}%s"
+}
+
+if grep -F "changeme" $config 1>/dev/null; then
+	GenPasswd
+fi
+
+exit 0
diff --git a/testing/bitcoin/bitcoin.pre-install b/testing/bitcoin/bitcoin.pre-install
new file mode 100644
index 0000000..f020a8b
--- /dev/null
+++ b/testing/bitcoin/bitcoin.pre-install
@@ -0,0 +1,5 @@
+#!/bin/sh
+addgroup -S bitcoin 2>/dev/null
+adduser -S -H -h /var/lib/bitcoin -g bitcoin -G bitcoin -D -s /sbin/nologin bitcoin 2>/dev/null
+exit 0
+
-- 
1.9.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---