Skip to content

Commit ac7fa24

Browse files
authored
Merge pull request #483 from yungwine/git-custom
add support for custom TON node git URL
2 parents 3816eb2 + c0eba0f commit ac7fa24

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

mytonctrl/mytonctrl.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from mytoncore.telemetry import is_host_virtual
4747
from mytonctrl.migrate import run_migrations
4848
from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime, fix_git_config, is_hex, GetColorInt, \
49-
pop_user_from_args
49+
pop_user_from_args, pop_arg_from_args
5050

5151
import sys, getopt, os
5252

@@ -280,15 +280,30 @@ def check_git(input_args, default_repo, text, default_branch='master'):
280280
fix_git_config(git_path)
281281
default_author = "ton-blockchain"
282282

283-
# Get author, repo, branch
283+
branch = pop_arg_from_args(input_args, '--branch')
284+
285+
if '--url' in input_args:
286+
git_url = pop_arg_from_args(input_args, '--url')
287+
if branch is None:
288+
if '#' in git_url:
289+
ref_fragment = git_url.rsplit('#', 1)[1]
290+
if not ref_fragment:
291+
raise Exception("--url fragment after # is empty")
292+
branch = ref_fragment
293+
else:
294+
branch = default_branch
295+
if '#' in git_url:
296+
git_url = git_url.split('#', 1)[0]
297+
return None, None, branch, git_url
298+
284299
local_author, local_repo = get_git_author_and_repo(git_path)
285300
local_branch = get_git_branch(git_path)
286301

287302
# Set author, repo, branch
288303
data = GetAuthorRepoBranchFromArgs(input_args)
289304
need_author = data.get("author")
290305
need_repo = data.get("repo")
291-
need_branch = data.get("branch")
306+
need_branch = data.get("branch") or branch
292307

293308
# Check if remote repo is different from default
294309
if ((need_author is None and local_author != default_author) or
@@ -306,7 +321,7 @@ def check_git(input_args, default_repo, text, default_branch='master'):
306321
if need_branch is None:
307322
need_branch = local_branch
308323
check_branch_exists(need_author, need_repo, need_branch)
309-
return need_author, need_repo, need_branch
324+
return need_author, need_repo, need_branch, None
310325
#end define
311326

312327
def check_branch_exists(author, repo, branch):
@@ -323,8 +338,7 @@ def check_branch_exists(author, repo, branch):
323338

324339
def Update(local, args):
325340
repo = "mytonctrl"
326-
author, repo, branch = check_git(args, repo, "update")
327-
341+
author, repo, branch, _ = check_git(args, repo, "update") # todo: implement --url for update
328342
# Run script
329343
update_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/update.sh')
330344
runArgs = ["bash", update_script_path, "-a", author, "-r", repo, "-b", branch]
@@ -345,8 +359,8 @@ def Upgrade(local, ton, args: list):
345359
branch = args[args.index('--btc-teleport') + 1]
346360
upgrade_btc_teleport(local, ton, reinstall=True, branch=branch, user=user)
347361
return
348-
repo = "ton"
349-
author, repo, branch = check_git(args, repo, "upgrade")
362+
363+
author, repo, branch, git_url = check_git(args, default_repo="ton", text="upgrade")
350364

351365
# bugfix if the files are in the wrong place
352366
liteClient = ton.GetSettings("liteClient")
@@ -376,7 +390,11 @@ def Upgrade(local, ton, args: list):
376390

377391
# Run script
378392
upgrade_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/upgrade.sh')
379-
runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch]
393+
if git_url:
394+
runArgs = ["bash", upgrade_script_path, "-g", git_url, "-b", branch]
395+
else:
396+
runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch]
397+
380398
exitCode = run_as_root(runArgs)
381399
if ton.using_validator():
382400
upgrade_btc_teleport(local, ton)

mytonctrl/scripts/upgrade.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ bindir="/usr/bin/"
1616
tmpdir="/tmp/ton_src/"
1717

1818
# Get arguments
19-
while getopts a:r:b: flag
19+
while getopts a:r:b:g: flag
2020
do
2121
case "${flag}" in
2222
a) author=${OPTARG};;
2323
r) repo=${OPTARG};;
2424
b) branch=${OPTARG};;
25+
g) git_url=${OPTARG};;
2526
esac
2627
done
2728

29+
remote_url="https://github.com/${author}/${repo}.git"
30+
if [ -n "${git_url}" ]; then
31+
remote_url="${git_url}"
32+
fi
33+
2834
# Цвета
2935
COLOR='\033[92m'
3036
ENDC='\033[0m'
@@ -63,8 +69,8 @@ fi
6369
rm -rf ${tmpdir}/${repo}
6470
mkdir -p ${tmpdir}/${repo}
6571
cd ${tmpdir}/${repo}
66-
echo "https://github.com/${author}/${repo}.git -> ${branch}"
67-
git clone --recursive https://github.com/${author}/${repo}.git . || exit 1
72+
echo "${remote_url} -> ${branch}"
73+
git clone --recursive ${remote_url} . || exit 1
6874

6975
# Go to work dir
7076
cd ${srcdir}/${repo}

scripts/install.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ repo="mytonctrl"
1717
branch="master"
1818
network="mainnet"
1919
ton_node_version="master" # Default version
20-
20+
ton_node_git_url="https://github.com/ton-blockchain/ton.git"
21+
config_overridden=false
2122

2223
show_help_and_exit() {
2324
echo 'Supported arguments:'
@@ -28,6 +29,7 @@ show_help_and_exit() {
2829
echo ' -a Set MyTonCtrl git repo author'
2930
echo ' -r Set MyTonCtrl git repo'
3031
echo ' -b Set MyTonCtrl git repo branch'
32+
echo ' -g URL TON node git repo URL (default: https://github.com/ton-blockchain/ton.git)'
3133
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
3234
echo ' -n NETWORK Specify the network (mainnet or testnet)'
3335
echo ' -v VERSION Specify the ton node version (commit, branch, or tag)'
@@ -55,14 +57,15 @@ mode=none
5557
cpu_required=16
5658
mem_required=64000000 # 64GB in KB
5759

58-
while getopts ":c:tidola:r:b:m:n:v:u:p:h" flag; do
60+
while getopts ":c:tidola:r:b:m:n:v:u:p:g:h" flag; do
5961
case "${flag}" in
60-
c) config=${OPTARG};;
62+
c) config=${OPTARG}; config_overridden=true;;
6163
t) telemetry=false;;
6264
i) ignore=true;;
6365
d) dump=true;;
6466
a) author=${OPTARG};;
6567
r) repo=${OPTARG};;
68+
g) ton_node_git_url=${OPTARG};;
6669
b) branch=${OPTARG};;
6770
m) mode=${OPTARG};;
6871
n) network=${OPTARG};;
@@ -100,7 +103,10 @@ fi
100103

101104
# Set config based on network argument
102105
if [ "${network}" = "testnet" ]; then
103-
config="https://ton-blockchain.github.io/testnet-global.config.json"
106+
if [ "${config_overridden}" = false ]; then
107+
config="https://ton-blockchain.github.io/testnet-global.config.json"
108+
fi
109+
104110
cpu_required=8
105111
mem_required=16000000 # 16GB in KB
106112
fi
@@ -144,7 +150,7 @@ file3=${BIN_DIR}/ton/validator-engine-console/validator-engine-console
144150
if [ ! -f "${file1}" ] || [ ! -f "${file2}" ] || [ ! -f "${file3}" ]; then
145151
echo "TON does not exists, building"
146152
wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/ton_installer.sh -O /tmp/ton_installer.sh
147-
bash /tmp/ton_installer.sh -c ${config} -v ${ton_node_version}
153+
bash /tmp/ton_installer.sh -c ${config} -g ${ton_node_git_url} -v ${ton_node_version}
148154
fi
149155

150156
# Cloning mytonctrl

scripts/ton_installer.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ if [ "$(id -u)" != "0" ]; then
88
exit 1
99
fi
1010

11-
while getopts ":c:v:h" flag; do
11+
repo_git_url="https://github.com/ton-blockchain/ton.git"
12+
13+
while getopts ":c:v:g:h" flag; do
1214
case "${flag}" in
15+
g) repo_git_url=${OPTARG};;
1316
c) config=${OPTARG};;
1417
v) ton_node_version=${OPTARG};;
1518
h) show_help_and_exit;;
@@ -108,7 +111,7 @@ make build_libs -j$(nproc)
108111
echo -e "${COLOR}[3/6]${ENDC} Preparing for compilation"
109112
cd $SOURCES_DIR
110113
rm -rf $SOURCES_DIR/ton
111-
git clone --recursive https://github.com/ton-blockchain/ton.git
114+
git clone --recursive $repo_git_url $SOURCES_DIR/ton
112115

113116
echo "checkout to ${ton_node_version}"
114117

0 commit comments

Comments
 (0)