67 lines
1.4 KiB
Bash
67 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Simulate NodeInfo as separate variables
|
|
NodeInfo_IPV4="192.168.1.20"
|
|
NodeInfo_ServerPort="9000"
|
|
|
|
# UUID fallback
|
|
generate_uuid() {
|
|
echo "uuid-$(date +%s%N)"
|
|
}
|
|
|
|
P2PRCMapPort() {
|
|
local port="$1"
|
|
local domain="$2"
|
|
local server="$3"
|
|
echo "${domain}:${port}"
|
|
}
|
|
|
|
AddProcessToMemory() {
|
|
local id="$1"
|
|
echo "Added to memory: $id"
|
|
}
|
|
|
|
SaveProcess() {
|
|
echo "Saved to disk (simulated)"
|
|
}
|
|
|
|
SpinProcess() {
|
|
# Parameters are passed as positional args
|
|
local InternalPortNo="$1"
|
|
local CommandToRunScript="$2"
|
|
local DomainName="$3"
|
|
|
|
# Run script (locally)
|
|
bash "$CommandToRunScript"
|
|
|
|
# Server address
|
|
local ServerAddress="${NodeInfo_IPV4}:${NodeInfo_ServerPort}"
|
|
|
|
# Map port
|
|
local ExternalAddress
|
|
ExternalAddress=$(P2PRCMapPort "$InternalPortNo" "$DomainName" "$ServerAddress")
|
|
|
|
# Generate UUID and set status
|
|
local ID
|
|
ID=$(generate_uuid)
|
|
local Status="true"
|
|
|
|
# Output simulated "process object"
|
|
echo "Process Started:"
|
|
echo "ID: $ID"
|
|
echo "InternalPortNo: $InternalPortNo"
|
|
echo "ExternalAddress: $ExternalAddress"
|
|
echo "DomainName: $DomainName"
|
|
echo "Status: $Status"
|
|
|
|
AddProcessToMemory "$ID"
|
|
SaveProcess
|
|
}
|
|
|
|
# Example usage
|
|
InternalPortNo="8080"
|
|
CommandToRunScript="test.sh"
|
|
DomainName="example.com"
|
|
|
|
SpinProcess "$InternalPortNo" "$CommandToRunScript" "$DomainName"
|