Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion mytoninstaller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import base64

from mytoncore.utils import hex2b64, dict2b64
from mytoninstaller.utils import StartMytoncore, GetInitBlock
from mytoninstaller.utils import StartMytoncore, GetInitBlock, get_ed25519_pubkey_text
from mypylib.mypylib import ip2int, Dict


Expand Down Expand Up @@ -134,3 +134,19 @@ def GetLiteServerConfig(local):
result.id.key= key.decode()
return result
#end define

def get_ls_proxy_config(local):
ls_proxy_config_path = "/var/ls_proxy/ls-proxy-config.json"
ls_proxy_config = GetConfig(path=ls_proxy_config_path)
ip = get_own_ip()
port = ls_proxy_config.ListenAddr.split(':')[1]
privkey_text = ls_proxy_config.Clients[0].PrivateKey

result = Dict()
result.ip = ip2int(ip)
result.port = port
result.id = Dict()
result.id["@type"]= "pub.ed25519"
result.id.key= get_ed25519_pubkey_text(privkey_text)
return result
#end define
86 changes: 55 additions & 31 deletions mytoninstaller/mytoninstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
import json
import subprocess

from mypylib.mypylib import MyPyClass, run_as_root
from mypylib.mypylib import MyPyClass, run_as_root, color_print
from mypyconsole.mypyconsole import MyPyConsole

from mytoninstaller.config import GetLiteServerConfig
from mytoninstaller.config import GetLiteServerConfig, get_ls_proxy_config
from mytoninstaller.utils import GetInitBlock
from mytoncore.utils import dict2b64, str2bool, b642dict

from mytoninstaller.settings import (
FirstNodeSettings,
FirstMytoncoreSettings,
EnableValidatorConsole,
EnableLiteServer,
EnableDhtServer,
EnableJsonRpc,
EnablePytonv3,
FirstNodeSettings,
FirstMytoncoreSettings,
EnableValidatorConsole,
EnableLiteServer,
EnableDhtServer,
EnableJsonRpc,
EnableTonHttpApi,
DangerousRecoveryValidatorConfigFile,
CreateSymlinks,
DangerousRecoveryValidatorConfigFile,
CreateSymlinks,
enable_ls_proxy
)
from mytoninstaller.config import (
CreateLocalConfig,
BackupVconfig,
BackupMconfig,
CreateLocalConfig,
BackupVconfig,
BackupMconfig,
)

from functools import partial
Expand Down Expand Up @@ -62,10 +62,12 @@ def inject_globals(func):
console.name = "MyTonInstaller"
console.color = console.RED
console.AddItem("status", inject_globals(Status), "Print TON component status")
console.AddItem("enable", inject_globals(Enable), "Enable some function: 'FN' - Full node, 'VC' - Validator console, 'LS' - Liteserver, 'DS' - DHT-Server, 'JR' - jsonrpc, 'PT' - ton-http-api. Example: 'enable FN'")
console.AddItem("enable", inject_globals(Enable), "Enable some function")
console.AddItem("update", inject_globals(Enable), "Update some function: 'JR' - jsonrpc. Example: 'update JR'")
console.AddItem("plsc", inject_globals(PrintLiteServerConfig), "Print LiteServer config")
console.AddItem("clcf", inject_globals(CreateLocalConfigFile), "CreateLocalConfigFile")
console.AddItem("plsc", inject_globals(PrintLiteServerConfig), "Print lite-server config")
console.AddItem("clcf", inject_globals(CreateLocalConfigFile), "Create lite-server config file")
console.AddItem("print_ls_proxy_config", inject_globals(print_ls_proxy_config), "Print ls-proxy config")
console.AddItem("create_ls_proxy_config_file", inject_globals(create_ls_proxy_config_file), "Create ls-proxy config file")
console.AddItem("drvcf", inject_globals(DRVCF), "Dangerous recovery validator config file")
console.AddItem("setwebpass", inject_globals(SetWebPassword), "Set a password for the web admin interface")

Expand Down Expand Up @@ -123,10 +125,22 @@ def Status(local, args):


def Enable(local, args):
name = args[0]
if name == "PT":
try:
name = args[0]
except:
color_print("{red}Bad args. Usage:{endc} enable <mode-name>")
print("'FN' - Full node")
print("'VC' - Validator console")
print("'LS' - Lite-Server")
print("'DS' - DHT-Server")
print("'JR' - jsonrpc")
print("'THA' - ton-http-api")
print("'LSP' - ls-proxy")
print("Example: 'enable FN'")
return
if name == "THA":
CreateLocalConfigFile(local, args)
args = ["python3", "-m", "mytoninstaller", "-u", local.buffer.user, "-e", "enable{name}".format(name=name)]
args = ["python3", "-m", "mytoninstaller", "-u", local.buffer.user, "-e", f"enable{name}"]
run_as_root(args)
#end define

Expand Down Expand Up @@ -159,6 +173,15 @@ def CreateLocalConfigFile(local, args):
run_as_root(args)
#end define

def print_ls_proxy_config(local, args):
ls_proxy_config = get_ls_proxy_config(local)
text = json.dumps(ls_proxy_config, indent=4)
print(text)
#end define

def create_ls_proxy_config_file(local, args):
print("TODO")
#end define

def Event(local, name):
if name == "enableFN":
Expand All @@ -173,9 +196,10 @@ def Event(local, name):
DangerousRecoveryValidatorConfigFile(local)
if name == "enableJR":
EnableJsonRpc(local)
if name == "enablePT":
# EnablePytonv3(local)
if name == "enableTHA":
EnableTonHttpApi(local)
if name == "enableLSP":
enable_ls_proxy(local)
if name == "clc":
ix = sys.argv.index("-i")
initBlock_b64 = sys.argv[ix+1]
Expand Down Expand Up @@ -219,12 +243,12 @@ def General(local):
### Start of the program
###
def mytoninstaller():
local = MyPyClass(__file__)
console = MyPyConsole()

Init(local, console)
if len(sys.argv) > 1:
General(local)
else:
console.Run()
local.exit()
local = MyPyClass(__file__)
console = MyPyConsole()

Init(local, console)
if len(sys.argv) > 1:
General(local)
else:
console.Run()
local.exit()
103 changes: 103 additions & 0 deletions mytoninstaller/scripts/ls_proxy_installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
set -e

# Проверить sudo
if [ "$(id -u)" != "0" ]; then
echo "Please run script as root"
exit 1
fi

# install parameters
src_path=/usr/src
bin_path=/usr/bin
openssl_path=${bin_path}/openssl_3

# Get arguments
while getopts u:s:b:o: flag
do
case "${flag}" in
u) user=${OPTARG};;
s) src_path=${OPTARG};;
b) bin_path=${OPTARG};;
o) openssl_path=${OPTARG};;
*)
echo "Flag -${flag} is not recognized. Aborting"
exit 1;;
esac
done

# install parameters
author=xssnick
repo=tonutils-liteserver-proxy
branch=master
bin_name=ls_proxy

# Цвета
COLOR='\033[95m'
ENDC='\033[0m'

# Клонирование репозиториев с github.com
echo -e "${COLOR}[1/4]${ENDC} Cloning github repository"
echo "https://github.com/${author}/${repo}.git -> ${branch}"

cd ${src_path}
rm -rf ${repo}
git clone --branch=${branch} --recursive https://github.com/${author}/${repo}.git

# Установка компонентов
echo -e "${COLOR}[2/4]${ENDC} Installing required packages"

arc=$(dpkg --print-architecture)
go_version_url=https://go.dev/VERSION?m=text
go_version=$(curl -s ${go_version_url} | head -n 1)
go_url=https://go.dev/dl/${go_version}.linux-${arc}.tar.gz
go_path=/usr/local/go/bin/go
rm -rf /usr/local/go
wget -c ${go_url} -O - | tar -C /usr/local -xz

# Расчитываем количество процессоров для сборки
if [[ "$OSTYPE" =~ darwin.* ]]; then
cpu_number=$(sysctl -n hw.logicalcpu)
else
memory=$(cat /proc/meminfo | grep MemAvailable | awk '{print $2}')
cpu_number=$(($memory/2100000))
max_cpu_number=$(nproc)
if [ ${cpu_number} -gt ${max_cpu_number} ]; then
cpu_number=$((${max_cpu_number}-1))
fi
if [ ${cpu_number} == 0 ]; then
echo "Warning! insufficient RAM"
cpu_number=1
fi
fi

# Компилируем из исходников
echo -e "${COLOR}[3/4]${ENDC} Source compilation, use ${cpu_number} cpus"

proxy_src_path=${src_path}/${repo}
ton_src_path=${proxy_src_path}/ton
proxy_internal_path=${proxy_src_path}/internal/emulate/lib

proxy_build_path=${bin_path}/${bin_name}
ton_build_path=${proxy_build_path}/ton
proxy_db_path=/var/${bin_name}
proxy_lib_path=${proxy_db_path}/lib

mkdir -p ${proxy_lib_path}
mkdir -p ${ton_build_path} && cd ${ton_build_path}
cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=${openssl_path}/include -DOPENSSL_CRYPTO_LIBRARY=${openssl_path}/libcrypto.a ${ton_src_path}
make emulator -j ${cpu_number}
cp ${ton_build_path}/emulator/libemulator.so ${proxy_lib_path}
cp ${ton_build_path}/emulator/libemulator.so ${proxy_internal_path}
cp ${ton_build_path}/emulator/emulator_export.h ${proxy_internal_path}

# Компилируем
cd ${proxy_src_path}
CGO_ENABLED=1 ${go_path} build -o ${proxy_db_path}/${bin_name} ${proxy_src_path}/cmd/main.go

# Настроить директорию работы
chown -R ${user}:${user} ${proxy_db_path}

# Выход из программы
echo -e "${COLOR}[4/4]${ENDC} ${bin_name} installation complete"
exit 0
Loading