Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Merge with upstream
  • Loading branch information
gruve-p committed Aug 6, 2018
2 parents 2637e44 + b96c13e commit 572cec2
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -16,3 +16,5 @@ env:
- IMAGE="debian:8"
- IMAGE="centos:7"
- IMAGE="debian:9"
- IMAGE="alpine:edge"
- IMAGE="ubuntu:18.04"
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -29,10 +29,12 @@ The following operating systems are officially supported and automatically being

| OS | Status |
|----------|---:|
| Ubuntu 18.04 | [![ubuntu](https://badges.herokuapp.com/travis/bauerj/electrumx-installer?env=IMAGE=%22ubuntu:18.04%22&label=ubuntu:18.04)](https://travis-ci.org/bauerj/electrumx-installer/) |
| Debian Jessie | [![debian](https://badges.herokuapp.com/travis/bauerj/electrumx-installer?env=IMAGE=%22debian:8%22&label=debian:8)](https://travis-ci.org/bauerj/electrumx-installer/) |
| Ubuntu 16.04 | [![ubuntu](https://badges.herokuapp.com/travis/bauerj/electrumx-installer?env=IMAGE=%22ubuntu:16.04%22&label=ubuntu:16.04)](https://travis-ci.org/bauerj/electrumx-installer/) |
| CentOS 7 | [![centos](https://badges.herokuapp.com/travis/bauerj/electrumx-installer?env=IMAGE=%22centos:7%22&label=centos:7)](https://travis-ci.org/bauerj/electrumx-installer/) |
| Debian Stretch | [![debian](https://badges.herokuapp.com/travis/bauerj/electrumx-installer?env=IMAGE=%22debian:9%22&label=debian:9)](https://travis-ci.org/bauerj/electrumx-installer/) |
| Alpine Edge | [![alpine](https://badges.herokuapp.com/travis/bauerj/electrumx-installer?env=IMAGE=%22alpine:edge%22&label=alpine:edge)](https://travis-ci.org/bauerj/electrumx-installer/) |


If you prefer a different operating system that's not listed here, see
Expand Down
4 changes: 2 additions & 2 deletions bootstrap.sh
Expand Up @@ -7,14 +7,14 @@ fi
if which git > /dev/null 2>&1; then
git clone https://github.com/Groestlcoin/electrumx-grs-installer ~/.electrumx-grs-installer
else
which wget > /dev/null 2>&1 && which unzip > /dev/null 2>&1 || echo "Please install git or wget and unzip" && exit 1
which wget > /dev/null 2>&1 && which unzip > /dev/null 2>&1 || { echo "Please install git or wget and unzip" && exit 1 ; }
wget https://github.com/Groestlcoin/electrumx-grs-installer/archive/master.zip -O /tmp/electrumx-grs-master.zip
unzip /tmp/electrumx-grs-master.zip -d ~/.electrumx-grs-installer
rm /tmp/electrumx-grs-master.zip
fi
cd ~/.electrumx-grs-installer/
if [[ $EUID -ne 0 ]]; then
which sudo > /dev/null 2>&1 || echo "You need to run this script as root" && exit 1
which sudo > /dev/null 2>&1 || { echo "You need to run this script as root" && exit 1 ; }
sudo -H ./install.sh "$@"
else
./install.sh "$@"
Expand Down
83 changes: 83 additions & 0 deletions distributions/AlpineLinux.sh
@@ -0,0 +1,83 @@
ERROR_EDGE="electrumX-grs can currently be installed only on the edge Version of Alpine Linux"
grep -q -F "/edge/main" /etc/apk/repositories > /dev/null || _error "${ERROR_EDGE}"
grep -q -F "/edge/community" /etc/apk/repositories > /dev/null || _error "${ERROR_EDGE}"

. distributions/base.sh

APK="apk --no-cache"

function install_script_dependencies {
REPO="http://dl-cdn.alpinelinux.org/alpine/edge/testing"
grep -q -F "${REPO}" /etc/apk/repositories || echo "${REPO}" >> /etc/apk/repositories
apk update
$APK add leveldb
$APK add --virtual electrumX-grs-dep openssl wget gcc g++ leveldb-dev
}

function add_user {
adduser -D electrumx-grs
id -u electrumx-grs || _error "Could not add user account" 1
}

function install_python36 {
$APK add python3
$APK add --virtual electrumX-grs-python python3-dev
python3 -m pip install plyvel || _error "Could not install plyvel" 1
ln -s $(which python3.6) /usr/local/bin/python3
}

function install_git {
$APK add --virtual electrumX-grs-git git
}

function install_rocksdb {
$APK add rocksdb
$APK add --virtual electrumX-grs-db rocksdb-dev
}

function install_leveldb {
$APK add leveldb
}

function install_init {
# init is not required. Alpine is used for containers running the program directly
:
}

function generate_cert {
if ! which openssl > /dev/null 2>&1; then
_info "OpenSSL not found. Skipping certificates.."
return
fi
_DIR=$(pwd)
mkdir -p /etc/electrumx-grs/
cd /etc/electrumx-grs
# openssl default configuration is incomplet under alpine.
# Hence adding this configruation from archlinux to allow certificat creation
# https://www.archlinux.org/packages/core/x86_64/openssl/
echo "[ req ]
distinguished_name = req_distinguished_name
[ req_distinguished_name ]
countryName_default = AU
stateOrProvinceName_default = Some-State
0.organizationName_default = Internet Widgits Pty Ltd" > openssl.cnf
openssl genrsa -des3 -passout pass:xxxx -out server.pass.key 2048
openssl rsa -passin pass:xxxx -in server.pass.key -out server.key
rm server.pass.key
openssl req -new -key server.key -batch -out server.csr
openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt
rm server.csr
chown electrumx-grs:electrumx-grs /etc/electrumx-grs -R
chmod 600 /etc/electrumx-grs/server*
cd $_DIR
echo -e "\nSSL_CERTFILE=/etc/electrumx-grs/server.crt" >> /etc/electrumx-grs.conf
echo "SSL_KEYFILE=/etc/electrumx-grs/server.key" >> /etc/electrumx-grs.conf
echo "TCP_PORT=50001" >> /etc/electrumx-grs.conf
echo "SSL_PORT=50002" >> /etc/electrumx-grs.conf
echo -e "# Listen on all interfaces:\nHOST=" >> /etc/electrumx-grs.conf
}

function package_cleanup {
$APK del electrumX-grs-dep electrumX-grs-python electrumX-grs-git electrumX-grs-db
}
33 changes: 24 additions & 9 deletions distributions/Ubuntu.sh
@@ -1,23 +1,38 @@
if [ "$VERSION_ID" != "16.04" ]; then
_warning "Only the latest LTS version (16.04) is officially supported (but this will probably work)"
if [ "$VERSION_ID" != "16.04" ] && [ "$VERSION_ID" != "18.04" ]; then
_warning "Only the last two LTS versions (16.04 and 18.04) are officially supported (but this will probably work)"
fi

. distributions/base.sh
. distributions/base-systemd.sh
. distributions/base-debianoid.sh
. distributions/base-compile-rocksdb.sh

if [ $(ver "$VERSION_ID") -ge $(ver "18.04") ]; then
newer_rocksdb=1
fi

has_rocksdb_binary=1

function install_python36 {
$APT update
$APT install -y software-properties-common || _error "Could not install package" 5
add-apt-repository -y ppa:jonathonf/python-3.6
$APT update
$APT install -y python3.6 python3.6-dev || _error "Could not install package python3.6" 1
ln -s $(which python3.6) /usr/local/bin/python3
if [ "$VERSION_ID" == "16.04" ]; then
$APT install -y software-properties-common || _error "Could not install package" 5
add-apt-repository -y ppa:jonathonf/python-3.6
$APT update
packages="python3.6 python3.6-dev"
else
packages="python3-pip python3.6-dev"
fi
$APT install -y $packages || _error "Could not install package python3.6" 1
ln -s $(which python3.6) /usr/local/bin/python3 > /dev/null
}

function binary_install_rocksdb {
$APT install -y librocksdb-dev liblz4-dev build-essential libsnappy-dev zlib1g-dev libbz2-dev libgflags-dev || _error "Could not install packages" 1
}

function install_rocksdb {
$APT install -y librocksdb-dev build-essential libsnappy-dev zlib1g-dev libbz2-dev libgflags-dev || _error "Could not install packages" 1
function binary_uninstall_rocksdb {
$APT remove -y librocksdb-dev || _error "Could not remove rocksdb" 1
}

function install_leveldb {
Expand Down
24 changes: 14 additions & 10 deletions distributions/base.sh
Expand Up @@ -4,25 +4,22 @@ function create_db_dir {
chown electrumx-grs:electrumx-grs $1
}

function assert_pyrocksdb {
if ! python3 -B -c "import rocksdb"; then
_error "pyrocksdb installation doesn't work"
exit 6
fi
function check_pyrocksdb {
python3 -B -c "import rocksdb"
}

function install_electrumx {
_DIR=$(pwd)
python3 -m pip install multidict || true
rm -rf "/tmp/electrumx-grs/"
git clone https://github.com/Groestlcoin/electrumx-grs /tmp/electrumx-grs
git clone $ELECTRUMX_GIT_URL /tmp/electrumx-grs
cd /tmp/electrumx-grs
if [ $USE_ROCKSDB == 1 ]; then
git checkout $ELECTRUMX_GIT_BRANCH
if [ $USE_ROCKSDB == 1 ]; then
# We don't necessarily want to install plyvel
sed -i "s/'plyvel',//" setup.py
fi
python3 setup.py install > /dev/null 2>&1
if ! python3 setup.py install; then
python3 -m pip install . --upgrade > /dev/null 2>&1
if ! python3 -m pip install . --upgrade; then
_error "Unable to install electrumx-grs" 7
fi
cd $_DIR
Expand All @@ -39,6 +36,11 @@ function install_pyrocksdb {
python3 -m pip install git+git://github.com/stephan-hof/pyrocksdb.git || _error "Could not install pyrocksdb" 1
}

function install_python_rocksdb {
python3 -m pip install "Cython>=0.20"
python3 -m pip install python-rocksdb || _error "Could not install python_rocksdb" 1
}

function add_user {
useradd electrumx-grs
id -u electrumx-grs || _error "Could not add user account" 1
Expand Down Expand Up @@ -67,3 +69,5 @@ function generate_cert {
echo "SSL_PORT=50002" >> /etc/electrumx-grs.conf
echo -e "# Listen on all interfaces:\nHOST=" >> /etc/electrumx-grs.conf
}

function ver { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); }
102 changes: 83 additions & 19 deletions install.sh
Expand Up @@ -8,24 +8,38 @@ NC='\033[0m' # No Color
DB_DIR="/db"
UPDATE_ONLY=0
USE_ROCKSDB=1
ELECTRUMX_GIT_URL="https://github.com/Groestlcoin/electrumx-grs"
ELECTRUMX_GIT_BRANCH="master"

# redirect child output
rm /tmp/electrumx-grs-installer-$$.log > /dev/null 2>&1
exec 3>&1 4>&2 2>/tmp/electrumx-grs-installer-$$.log >&2
installer=$(realpath $0)

cd "$(dirname "$0")"

# Self-update
if which git > /dev/null 2>&1; then
_version_now=$(git rev-parse HEAD)
git pull > /dev/null 2>&1
if [ $_version_now != $(git rev-parse HEAD) ]; then
echo "Updated installer."
exec $installer "$@"
fi
fi

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
cat >&4 <<HELP
cat >&2 <<HELP
Usage: install.sh [OPTIONS]
Install electrumx-grs.
-h --help Show this help
-d --dbdir Set database directory (default: /db/)
--update Update previously installed version
--leveldb Use LevelDB instead of RocksDB
-h --help Show this help
-d --dbdir dir Set database directory (default: /db/)
--update Update previously installed version
--leveldb Use LevelDB instead of RocksDB
--electrumx-grs-git-url url Install ElectrumX-grs from this URL instead
--electrumx-grs-git-branch branch Install specific branch of ElectrumX-grs repository
HELP
exit 0
;;
Expand All @@ -39,14 +53,26 @@ HELP
--leveldb)
USE_ROCKSDB=0
;;
--electrumx-grs-git-url)
ELECTRUMX_GIT_URL="$2"
shift
;;
--electrumx-grs-git-branch)
ELECTRUMX_GIT_BRANCH="$2"
shift
;;
*)
_warning "Unknown option $key"
echo "WARNING: Unknown option $key" >&2
exit 12
;;
esac
shift # past argument or value
done

# redirect child output
rm /tmp/electrumx-grs-installer-$$.log > /dev/null 2>&1
exec 3>&1 4>&2 2>/tmp/electrumx-grs-installer-$$.log >&2


function _error {
if [ -s /tmp/electrumx-grs-installer-$$.log ]; then
Expand Down Expand Up @@ -84,12 +110,12 @@ function _progress {
printf "\r%3d.%1d%% %.${_pd}s" $(( $_progress_count * 100 / $_progress_total )) $(( ($_progress_count * 1000 / $_progress_total) % 10 )) $_pstr >&3
}

rocksdb_compile=1

if [[ $EUID -ne 0 ]]; then
_error "This script must be run as root (e.g. sudo -H $0)" 1
fi

cd "$(dirname "$0")"

if [ -f /etc/os-release ]; then
# Load release information
. /etc/os-release
Expand All @@ -108,7 +134,7 @@ else
fi

if [ $UPDATE_ONLY == 0 ]; then
if which electrumx_server.py > /dev/null 2>&1; then
if which electrumx_server > /dev/null 2>&1; then
_error "electrumx-grs is already installed. Use $0 --update to... update." 9
fi
_status "Installing installer dependencies"
Expand Down Expand Up @@ -140,13 +166,33 @@ if [ $UPDATE_ONLY == 0 ]; then
fi

if [ $USE_ROCKSDB == 1 ]; then
_progress_total=$(( $_progress_total + 2 ))
_status "Installing RocksDB"
install_rocksdb
_status "Installing pyrocksdb"
install_pyrocksdb
_progress_total=$(( $_progress_total + 2 ))
_status "Installing RocksDB"
if [ ! -z $has_rocksdb_binary ]; then
binary_install_rocksdb
else
install_rocksdb
fi
if [ -z $newer_rocksdb ]; then
_status "Installing pyrocksdb"
install_pyrocksdb
else
_status "Installing python_rocksdb"
install_python_rocksdb
fi
_status "Checking pyrocksdb installation"
assert_pyrocksdb
if [ ! check_pyrocksdb ]; then
if [ ! -z $has_rocksdb_binary ]; then
_status "binary rocksdb doesn't work - compiling instead"
binary_uninstall_rocksdb
install_rocksdb
if [ ! check_pyrocksdb ]; then
_error "pyrocksdb installation still doesn't work" 7
fi
else
_error "pyrocksdb installation doesn't work" 6
fi
fi
else
_status "Installing leveldb"
install_leveldb
Expand All @@ -160,9 +206,27 @@ if [ $UPDATE_ONLY == 0 ]; then

_status "Generating TLS certificates"
generate_cert

if declare -f package_cleanup > /dev/null; then
_status "Cleaning up"
package_cleanup
fi
_info "electrumx-grs has been installed successfully. Edit /etc/electrumx-grs.conf to configure it."
else
_info "Updating electrumx-grs"
i=0
while python3 -m pip show electrumx-grs; do
python3 -m pip uninstall -y electrumx-grs || true
((i++))
if "$i" -gt 5; then
break
fi
done
if grep '/usr/local/bin/electrumx_server.py' /etc/systemd/system/electrumx-grs.service; then
_info "Updating pre-1.5 systemd configuration to new binary names"
sed -i -- 's/_server.py/_server/g' /etc/systemd/system/electrumx-grs.service
systemctl daemon-reload
fi
install_electrumx
_info "Installed $(python3 -m pip freeze | grep electrumx-grs)"
_info "Installed $(python3 -m pip freeze | grep -i electrumx-grs)"
fi
3 changes: 3 additions & 0 deletions test/preinstall/alpine
@@ -0,0 +1,3 @@
#!/bin/sh
apk update
apk add bash git

0 comments on commit 572cec2

Please sign in to comment.