2015-05-24 23:01:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-12-02 21:41:55 +01:00
|
|
|
#set -e
|
|
|
|
|
2015-05-24 23:01:16 +02:00
|
|
|
# Retrieve arguments
|
2015-12-25 21:33:56 +01:00
|
|
|
app=ucoin
|
2015-05-24 23:01:16 +02:00
|
|
|
domain=$1
|
2015-12-25 21:33:56 +01:00
|
|
|
path=$2
|
|
|
|
port=$3
|
|
|
|
sync_node=$4
|
|
|
|
sync_port=$5
|
|
|
|
salt=$6
|
|
|
|
password=$7
|
2015-06-04 21:59:29 +02:00
|
|
|
#cpu=$(($7/100))
|
2015-06-02 23:57:56 +02:00
|
|
|
#cpu=`expr $7 / 100`
|
2015-12-25 21:33:56 +01:00
|
|
|
data_path=/home/yunohost.app/ucoin
|
|
|
|
ucoin="node --harmony $data_path/bin/ucoind"
|
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a $app \
|
|
|
|
|| (echo "Path not available: $domain$path" && exit 1)
|
|
|
|
|
|
|
|
# Check port availability
|
|
|
|
sudo yunohost app checkport $port
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Open port on firewall
|
|
|
|
sudo yunohost firewall allow TCP $port > /dev/null 2>&1
|
|
|
|
|
|
|
|
# Store config on YunoHost instance
|
|
|
|
sudo yunohost app setting $app port -v $port
|
|
|
|
sudo yunohost app setting $app data_path -v $data_path
|
2015-05-24 23:01:16 +02:00
|
|
|
|
2015-12-02 21:41:55 +01:00
|
|
|
# Install dependencies: nodejs 0.12.x, npm
|
|
|
|
#sudo apt -y -qq install npm node nodejs-legacy
|
|
|
|
sudo apt -y -qq install curl g++ make
|
|
|
|
sudo curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
|
|
|
|
sudo apt -y -qq install nodejs
|
2015-05-24 23:01:16 +02:00
|
|
|
|
|
|
|
# Install uCoin node and pm2 daemon manager
|
2015-12-02 21:41:55 +01:00
|
|
|
cd /home/yunohost.app/
|
|
|
|
sudo git clone https://github.com/ucoin-io/ucoin
|
2015-12-25 21:33:56 +01:00
|
|
|
cd $data_path
|
2015-12-02 21:41:55 +01:00
|
|
|
sudo npm install
|
|
|
|
sudo npm install -g pm2
|
2015-05-24 23:01:16 +02:00
|
|
|
|
2015-12-25 21:33:56 +01:00
|
|
|
# Configure uCoin node
|
2015-12-02 21:41:55 +01:00
|
|
|
$ucoin init --autoconf
|
2015-12-25 21:33:56 +01:00
|
|
|
$ucoin config --remoteh $domain --port $port --remotep $port --salt $salt --passwd $password # --cpu $cpu
|
|
|
|
|
|
|
|
# Synchronize uCoin node
|
|
|
|
echo "Synchronizing with $sync_node:$sync_port"
|
|
|
|
$ucoin sync $sync_node $sync_port --nointeractive > /dev/null 2>&1
|
2015-05-24 23:01:16 +02:00
|
|
|
|
2015-06-04 21:59:29 +02:00
|
|
|
# Launch uCoin node with pm2 daemon
|
2015-12-25 21:33:56 +01:00
|
|
|
sudo pm2 start $data_path/bin/ucoind --name ucoin --interpreter=node --node-args="--harmony" --log /var/log/$app.log -- start
|
2015-12-02 21:41:55 +01:00
|
|
|
|
|
|
|
# Add uCoin service to the YunoHost monitoring
|
2015-12-25 21:33:56 +01:00
|
|
|
sudo yunohost service add $app --log /var/log/$app.log
|
|
|
|
|
|
|
|
# SSOwat Configuration
|
|
|
|
sudo yunohost app setting $app skipped_uris -v "/"
|
|
|
|
|
|
|
|
# Add proxy_pass
|
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@" ../conf/nginx.conf
|
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PORT@$port@" ../conf/nginx.conf
|
|
|
|
sudo sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@" ../conf/nginx.conf
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
sudo service nginx reload
|