Mail archive
alpine-devel

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

From: Natanael Copa <ncopa_at_alpinelinux.org>
Date: Thu, 8 May 2014 15:03:45 +0200

On Thu, 8 May 2014 09:52:39 +0000
Stuart Cardall <developer_at_it-offshore.co.uk> wrote:

> 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

nice!

I have some comment below.

...

> 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
> _at_@ -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
> +

I don't think we should run it as root by default. We should create a namecoin user.

the init.d script should then checkpath
--directory /var/run/namecoin ... and set the pid dir ownership to the
user.

Does it need a datadir? if so, we should also have a /var/lib/namecoin data dir.

> 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
> _at_@ -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"
> +}

I think this check_config should be removed. the conf.d config should
be optional (and init.d should have sensible defaults). The check for
executable is not really needed as we ship it with same package and
start-stop-daemon will fail if its missing.

> +
> +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
> _at_@ -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!_at_#$%^&*_+-' | 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
> +}

Why is this needed? cannot the application itself find a random 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



---
Unsubscribe:  alpine-devel+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-devel+help_at_lists.alpinelinux.org
---
Received on Thu May 08 2014 - 15:03:45 UTC