Subject: [alpine-devel] [PATCH] testing/namecoin: new aport

From: Stuart Cardall <[email-masked]>
Date: Thu, 8 May 2014 09:52:39 +0000

This is a revised patch with the sources patched & proposed upstream
to fix a locale bug.

The post-install script now just generates a random user / pass /port

This patch provides the namecoin daemon & qt frontend
---
 testing/namecoin/10-use-latest-UPnP-lib.patch      | 11 +++
 .../namecoin/20-boost-multithread-dynamic.patch    | 37 +++++++++
 testing/namecoin/30-set-default-env.patch          | 19 +++++
 testing/namecoin/APKBUILD                          | 89 ++++++++++++++++++++++
 testing/namecoin/namecoin.conf                     | 10 +++
 testing/namecoin/namecoin.confd                    | 13 ++++
 testing/namecoin/namecoin.initd                    | 35 +++++++++
 testing/namecoin/namecoin.post-install             | 53 +++++++++++++
 8 files changed, 267 insertions(+)
 create mode 100644 testing/namecoin/10-use-latest-UPnP-lib.patch
 create mode 100644 testing/namecoin/20-boost-multithread-dynamic.patch
 create mode 100644 testing/namecoin/30-set-default-env.patch
 create mode 100644 testing/namecoin/APKBUILD
 create mode 100644 testing/namecoin/namecoin.conf
 create mode 100644 testing/namecoin/namecoin.confd
 create mode 100644 testing/namecoin/namecoin.initd
 create mode 100644 testing/namecoin/namecoin.post-install

diff --git a/testing/namecoin/10-use-latest-UPnP-lib.patch b/testing/namecoin/10-use-latest-UPnP-lib.patch
new file mode 100644
index 0000000..89d9a45
--- /dev/null
+++ b/testing/namecoin/10-use-latest-UPnP-lib.patch
@@ -0,0 +1,11 @@
+--- src/net.cpp
++++ src/net.cpp.new
+@@ -1087,7 +1087,7 @@
+ 
+ #ifndef __WXMSW__
+         r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
+-	                        port, port, lanaddr, 0, "TCP", 0);
++	                        port, port, lanaddr, 0, "TCP", 0, "0");
+ #else
+         r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
+ 	                        port, port, lanaddr, 0, "TCP", 0, "0");
diff --git a/testing/namecoin/20-boost-multithread-dynamic.patch b/testing/namecoin/20-boost-multithread-dynamic.patch
new file mode 100644
index 0000000..36efaa9
--- /dev/null
+++ b/testing/namecoin/20-boost-multithread-dynamic.patch
@@ -0,0 +1,37 @@
+--- src/Makefile
++++ src/Makefile.new
+@@ -9,27 +9,23 @@
+ DEFS += -DBOOST_THREAD_USE_LIB
+ 
+ INCLUDEPATHS= \
+-	-I../libs/openssl-1.0.1e/include \
+-	-I../libs/db-4.7.25.NC/build_unix \
+-	-I../libs/boost_1_50_0
++	-I/usr/include
+ 
+ LIBPATHS= \
+-	-L../libs/openssl-1.0.1e \
+-	-L../libs/db-4.7.25.NC/build_unix \
+-	-L../libs/boost_1_50_0/stage/lib
++	-L/usr/lib
+ 
+ LIBBOOST_SUFFIX=
+ 
+ LIBS= \
+- -Wl,-Bstatic \
++ -Wl,-Bdynamic \
+    -l boost_system$(LIBBOOST_SUFFIX) \
+    -l boost_filesystem$(LIBBOOST_SUFFIX) \
+-   -l boost_program_options$(LIBBOOST_SUFFIX) \
+-   -l boost_thread$(LIBBOOST_SUFFIX) \
+-   -l boost_chrono$(LIBBOOST_SUFFIX) \
++   -l boost_program_options-mt$(LIBBOOST_SUFFIX) \
++   -l boost_thread-mt$(LIBBOOST_SUFFIX) \
++   -l boost_chrono-mt$(LIBBOOST_SUFFIX) \
+    -l db_cxx \
+    -l ssl \
+-   -l crypto
++   -l crypto  
+ 
+ namecoin: USE_UPNP:=1
+ 	ifdef USE_UPNP
diff --git a/testing/namecoin/30-set-default-env.patch b/testing/namecoin/30-set-default-env.patch
new file mode 100644
index 0000000..4640fa3
--- /dev/null
+++ b/testing/namecoin/30-set-default-env.patch
@@ -0,0 +1,19 @@
+--- src/init.cpp
++++ src/init.cpp.new
+@@ -98,6 +99,16 @@
+ #ifndef GUI
+ 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;
+     fRet = AppInit(argc, argv);
+ 
diff --git a/testing/namecoin/APKBUILD b/testing/namecoin/APKBUILD
new file mode 100644
index 0000000..0bcf1f4
--- /dev/null
+++ b/testing/namecoin/APKBUILD
@@ -0,0 +1,89 @@
+# Contributor: Stuart Cardall <[email-masked]>
+# Maintainer: Stuart Cardall <[email-masked]>
+pkgname=namecoin
+pkgver=3.72
+pkgrel=0
+pkgdesc="Namecoin is a peer to peer DNS based on bitcoin"
+url="https://github.com/namecoin/namecoin"
+arch="all"
+license="GPL"
+depends=""
+depends_dev="openssl-dev db-dev boost-dev miniupnpc-dev glib-dev qt-dev"
+makedepends="$depends_dev"
+install="$pkgname.post-install"
+subpackages="$pkgname-qt"
+source="https://github.com/namecoin/namecoin/archive/vQ.$pkgver.tar.gz
+	10-use-latest-UPnP-lib.patch
+	20-boost-multithread-dynamic.patch    
+	30-set-default-env.patch
+	$pkgname.initd
+        $pkgname.confd
+	$pkgname.conf
+	"
+
+_builddir="$srcdir"/namecoin-vQ.$pkgver/src
+prepare() {
+	local i
+	cd "$_builddir"
+	for i in $source; do
+		case $i in
+		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+		esac
+	done
+}
+
+build() {
+	cd "$_builddir"
+	# build namecoind
+	make USE_UPNP=1 USE_SSL=1 || return 1
+	cd ..
+	# build namecoin-qt
+	qmake
+	# Fix boost_multi thread linking in the GUI too
+	sed -i 's/-lboost_thread/-lboost_thread-mt/g' ./Makefile
+	sed -i 's/-lboost_program_options/-lboost_program_options-mt/g' ./Makefile
+	sed -i 's/-lboost_chrono/-lboost_chrono-mt/g' ./Makefile
+	make || return 1
+}
+
+qt() {
+	pkgdesc="Namecoin with a Qt frontend"
+        #depends="namecoin=$pkgver-r$pkgrel"
+	cd "$srcdir"/namecoin-vQ.$pkgver
+	install -Dm755 namecoin-qt "$pkgdir"/usr/bin/namecoin-qt || return 1
+	mkdir -p "$subpkgdir"/usr/bin
+        mv "$pkgdir"/usr/bin/namecoin-qt \
+                "$subpkgdir"/usr/bin/
+}
+
+package() {
+	cd "$_builddir"
+	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname || return 1
+	# daemon config
+        install -m600 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname || return 1
+	# app config
+	install -m600 -D "$srcdir"/$pkgname.conf "$pkgdir"/etc/$pkgname.conf || return 1
+        install -Dm755 namecoind "$pkgdir"/usr/bin/namecoind || return 1
+}
+
+md5sums="dc1cc80bcf0833f0bf7239e7ae6c1399  vQ.3.72.tar.gz
+4806af721972347f7bc9f00cc8209368  10-use-latest-UPnP-lib.patch
+a5e729e2fee30e18cfdec4cb70d1403a  20-boost-multithread-dynamic.patch
+50c73bd5614b2518800e95515f509eb1  30-set-default-env.patch
+3f8c9adc673b70b91a776f7e88056e0f  namecoin.initd
+a09e207f13abdf2aa098348f362b2ebc  namecoin.confd
+7c27809a00b5c43577d5ebc93e287ff4  namecoin.conf"
+sha256sums="8c30214186bf0baf4f779235e82715a99686c8c358524ffa352b88e2a3d98725  vQ.3.72.tar.gz
+781f9e85d02edbd6bd635302a4b9563ee0a00762949343cb192df8d675ffc06f  10-use-latest-UPnP-lib.patch
+a04796aa12bf69e5daa9cf61a9fd0308440aff5ccacb97518f16fdb122905a61  20-boost-multithread-dynamic.patch
+458133b1e8f6538f1e15b7d97bca04ee7dfbd441c725770cff5ef7cfb0662dc2  30-set-default-env.patch
+c231e1e7149d46c6895390c08cf52b9d6bc5e7d34e45a378e5775866b5534c10  namecoin.initd
+ce62ed34f03544de3afa6beca86c6ac62a5860da808f8412e6b5dd87ea3086fa  namecoin.confd
+d12169f4ba7606220c9d1f84a9997fc497fbc7b5e88c2b651849df011ac0a7f4  namecoin.conf"
+sha512sums="fac3b0cb3d02ccb438869752581ab57df6dd8e47201e613e73c64459009d9d20358f6595400938e61bf795f679466a098bbc77f1b2940591ec93d04cc387ea32  vQ.3.72.tar.gz
+c69826ac80ea1c1f447d6000a43b7be93f79e3667e0b7dd19cc86a9cb2d579d715549c32bf5b75b601208c404a7c0e574627c566c0cca513258ad73a28a831b5  10-use-latest-UPnP-lib.patch
+d086e59612097c29c89c12e6b14bb369ec84db9b7d2d9c9ed65109d74442692300c812814525012a5869e172b8757e29e54ebc4e5eabebcae68e2ef0a8976d99  20-boost-multithread-dynamic.patch
+1fd427a41be0b26cc069f3babd1e8380736be4f87834511626dcf6c61f74137412c4a144648445caa4271663c4c630e823e840915bc744c994b4569f065c4ec9  30-set-default-env.patch
+6fbf943de5fe305bd899d7b10ab014f078154b1f73cb7fa8d3bcbc7fa77c11e512e1e86f7ea3144702c8fc714432239a55d13d3950fe71c0ce77a314ced9c559  namecoin.initd
+e86d673c90aaac797c4c2a9ad4471e32774ac1fa81b0ce57ee4413d452ddd0d2ac1b7f825e62a713d1075d099385cb2687b8bdf534b200b0d7b20946786be119  namecoin.confd
+811c8f8dd2786876e699fe98c94dda363bac5b0e2f1c0f359a067a5858dd65312d3ab5cbdb7f79da6a6717f97e47691ed598e0a4b49084dcec8c0cb298e596f1  namecoin.conf"
diff --git a/testing/namecoin/namecoin.conf b/testing/namecoin/namecoin.conf
new file mode 100644
index 0000000..7697273
--- /dev/null
+++ b/testing/namecoin/namecoin.conf
@@ -0,0 +1,10 @@
+# Namecoin configuration file for Alpine Linux
+#
+#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 namecoins
+
diff --git a/testing/namecoin/namecoin.confd b/testing/namecoin/namecoin.confd
new file mode 100644
index 0000000..a2b4542
--- /dev/null
+++ b/testing/namecoin/namecoin.confd
@@ -0,0 +1,13 @@
+# Namecoin daemon conf.d file for Alpine Linux
+#
+##################################################
+## If run as a NON root user / group change     ##
+## 'pidfile' below to a user writable location  ##
+##################################################
+name=namecoind
+daemon=/usr/bin/$name
+config=/etc/namecoin.conf
+user=root
+group=root
+pidfile=/var/run/$name.pid
+
diff --git a/testing/namecoin/namecoin.initd b/testing/namecoin/namecoin.initd
new file mode 100644
index 0000000..51f509c
--- /dev/null
+++ b/testing/namecoin/namecoin.initd
@@ -0,0 +1,35 @@
+#!/sbin/runscript
+
+# Namecoin init.d file for Alpine Linux.
+
+config_file=/etc/conf.d/namecoin
+
+depend() {
+        need net
+        after firewall
+}
+
+check_config() {
+        [ -f "$config_file" ] || eend "$config_file is missing"
+        [ -f "/usr/bin/namecoind" ] || eend "Namecoin Daemon is not installed"
+}
+
+start() {
+        ebegin "Starting ${name}"
+        check_config || return 1
+                start-stop-daemon --start --quiet \
+                        --pidfile /var/run/${name}.pid \
+                        --user ${user}:${group} \
+                        --exec ${daemon} -- -conf=${config} -pid=${pidfile}
+        eend $?
+}
+
+stop() {
+	ebegin "Stopping ${name}"
+		start-stop-daemon --stop --quiet \
+			--pidfile ${pidfile} \
+			--exec ${daemon}
+	eend $?
+}
+
+
diff --git a/testing/namecoin/namecoin.post-install b/testing/namecoin/namecoin.post-install
new file mode 100644
index 0000000..94d2643
--- /dev/null
+++ b/testing/namecoin/namecoin.post-install
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+NORMAL="\033[1;0m"
+STRONG="\033[1;1m"
+GREEN="\033[1;32m"
+
+config=$(grep config /etc/conf.d/namecoin |sed 's/config=//')
+
+randgen() {
+	output=$(< /dev/urandom tr -dc '0-9a-zA-Z!@#$%^&*_+-' | head -c${1:-$1}) 2>/dev/null
+	echo $output
+}
+
+# Generate random port
+randport() {
+        n=$RANDOM
+        while [ $n -gt 65536 ] && [ $n -lt 1024 ]; do
+                n=$RANDOM
+        done
+        echo $n
+}
+
+# Find unused TCP port
+findRandomTcpPort(){
+        port=$(randport)
+        while :
+        do
+                (echo >/dev/tcp/localhost/$port) &>/dev/null &&  port=$(randport) || break
+        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
+else
+	print_green "Generate a new random username / password / port in: $config ?" " [ y | n <default> ] "; read ans
+	if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
+		GenPasswd
+	fi
+fi
-- 
1.9.1

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