-
Notifications
You must be signed in to change notification settings - Fork 19
/
node-install.sh
executable file
·57 lines (43 loc) · 1.65 KB
/
node-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Create the 'masa' user and set up home directory
useradd -m masa
# set RPC_URL
RPC_URL=https://ethereum-sepolia.publicnode.com
# Append the RPC_URL to the masa user's .bash_profile
echo "export RPC_URL=${RPC_URL}" | tee -a /home/masa/.bash_profile
# Set permissions for the masa user's home directory
chown masa:masa /home/masa/.bash_profile
# Install Node.js and Yarn
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarn-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update -y && apt-get install -y yarn nodejs jq
# Build go binary
make build
cp masa-node /usr/local/bin/masa-node
chmod +x /usr/local/bin/masa-node
# Determine global npm modules path and set NODE_PATH
GLOBAL_NODE_MODULES=$(npm root -g)
export NODE_PATH=$GLOBAL_NODE_MODULES
MASANODE_CMD="/usr/bin/masa-node --port=4001 --udp=true --tcp=false --start --bootnodes=${BOOTNODES}"
# Create a systemd service file for masa-node
cat <<EOF | sudo tee /etc/systemd/system/masa-node.service
[Unit]
Description=MASA Node Service
After=network.target
[Service]
User=masa
WorkingDirectory=/home/masa
Environment="RPC_URL=${RPC_URL}"
ExecStart=$MASANODE_CMD
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Ensure the service file is owned by root
sudo chown root:root /etc/systemd/system/masa-node.service
# Reload the systemd daemon
sudo systemctl daemon-reload
# Enable and start the masa-node service
sudo systemctl enable masa-node
sudo systemctl start masa-node