Skip to content

Commit 2d24974

Browse files
committed
fix: start node script
1 parent e37dfb5 commit 2d24974

3 files changed

Lines changed: 176 additions & 39 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
sudo apt install wireguard
3+
4+
5+
sudo rm -rf /etc/systemd/system/dvpn-node.service
6+
sudo rm -rf /home/user/.qubetics-dvpnx
7+
8+
9+
10+
sudo nano /etc/systemd/system/dvpn-node.service
11+
12+
sudo systemctl daemon-reload
13+
sudo systemctl restart dvpn-node.service
14+
journalctl -u dvpn-node.service -f
15+
16+
curl -k https://112.196.81.250:18133
17+
18+
19+
API_PORT=18133
20+
21+
22+
23+
sudo setcap cap_net_admin+ep /path/to/your-binary
24+
25+
================= wireguadr uninstall
26+
27+
28+
# Stop any running WireGuard interfaces
29+
sudo wg-quick down wg0 # repeat for other interfaces if any
30+
31+
# Remove WireGuard packages
32+
sudo apt purge wireguard wireguard-tools -y
33+
34+
# Remove dependencies no longer needed
35+
sudo apt autoremove -y
36+
37+
# Delete configuration directory
38+
sudo rm -rf /etc/wireguard

setup_wireguard.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ show_usage() {
9494
exit 1
9595
}
9696

97+
wireguard_install(){
98+
sudo apt update
99+
sudo apt install -y wireguard wireguard-tools
100+
101+
}
97102
# Parse command line arguments
98103
parse_arguments() {
99104
while [[ $# -gt 0 ]]; do
@@ -115,6 +120,7 @@ parse_arguments() {
115120

116121
# Main execution
117122
main() {
123+
wireguard_install
118124
parse_arguments "$@"
119125
check_root
120126
handle_keys

start-node.sh

Lines changed: 132 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
#!/usr/bin/env bash
22

3-
# --- Go Installation Check ---
3+
set -Eeou pipefail
4+
5+
NODE_DIR="${HOME}/.qubetics-dvpnx"
6+
BINARY="${BINARY:-qubetics-dvpnx}" # Default binary name; override by setting $BINARY
7+
CONTAINER_NAME=qubetics-node
8+
API_PORT=18133
9+
SERVICE_PORT=21529
10+
PUBLIC_IP=$(curl -fsSL https://ifconfig.me)
11+
CHAIN_RPC="http://111.119.253.129:26657"
12+
CHAIN_ID="qubetics_9003-1"
13+
KEYRING_BACKEND="test"
14+
KEYRING_NAME="qubetics"
15+
LOG_LEVEL="debug"
16+
WG_CONF="/etc/wireguard/wg0.conf"
17+
18+
function cmd_help {
19+
echo "Usage: ${0} [COMMAND]"
20+
echo ""
21+
echo "Commands:"
22+
echo " init Initialize configuration and keys"
23+
echo " start Start the node"
24+
echo " stop Stop the node process (if backgrounded)"
25+
echo " restart Restart the node"
26+
echo " status Show node logs (if running)"
27+
echo " help Print this help message"
28+
}
29+
30+
31+
32+
33+
34+
35+
36+
function cmd_init {
37+
# --- Go Installation Check ---
438
if ! command -v go &> /dev/null; then
539
echo "Go not found. Installing Go..."
640
bash "$(dirname "$0")/install-go.sh"
@@ -11,46 +45,33 @@ else
1145
echo "Go is already installed. Skipping installation."
1246
fi
1347

14-
set -Eeou pipefail
15-
NODE_DIR="${HOME}/.qubetics-dvpnx"
16-
BINARY="${BINARY:-qubetics-dvpnx}" # Default binary name; override by setting $BINARY
17-
CONTAINER_NAME=qubetics-node # For legacy cmd compatibility
18-
API_PORT=18133
19-
SERVICE_PORT=21529
20-
PUBLIC_IP=$(curl -fsSL https://ifconfig.me)
21-
2248
# --- Binary Download Logic ---
2349
# Detect Ubuntu version
24-
UBUNTU_VERSION=$(lsb_release -rs | cut -d. -f1)
25-
50+
UBUNTU_VERSION=$(lsb_release -rs)
2651
# Set binary download URL (update this if your release URL pattern is different)
27-
BINARY_URL="https://github.com/Qubetics/dvpn-node-script/releases/latest/download/${BINARY}-ubuntu${UBUNTU_VERSION}"
52+
BINARY_URL="https://github.com/Qubetics/dvpn-node-script/releases/download/ubuntu${UBUNTU_VERSION}/${BINARY}"
53+
echo $BINARY_URL
2854

2955

56+
# curl -k https://101.44.160.159:18133/
3057
# Target directory for binary
31-
INSTALL_PATH="/usr/local/bin/"
32-
mkdir -p "$INSTALL_PATH"
58+
GOLANGPATH=$(which go)
59+
INSTALL_PATH="$(dirname "$GOLANGPATH")"
60+
# Remove trailing '/go' if present
61+
if [[ "$INSTALL_PATH" == */go ]]; then
62+
INSTALL_PATH="${INSTALL_PATH%/go}"
63+
fi
64+
echo "INSTALL PATH OF THE BINARY:" $INSTALL_PATH/
65+
3366

3467
# Download and move binary
3568
echo "Downloading binary for Ubuntu $UBUNTU_VERSION: $BINARY_URL"
3669
curl -L "$BINARY_URL" -o "/tmp/${BINARY}"
3770
chmod +x "/tmp/${BINARY}"
38-
mv "/tmp/${BINARY}" "$INSTALL_PATH${BINARY}"
39-
echo "Binary moved to $INSTALL_PATH${BINARY}"
71+
sudo mv "/tmp/${BINARY}" "$INSTALL_PATH/${BINARY}"
72+
echo "Binary moved to $INSTALL_PATH/${BINARY}"
4073

41-
function cmd_help {
42-
echo "Usage: ${0} [COMMAND]"
43-
echo ""
44-
echo "Commands:"
45-
echo " init Initialize configuration and keys"
46-
echo " start Start the node"
47-
echo " stop Stop the node process (if backgrounded)"
48-
echo " restart Restart the node"
49-
echo " status Show node logs (if running)"
50-
echo " help Print this help message"
51-
}
5274

53-
function cmd_init {
5475
mkdir -p "${NODE_DIR}"
5576
MONIKER="node-$(openssl rand -hex 4)"
5677

@@ -78,11 +99,11 @@ function cmd_init {
7899
--node.gigabyte-prices "200;200;tics" \
79100
--node.hourly-prices "20;20;tics" \
80101
--node.type "${NODE_TYPE}" \
81-
--rpc.addrs "http://111.119.253.129:26657" \
82-
--rpc.chain-id "qubetics_9009-1" \
102+
--rpc.addrs "${CHAIN_RPC}" \
103+
--rpc.chain-id "${CHAIN_ID}" \
83104
--with-tls \
84-
--keyring.backend "test" \
85-
--keyring.name "qubetics"
105+
--keyring.backend "${KEYRING_BACKEND}" \
106+
--keyring.name "${KEYRING_NAME}"
86107

87108

88109

@@ -93,8 +114,8 @@ function cmd_init {
93114
fi
94115
"${BINARY}" keys add "${ACCOUNT_NAME}" \
95116
--home "${NODE_DIR}" \
96-
--keyring.backend "test" \
97-
--keyring.name "qubetics"
117+
--keyring.backend "${KEYRING_BACKEND}" \
118+
--keyring.name "${KEYRING_NAME}"
98119

99120
# Update from_name in config.toml with the account name
100121
if [[ -f "${NODE_DIR}/config.toml" ]]; then
@@ -113,6 +134,43 @@ function cmd_init {
113134

114135

115136
function cmd_start {
137+
# wg-quick down wg0
138+
# Extract WireGuard config values using sudo
139+
if sudo test -f "$WG_CONF"; then
140+
WG_ADDRESS=$(sudo grep -m1 '^Address' "$WG_CONF" | sed -E 's/.*[:=][[:space:]]*//')
141+
WG_LISTENPORT=$(sudo grep -m1 '^ListenPort' "$WG_CONF" | awk -F '=' '{print $2}')
142+
WG_PRIVATEKEY=$(sudo grep -m1 '^PrivateKey' "$WG_CONF" | awk -F '=' '{print $2}')
143+
PRIVATE_KEY=$(echo "$WG_PRIVATEKEY" | xargs)
144+
if [[ "$PRIVATE_KEY" != *= ]]; then
145+
PRIVATE_KEY="${PRIVATE_KEY}="
146+
fi
147+
echo "WireGuard Config:"
148+
echo "- Address: $WG_ADDRESS"
149+
echo "- ListenPort: $WG_LISTENPORT"
150+
echo "- PrivateKey: $PRIVATE_KEY"
151+
else
152+
echo "WireGuard config not found at $WG_CONF"
153+
fi
154+
155+
# Update ~/.qubetics-dvpnx/config.toml [wireguard] section with values from wg0.conf
156+
CONFIG_TOML="${NODE_DIR}/config.toml"
157+
if [[ -f "$CONFIG_TOML" ]]; then
158+
# Extract first IPv4 address from WG_ADDRESS (Address can be comma-separated and include IPv6)
159+
if [[ -n "$WG_ADDRESS" && -n "$WG_LISTENPORT" && -n "$WG_PRIVATEKEY" ]]; then
160+
echo "Updating $CONFIG_TOML [wireguard] ipv4_addr, port, private_key"
161+
cp "$CONFIG_TOML" "${CONFIG_TOML}.bak.$(date +%s)"
162+
# Replace only inside [wireguard] section
163+
sed -i -E '/^\[wireguard\]/,/^\[/ {
164+
s|^ipv4_addr = .*|ipv4_addr = "'"${WG_ADDRESS//&/\\&}"'"|
165+
s|^port = .*|port = "'"${WG_LISTENPORT//&/\\&}"'"|
166+
s|^private_key = .*|private_key = "'"${PRIVATE_KEY//&/\\&}"'"|
167+
}' "$CONFIG_TOML"
168+
else
169+
echo "WireGuard values missing; skipping config.toml update"
170+
fi
171+
else
172+
echo "Config file not found at $CONFIG_TOML"
173+
fi
116174
echo "=== Starting Node ==="
117175
# Generate random ports
118176
mapfile -t PORTS < <(shuf -i 1024-65535 -n 2)
@@ -154,14 +212,47 @@ function cmd_start {
154212

155213

156214
echo "Starting node with command:"
157-
echo "${BINARY} start --home ${NODE_DIR} --keyring.backend test --node.remote-addrs ${NODE_REMOTE_URL}"
215+
echo "${BINARY} start --home ${NODE_DIR} --keyring.backend ${KEYRING_BACKEND} --node.remote-addrs ${NODE_REMOTE_URL}"
158216

159217
# Start the node
160-
"${BINARY}" start \
161-
--home "${NODE_DIR}" \
162-
--keyring.backend "test"
163-
--log.level "debug"
218+
# "${BINARY}" start \
219+
# --home "${NODE_DIR}" \
220+
# --keyring.backend "${KEYRING_BACKEND}"
221+
# --log.level "${LOG_LEVEL}"
222+
# sudo systemctl start wg-quick@wg0
223+
# echo "Starting node:"
224+
# #========================================================================================================================================================
225+
# sudo su -c "echo '[Unit]
226+
# Description=Qubetics dVPN Node
227+
# Wants=network-online.target
228+
# After=network-online.target
229+
# [Service]
230+
# User=$(whoami)
231+
# Group=$(whoami)
232+
# Type=simple
233+
# ExecStart=/${HOME}/.go/bin/qubetics-dvpnx start --home $NODE_DIR --keyring.backend test
234+
# Restart=always
235+
# RestartSec=5
236+
# LimitNOFILE=65536
237+
# Environment="DAEMON_NAME=$BINARY"
238+
# Environment="DAEMON_HOME="$NODE_DIR""
239+
# Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
240+
# Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
241+
# Environment="DAEMON_LOG_BUFFER_SIZE=512"
242+
# Environment="UNSAFE_SKIP_BACKUP=false"
243+
# [Install]
244+
# WantedBy=multi-user.target'> /etc/systemd/system/dvpn-node.service"
164245

246+
# sudo systemctl daemon-reload
247+
# sudo systemctl enable dvpn-node.service
248+
# sudo systemctl start dvpn-node.service
249+
250+
# # Wait a few minutes before fetching node address
251+
# echo "Waiting 30 seconds for node to initialize..."
252+
# sleep 30
253+
# NODE_ADDR=$(curl -sk https://$PUBLIC_IP:$API_PORT | jq -r '.result.addr')
254+
# NODE_ADDR=$(curl -sk https://125.21.216.158:18133 | jq -r '.result.addr')
255+
# echo "Node address: $NODE_ADDR"
165256
}
166257

167258
function cmd_status {
@@ -190,3 +281,5 @@ case "${v}" in
190281
"status") cmd_status ;;
191282
"help" | *) cmd_help ;;
192283
esac
284+
285+

0 commit comments

Comments
 (0)