Skip to content
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p><strong>INSTALL AS A DAEMON (!!! Tested only on Ubuntu 20.04 !!!)</strong></p>
<p><br />Prerequisites:<br />1. You should install humanode as in original manual (<a href="https://testnet.humanode.io/run-your-own-humanode">https://testnet.humanode.io/run-your-own-humanode</a>)<br />2. Humanode files must be in $HOME/humanode<br />3. Ngrok binary file should be located in /usr/bin</p>
<p>To install humanode and ngrok as a daemon you should to edit installer.sh file and add your own variables:<br />NAME= Your node name, for example "SuPerValiDat0r"<br />RPC_URL= Your Ngrok url, you can see it on the ngrok website (<a href="https://dashboard.ngrok.com/endpoints/status">https://dashboard.ngrok.com/endpoints/status</a>)<br />NGROK_TOKEN= Your Ngrok authentification token</p>
<p>Then make this file executable (run a command chmod +x installer.sh) and run it <strong>AS ROOT!</strong></p>
<p><br />Prerequisites:<br />1. !!! You should have secret phrase (i.e. mnemonic) !!!<br />2. Humanode files must be in $HOME/humanode</p><p>Ngrok binary now is auto install in /usr/bin</p>
<p>To install humanode and ngrok as a daemon you should to edit installer.sh file and add your own variables:<br />NAME= Your node name, for example "SuPerValiDat0r"<br />NGROK_TOKEN= Your Ngrok authentification token<br />SECRET_PHRASE= Your humanode secret phrase (i.e. mnemonic)</p>
<p>RUN $ ./installer.sh</strong></p>
<p>&nbsp;</p>
<p><strong>TELEGRAM NOTIFICATIONS</strong></p>
<p><br />Prerequisites: <br />Humanode and Ngrok should run as a services (daemons)</p>
Expand Down
129 changes: 93 additions & 36 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,60 @@

# REPLACE DEMO VALUES WITH YOUR VALUES
NAME=DEMO_NODE_NAME
RPC_URL=DEMO_UNIQUE_RPC_URL
NGROK_TOKEN=DEMO_NGROK_TOKEN
SECRET_PHRASE=DEMO_SECRET_PHRASE
USER_HOME="/home/your_user_name"

echo "Setting up Humanode service..."
apt install curl jq -y
echo "Check for humanode & ngrok services..."
if [ -f /etc/systemd/system/humanode.service ]
then
systemctl stop humanode&& \
systemctl disable humanode
sleep 2
fi

# Make Humanode startup script
printf "exec 1> >(logger -t humanode) 2>&1
exec /usr/local/bin/humanode-peer --name "$NAME" --validator --chain chainspec.json --rpc-url "$RPC_URL" --rpc-cors all" > $HOME/humanode/start.sh
chmod +x $HOME/humanode/start.sh

# Create Humanode service
printf "[Unit]
Description=humanode
After=network.service

[Service]
type=simple
User=$USER
WorkingDirectory=$HOME/humanode
ExecStart=$HOME/humanode/start.sh
Restart=on-failure
if [ -f /etc/systemd/system/ngrok.service ]
then
systemctl stop ngrok&& \
systemctl disable ngrok
sleep 2
fi

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/humanode.service
echo "Install packages ..."
apt install curl jq wget unzip -y
sleep 2

# Enable & run Humanode service
systemctl daemon-reload && \
systemctl enable humanode && \
systemctl start humanode && \
systemctl restart systemd-journald

# View last 50 lines of Humanode log
journalctl -u humanode -n 50 | cat
if [ -f /usr/bin/ngrok ]
then
echo "Found ngrok in /usr/bin ..."
else
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
rm ngrok-stable-linux-amd64.zip
mv ./ngrok /usr/bin/ngrok
chmod +x /usr/bin/ngrok
sleep 2
fi

echo "Setting up Ngrok service..."
echo Copy new files from $USER_HOME/humanode to $HOME/humanode ...
#move humanode folder to /root
if [ -d $USER_HOME/humanode ]
then
echo Found $HOME/humanode ...
sleep 2
mkdir $HOME/humanode
cp $USER_HOME/humanode/chainspec.json $HOME/humanode/chainspec.json
cp $USER_HOME/humanode/binaries/$(uname -s)-$(uname -m)/humanode-peer $HOME/humanode/humanode-peer
sleep 2
else
echo TODO: unzip humanode-testnet1.zip $USER_HOME/humanode \
then run that script again ...
exit
fi

echo "Configure & run ngrok.service..."
# Make Ngrok config file
rm -rf $HOME/.ngrok2
mkdir $HOME/.ngrok2
printf "authtoken: $NGROK_TOKEN
tunnels:
Expand All @@ -54,7 +70,7 @@ Description=Ngrok
After=network.service

[Service]
type=simple
Type=simple
User=$USER
WorkingDirectory=$HOME/.ngrok2
ExecStart=/usr/bin/ngrok start --all --config="ngrok.yml"
Expand All @@ -63,10 +79,51 @@ Restart=on-failure
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/ngrok.service

systemctl daemon-reload
# Enable & run Ngrok service
systemctl daemon-reload && \
systemctl enable ngrok && \
systemctl start ngrok

systemctl enable ngrok && \
systemctl start ngrok && \
systemctl status ngrok
# View Ngrok status
curl localhost:4040/api/tunnels | jq
# curl localhost:4040/api/tunnels | jq
curl localhost:4040/api/tunnels | jq > $HOME/humanode/ngrok_tunnels.json
RPC_URL=$(echo "$public_url" | jq '.tunnels[0].public_url' $HOME/humanode/ngrok_tunnels.json)
sleep 2

cd $HOME/humanode
install -m 0755 "humanode-peer" /usr/local/bin
humanode-peer key insert --key-type aura --suri "$SECRET_PHRASE" --chain chainspec.json
echo "Make Humanode startup script ..."
printf "exec 1> >(logger -t humanode) 2>&1
exec /usr/local/bin/humanode-peer --name "$NAME" --validator --chain chainspec.json --rpc-url "$RPC_URL" --rpc-cors all" > $HOME/humanode/start.sh
chmod +x $HOME/humanode/start.sh
ls
sleep 2

# View last 50 lines of Humanode log
# journalctl -u humanode -n 50 | cat

echo "Configure & run humanode.service..."
# Create Humanode service
printf "[Unit]
Description=humanode
After=network.service

[Service]
Type=simple
User=$USER
WorkingDirectory=$HOME/humanode
ExecStart=/bin/bash $HOME/humanode/start.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/humanode.service

systemctl daemon-reload
# Enable & run Humanode service
systemctl enable humanode && \
systemctl start humanode && \
systemctl restart systemd-journal

systemctl status humanode
journalctl -u humanode -f
30 changes: 21 additions & 9 deletions telegram-notify.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#!/bin/bash

#
#Make telegram-send script and move it to /usr/bin folder
printf "#!/bin/bash
GROUP_ID="TELEGRAM_GROUP_ID"
BOT_TOKEN="YOUR_TELEGRAM_TOKEN"
curl -s --data "text=$1" --data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null" > /usr/bin/telegram-send
#
# script for sending TEXT/FILE to Telegram
#
# Usage: telegram-send "<text>" or "</path/to/file>"
# ..."folder non-exist" errors may be ignored
#
SEND_ME=$1
CHAT_ID=""
BOT_TOKEN=""
#
# Sending text-message
curl --socks5-basic \
-X POST https://api.telegram.org/bot$BOT_TOKEN/sendMessage \
-d chat_id=$CHAT_ID -d text="$SEND_ME"
#
chmod +x /usr/bin/telegram-send && \
chown root:root /usr/bin/telegram-send

#Add script to crontab (Run every 15 minutes)
#
# Add script to crontab (Run every 15 minutes)
crontab -l | { cat; echo "*/15 * * * * /$HOME/humanode/notify.sh >/dev/null 2>&1"; } | crontab -

#Send test message to Telegram
telegram-send "Test!"
#
# Send test message to Telegram
telegram-send "Working ..."