Skip to content

Commit 6438876

Browse files
authored
Merge pull request #194 from ton-blockchain/mytonctrl2_dev_installer
add ls-proxy installer
2 parents 78275ac + ff977ef commit 6438876

File tree

9 files changed

+335
-144
lines changed

9 files changed

+335
-144
lines changed

mytoninstaller/config.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import base64
66

77
from mytoncore.utils import hex2b64, dict2b64
8-
from mytoninstaller.utils import StartMytoncore, GetInitBlock
8+
from mytoninstaller.utils import StartMytoncore, GetInitBlock, get_ed25519_pubkey_text
99
from mypylib.mypylib import ip2int, Dict
1010

1111

@@ -134,3 +134,19 @@ def GetLiteServerConfig(local):
134134
result.id.key= key.decode()
135135
return result
136136
#end define
137+
138+
def get_ls_proxy_config(local):
139+
ls_proxy_config_path = "/var/ls_proxy/ls-proxy-config.json"
140+
ls_proxy_config = GetConfig(path=ls_proxy_config_path)
141+
ip = get_own_ip()
142+
port = ls_proxy_config.ListenAddr.split(':')[1]
143+
privkey_text = ls_proxy_config.Clients[0].PrivateKey
144+
145+
result = Dict()
146+
result.ip = ip2int(ip)
147+
result.port = port
148+
result.id = Dict()
149+
result.id["@type"]= "pub.ed25519"
150+
result.id.key= get_ed25519_pubkey_text(privkey_text)
151+
return result
152+
#end define

mytoninstaller/mytoninstaller.py

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77
import json
88
import subprocess
99

10-
from mypylib.mypylib import MyPyClass, run_as_root
10+
from mypylib.mypylib import MyPyClass, run_as_root, color_print
1111
from mypyconsole.mypyconsole import MyPyConsole
1212

13-
from mytoninstaller.config import GetLiteServerConfig
13+
from mytoninstaller.config import GetLiteServerConfig, get_ls_proxy_config
1414
from mytoninstaller.utils import GetInitBlock
1515
from mytoncore.utils import dict2b64, str2bool, b642dict
1616

1717
from mytoninstaller.settings import (
18-
FirstNodeSettings,
19-
FirstMytoncoreSettings,
20-
EnableValidatorConsole,
21-
EnableLiteServer,
22-
EnableDhtServer,
23-
EnableJsonRpc,
24-
EnablePytonv3,
18+
FirstNodeSettings,
19+
FirstMytoncoreSettings,
20+
EnableValidatorConsole,
21+
EnableLiteServer,
22+
EnableDhtServer,
23+
EnableJsonRpc,
2524
EnableTonHttpApi,
26-
DangerousRecoveryValidatorConfigFile,
27-
CreateSymlinks,
25+
DangerousRecoveryValidatorConfigFile,
26+
CreateSymlinks,
27+
enable_ls_proxy
2828
)
2929
from mytoninstaller.config import (
30-
CreateLocalConfig,
31-
BackupVconfig,
32-
BackupMconfig,
30+
CreateLocalConfig,
31+
BackupVconfig,
32+
BackupMconfig,
3333
)
3434

3535
from functools import partial
@@ -62,10 +62,12 @@ def inject_globals(func):
6262
console.name = "MyTonInstaller"
6363
console.color = console.RED
6464
console.AddItem("status", inject_globals(Status), "Print TON component status")
65-
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'")
65+
console.AddItem("enable", inject_globals(Enable), "Enable some function")
6666
console.AddItem("update", inject_globals(Enable), "Update some function: 'JR' - jsonrpc. Example: 'update JR'")
67-
console.AddItem("plsc", inject_globals(PrintLiteServerConfig), "Print LiteServer config")
68-
console.AddItem("clcf", inject_globals(CreateLocalConfigFile), "CreateLocalConfigFile")
67+
console.AddItem("plsc", inject_globals(PrintLiteServerConfig), "Print lite-server config")
68+
console.AddItem("clcf", inject_globals(CreateLocalConfigFile), "Create lite-server config file")
69+
console.AddItem("print_ls_proxy_config", inject_globals(print_ls_proxy_config), "Print ls-proxy config")
70+
console.AddItem("create_ls_proxy_config_file", inject_globals(create_ls_proxy_config_file), "Create ls-proxy config file")
6971
console.AddItem("drvcf", inject_globals(DRVCF), "Dangerous recovery validator config file")
7072
console.AddItem("setwebpass", inject_globals(SetWebPassword), "Set a password for the web admin interface")
7173

@@ -123,10 +125,22 @@ def Status(local, args):
123125

124126

125127
def Enable(local, args):
126-
name = args[0]
127-
if name == "PT":
128+
try:
129+
name = args[0]
130+
except:
131+
color_print("{red}Bad args. Usage:{endc} enable <mode-name>")
132+
print("'FN' - Full node")
133+
print("'VC' - Validator console")
134+
print("'LS' - Lite-Server")
135+
print("'DS' - DHT-Server")
136+
print("'JR' - jsonrpc")
137+
print("'THA' - ton-http-api")
138+
print("'LSP' - ls-proxy")
139+
print("Example: 'enable FN'")
140+
return
141+
if name == "THA":
128142
CreateLocalConfigFile(local, args)
129-
args = ["python3", "-m", "mytoninstaller", "-u", local.buffer.user, "-e", "enable{name}".format(name=name)]
143+
args = ["python3", "-m", "mytoninstaller", "-u", local.buffer.user, "-e", f"enable{name}"]
130144
run_as_root(args)
131145
#end define
132146

@@ -159,6 +173,15 @@ def CreateLocalConfigFile(local, args):
159173
run_as_root(args)
160174
#end define
161175

176+
def print_ls_proxy_config(local, args):
177+
ls_proxy_config = get_ls_proxy_config(local)
178+
text = json.dumps(ls_proxy_config, indent=4)
179+
print(text)
180+
#end define
181+
182+
def create_ls_proxy_config_file(local, args):
183+
print("TODO")
184+
#end define
162185

163186
def Event(local, name):
164187
if name == "enableFN":
@@ -173,9 +196,10 @@ def Event(local, name):
173196
DangerousRecoveryValidatorConfigFile(local)
174197
if name == "enableJR":
175198
EnableJsonRpc(local)
176-
if name == "enablePT":
177-
# EnablePytonv3(local)
199+
if name == "enableTHA":
178200
EnableTonHttpApi(local)
201+
if name == "enableLSP":
202+
enable_ls_proxy(local)
179203
if name == "clc":
180204
ix = sys.argv.index("-i")
181205
initBlock_b64 = sys.argv[ix+1]
@@ -219,12 +243,12 @@ def General(local):
219243
### Start of the program
220244
###
221245
def mytoninstaller():
222-
local = MyPyClass(__file__)
223-
console = MyPyConsole()
224-
225-
Init(local, console)
226-
if len(sys.argv) > 1:
227-
General(local)
228-
else:
229-
console.Run()
230-
local.exit()
246+
local = MyPyClass(__file__)
247+
console = MyPyConsole()
248+
249+
Init(local, console)
250+
if len(sys.argv) > 1:
251+
General(local)
252+
else:
253+
console.Run()
254+
local.exit()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Проверить sudo
5+
if [ "$(id -u)" != "0" ]; then
6+
echo "Please run script as root"
7+
exit 1
8+
fi
9+
10+
# install parameters
11+
src_path=/usr/src
12+
bin_path=/usr/bin
13+
openssl_path=${bin_path}/openssl_3
14+
15+
# Get arguments
16+
while getopts u:s:b:o: flag
17+
do
18+
case "${flag}" in
19+
u) user=${OPTARG};;
20+
s) src_path=${OPTARG};;
21+
b) bin_path=${OPTARG};;
22+
o) openssl_path=${OPTARG};;
23+
*)
24+
echo "Flag -${flag} is not recognized. Aborting"
25+
exit 1;;
26+
esac
27+
done
28+
29+
# install parameters
30+
author=xssnick
31+
repo=tonutils-liteserver-proxy
32+
branch=master
33+
bin_name=ls_proxy
34+
35+
# Цвета
36+
COLOR='\033[95m'
37+
ENDC='\033[0m'
38+
39+
# Клонирование репозиториев с github.com
40+
echo -e "${COLOR}[1/4]${ENDC} Cloning github repository"
41+
echo "https://github.com/${author}/${repo}.git -> ${branch}"
42+
43+
cd ${src_path}
44+
rm -rf ${repo}
45+
git clone --branch=${branch} --recursive https://github.com/${author}/${repo}.git
46+
47+
# Установка компонентов
48+
echo -e "${COLOR}[2/4]${ENDC} Installing required packages"
49+
50+
arc=$(dpkg --print-architecture)
51+
go_version_url=https://go.dev/VERSION?m=text
52+
go_version=$(curl -s ${go_version_url} | head -n 1)
53+
go_url=https://go.dev/dl/${go_version}.linux-${arc}.tar.gz
54+
go_path=/usr/local/go/bin/go
55+
rm -rf /usr/local/go
56+
wget -c ${go_url} -O - | tar -C /usr/local -xz
57+
58+
# Расчитываем количество процессоров для сборки
59+
if [[ "$OSTYPE" =~ darwin.* ]]; then
60+
cpu_number=$(sysctl -n hw.logicalcpu)
61+
else
62+
memory=$(cat /proc/meminfo | grep MemAvailable | awk '{print $2}')
63+
cpu_number=$(($memory/2100000))
64+
max_cpu_number=$(nproc)
65+
if [ ${cpu_number} -gt ${max_cpu_number} ]; then
66+
cpu_number=$((${max_cpu_number}-1))
67+
fi
68+
if [ ${cpu_number} == 0 ]; then
69+
echo "Warning! insufficient RAM"
70+
cpu_number=1
71+
fi
72+
fi
73+
74+
# Компилируем из исходников
75+
echo -e "${COLOR}[3/4]${ENDC} Source compilation, use ${cpu_number} cpus"
76+
77+
proxy_src_path=${src_path}/${repo}
78+
ton_src_path=${proxy_src_path}/ton
79+
proxy_internal_path=${proxy_src_path}/internal/emulate/lib
80+
81+
proxy_build_path=${bin_path}/${bin_name}
82+
ton_build_path=${proxy_build_path}/ton
83+
proxy_db_path=/var/${bin_name}
84+
proxy_lib_path=${proxy_db_path}/lib
85+
86+
mkdir -p ${proxy_lib_path}
87+
mkdir -p ${ton_build_path} && cd ${ton_build_path}
88+
cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_FOUND=1 -DOPENSSL_INCLUDE_DIR=${openssl_path}/include -DOPENSSL_CRYPTO_LIBRARY=${openssl_path}/libcrypto.a ${ton_src_path}
89+
make emulator -j ${cpu_number}
90+
cp ${ton_build_path}/emulator/libemulator.so ${proxy_lib_path}
91+
cp ${ton_build_path}/emulator/libemulator.so ${proxy_internal_path}
92+
cp ${ton_build_path}/emulator/emulator_export.h ${proxy_internal_path}
93+
94+
# Компилируем
95+
cd ${proxy_src_path}
96+
CGO_ENABLED=1 ${go_path} build -o ${proxy_db_path}/${bin_name} ${proxy_src_path}/cmd/main.go
97+
98+
# Настроить директорию работы
99+
chown -R ${user}:${user} ${proxy_db_path}
100+
101+
# Выход из программы
102+
echo -e "${COLOR}[4/4]${ENDC} ${bin_name} installation complete"
103+
exit 0

0 commit comments

Comments
 (0)