bin: better readlink handling.

This commit is contained in:
Christopher Jeffrey 2016-08-10 14:39:07 -07:00
parent a653707a17
commit 74c4294a36
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1,12 +1,26 @@
#!/bin/bash #!/bin/bash
rl=0
daemon=0 daemon=0
cli=0 cli=0
name='node' cmd='node'
if ! type perl > /dev/null 2>& 1; then
if uname | grep -i 'darwin' > /dev/null; then
echo 'BCoin requires perl to start.' >& 2
exit 1
fi
rl=1
fi
if test $rl -eq 1; then
file=$(readlink -f "$0")
else
# Have to do it this way
# because OSX isn't a real OS
file=$(perl -MCwd -e "print Cwd::realpath('$0')")
fi
# Have to do it this way
# because OSX isn't a real OS
file=$(perl -MCwd -e "print Cwd::realpath('$0')")
dir=$(dirname "$file") dir=$(dirname "$file")
if test x"$1" = x'cli'; then if test x"$1" = x'cli'; then
@ -14,13 +28,13 @@ if test x"$1" = x'cli'; then
cli=1 cli=1
fi fi
for v in "$@"; do for arg in "$@"; do
case "$v" in case "$arg" in
--daemon) --daemon)
daemon=1 daemon=1
;; ;;
--spv) --spv)
name='spvnode' cmd='spvnode'
;; ;;
esac esac
done done
@ -31,12 +45,16 @@ if test $cli -eq 1; then
fi fi
if test $daemon -eq 1; then if test $daemon -eq 1; then
if ! type setsid > /dev/null 2>& 1; then
echo 'BCoin requires setsid to start as a daemon.' >& 2
exit 1
fi
( (
setsid "${dir}/${name}" "$@" > /dev/null 2>& 1 & setsid "${dir}/${cmd}" "$@" > /dev/null 2>& 1 &
echo "$!" echo "$!"
) )
exit 0 exit 0
else else
exec "${dir}/${name}" "$@" exec "${dir}/${cmd}" "$@"
exit 1 exit 1
fi fi