Skip to content

Commit

Permalink
Merge pull request #1395 from braydonf/v4
Browse files Browse the repository at this point in the history
bitcoind address index
  • Loading branch information
kleetus committed May 27, 2016
2 parents 0c9d44c + 3ce344a commit 476933c
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 25 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ bower_components
report
.DS_Store

build

bitcore.js
bitcore.min.js
bitcore.js.sig
bitcore.min.js.sig
tests.js
24 changes: 15 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
language: node_js
sudo: false
language: node_js
env:
- CXX=g++-4.8 CC=gcc-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- gcc-4.8
- libzmq3-dev
node_js:
- '0.12'
before_install:
- npm install -g bower
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- '0.12'
- '4'
install:
- bower install
- npm install
after_script:
- gulp coveralls
script:
- npm run test
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Infrastructure to build Bitcoin and blockchain-based applications for the next g

## Getting Started

Before you begin you'll need to have Node.js v0.12 installed. There are several options for installation. One method is to use [nvm](https://github.com/creationix/nvm) to easily switch between different versions, or download directly from [Node.js](https://nodejs.org/).
Before you begin you'll need to have Node.js v4 or v0.12 installed. There are several options for installation. One method is to use [nvm](https://github.com/creationix/nvm) to easily switch between different versions, or download directly from [Node.js](https://nodejs.org/).

```bash
npm install -g bitcore
Expand Down Expand Up @@ -79,6 +79,7 @@ You can also use our pre-generated files, provided for each release along with a

To verify signatures, use the following PGP keys:
- @braydonf: https://pgp.mit.edu/pks/lookup?op=get&search=0x9BBF07CAC07A276D
- @kleetus: https://pgp.mit.edu/pks/lookup?op=get&search=0x33195D27EF6BDB7F
- @pnagurny: https://pgp.mit.edu/pks/lookup?op=get&search=0x0909B33F0AA53013

## License
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "bitcore",
"version": "3.0.0",
"version": "4.0.0",
"description": "A platform to build bitcoin and blockchain-based applications.",
"author": "BitPay <[email protected]>",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha test/** --recursive"
"test": "./node_modules/.bin/mocha test/** --recursive",
"build-deb": "./scripts/build-deb"
},
"bin": {
"bitcore": "./bin/bitcore",
Expand Down Expand Up @@ -81,10 +82,10 @@
"request": "browser-request"
},
"dependencies": {
"bitcore-lib": "^0.13.12",
"bitcore-node": "^2.0.0",
"insight-api": "^0.3.2",
"insight-ui": "^0.3.0"
"bitcore-lib": "^0.13.14",
"bitcore-node": "~3.0.0",
"insight-api": "^0.4.0",
"insight-ui": "^0.4.0"
},
"license": "MIT",
"devDependencies": {
Expand Down
97 changes: 97 additions & 0 deletions scripts/build-deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
set -e
set -o pipefail

log_title() {
local code="\033["
local color="${code}1;34m"
[ -z "$text" ] && local text="$color$1${code}0m"
echo -e "\n$text"
}

root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."

package_arch="amd64"
package_version=$(jq -r ".version" "${root_dir}/package.json")
package_maintainer=$(jq -r ".author" "${root_dir}/package.json")
package_description=$(jq -r ".description" "${root_dir}/package.json")

deb_dir="${root_dir}/build/bitcore_${package_version}_${package_arch}"

log_title "Making Debian package:\n"
echo -e " Name: bitcore"
echo -e " Version: ${package_version}"
echo -e " Maintainer: ${package_maintainer}"
echo -e " Description: ${package_description}"
echo -e ""

if [ -e "$deb_dir" ]; then rm -rf "$deb_dir"; fi

escape() {
sed -e 's/[]\/$*.^|[]/\\&/g' -e 's/&/\\&/g' <<< "$@"
}

replace_vars() {
declare -r file="$1"
declare -r target_file="$2"

sed < "$file" \
-e "s/{{ deb_package_version }}/$(escape $package_version)/g" \
-e "s/{{ deb_package_description }}/$(escape $package_description)/g" \
-e "s/{{ deb_package_maintainer }}/$(escape $package_maintainer)/g" \
-e "s/{{ deb_package_arch }}/$(escape $package_arch)/g" \
> "$target_file"
}

log_title "Setting up Debian package:"
mkdir -vp "$deb_dir/DEBIAN" \
"$deb_dir/etc/bitcore" \
"$deb_dir/usr/opt/bitcore" \
"$deb_dir/usr/opt/bitcore/bin" \
"$deb_dir/usr/bin"

mkdir -vp "$deb_dir/etc/init"
mkdir -vp "$deb_dir/etc/systemd/system"
replace_vars "${root_dir}/scripts/debian/control" "$deb_dir/DEBIAN/control"
replace_vars "${root_dir}/scripts/debian/postinst" "$deb_dir/DEBIAN/postinst"
replace_vars "${root_dir}/scripts/debian/prerm" "$deb_dir/DEBIAN/prerm"
replace_vars "${root_dir}/scripts/debian/bitcore.conf" "$deb_dir/etc/init/bitcore.conf"
replace_vars "${root_dir}/scripts/debian/bitcore.service" "$deb_dir/etc/systemd/system/bitcore.service"
replace_vars "${root_dir}/scripts/debian/bitcore-bitcoind.conf" "$deb_dir/etc/init/bitcore-bitcoind.conf"
replace_vars "${root_dir}/scripts/debian/bitcore-bitcoind.service" "$deb_dir/etc/systemd/system/bitcore-bitcoind.service"
chmod -vR 0755 "$deb_dir/DEBIAN/"

log_title "Copying Bitcore"

app_dir="$deb_dir/usr/opt/bitcore"

cp -v "${root_dir}/bin/bitcored" "${app_dir}/bin/bitcored"
cp -v "${root_dir}/bin/bitcore" "${app_dir}/bin/bitcore"
chmod -vR 0755 "${app_dir}/bin/bitcore" "${app_dir}/bin/bitcored"
cp -v "${root_dir}/package.json" "${app_dir}"
cp -v "${root_dir}/README.md" "${app_dir}"
cp -v "${root_dir}/index.js" "${app_dir}"
pushd "${deb_dir}/usr/bin"
ln -vs "../opt/bitcore/bin/bitcore"
ln -vs "../opt/bitcore/bin/bitcored"
ln -vs "../opt/bitcore/node_modules/.bin/bitcoind" "bitcore-bitcoind"
popd

log_title "Installing Bitcore Modules"
pushd "${app_dir}"
VERIFY_BITCOIN_DOWNLOAD=1 npm install --production
echo "Cleanup Node.js addon binaries before packaging:"
find "${app_dir}" -type f -name '*.node' -print -delete
find "${app_dir}" -type f -name '*.o' -print -delete
echo "Cleanup intermediate files:"
rm -v "${deb_dir}/usr/opt/bitcore/node_modules/bitcore-node/bin/bitcoin-0.12.0-linux64.tar.gz"
npm shrinkwrap --dev
popd

log_title "Building Debian package"
dpkg-deb -Z gzip --verbose --build "$deb_dir"

log_title "Signing Debian package"
dpkg-sig --sign builder "${deb_dir}.deb"

echo -e "Success.\n"
24 changes: 24 additions & 0 deletions scripts/debian/bitcore-bitcoind.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
description "Bitcoin Core for Bitcore"
author "BitPay, Inc."

limit nofile 20000 30000

start on runlevel [2345]
stop on runlevel [016]

kill timeout 300
kill signal SIGINT

# user/group for bitcore daemon to run as
setuid bitcore
setgid bitcore

# home dir of the bitcore daemon user
env HOME=/home/bitcore

respawn
respawn limit 5 15

script
exec bitcore-bitcored -datadir=/home/bitcore/.bitcore/data/
end script
20 changes: 20 additions & 0 deletions scripts/debian/bitcore-bitcoind.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Bitcoin Core for Bitcore
Requires=network.target

[Service]
Type=simple
WorkingDirectory=/usr/opt/bitcore
ExecStart=/usr/bin/bitcore-bitcoind -datadir=/home/bitcore/.bitcore/data/
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=15
User=bitcore
ExecStartPre=/bin/mkdir -p /run/bitcore
ExecStartPre=/bin/chown bitcore:bitcore /run/bitcore
ExecStartPre=/bin/chmod 755 /run/bitcore
PermissionsStartOnly=true
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target
5 changes: 0 additions & 5 deletions etc/init/bitcored.conf → scripts/debian/bitcore.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Bitcored Upstart script

description "Bitcore Daemon"
author "BitPay, Inc."

Expand All @@ -18,9 +16,6 @@ setgid bitcore
# home dir of the bitcore daemon user
env HOME=/home/bitcore

# path should include the correct version of node
env PATH=/home/bitcore/.nvm/versions/node/v0.12.7/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

respawn
respawn limit 5 15

Expand Down
20 changes: 20 additions & 0 deletions scripts/debian/bitcore.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description={{ deb_package_description }}
Requires=network.target

[Service]
Type=simple
WorkingDirectory=/usr/opt/bitcore
ExecStart=/usr/opt/bitcore/bin/bitcored
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=15
User=bitcore
ExecStartPre=/bin/mkdir -p /run/bitcore
ExecStartPre=/bin/chown bitcore:bitcore /run/bitcore
ExecStartPre=/bin/chmod 755 /run/bitcore
PermissionsStartOnly=true
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target
8 changes: 8 additions & 0 deletions scripts/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: bitcore
Version: {{ deb_package_version }}
Section: base
Priority: optional
Architecture: {{ deb_package_arch }}
Depends: nodejs, nodejs-legacy, npm, build-essential, libzmq3-dev
Maintainer: {{ deb_package_maintainer }}
Description: {{ deb_package_description }}
37 changes: 37 additions & 0 deletions scripts/debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e
set -o pipefail

# add group
if ! getent group | grep -q "^bitcore:" ; then
echo "Creating system group: bitcore"
groupadd --system bitcore
fi

# add user
if ! getent passwd | grep -q "^bitcore:"; then
echo "Creating bitcore system user"
useradd --gid "bitcore" --system -m bitcore
fi

# build nodejs addons
cd "/usr/opt/bitcore"
SKIP_BITCOIN_DOWNLOAD=1 npm rebuild

# setup data directory
mkdir -p "/home/bitcore/.bitcore/data"
chown -R bitcore:bitcore "/home/bitcore/.bitcore"

# start bitcore
if hash service 2> /dev/null; then
service bitcore start || echo "bitcore could not be registered or started"
elif hash start 2> /dev/null; then
start bitcore || echo "bitcore could not be registered or started"
elif hash systemctl 2> /dev/null; then
{
systemctl enable "bitcore.service" && \
systemctl start "bitcore.service"
} || echo "bitcore could not be registered or started"
else
echo 'Your system does not appear to use upstart or systemd, so bitcore could not be started'
fi
14 changes: 14 additions & 0 deletions scripts/debian/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e
set -o pipefail

if hash service 2> /dev/null; then
service bitcore stop || echo "bitcore wasn't running!"
elif hash stop 2> /dev/null; then
stop "$service_name" || echo "bitcore wasn't running!"
elif hash systemctl 2> /dev/null; then
systemctl disable "bitcore.service" || echo "bitcore wasn't running!"
else
echo "Your system does not appear to use upstart or systemd, so bitcore could not be stopped"
fi

0 comments on commit 476933c

Please sign in to comment.