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
36 changes: 27 additions & 9 deletions mytonctrl/mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from mytoncore.telemetry import is_host_virtual
from mytonctrl.migrate import run_migrations
from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime, fix_git_config, is_hex, GetColorInt, \
pop_user_from_args
pop_user_from_args, pop_arg_from_args

import sys, getopt, os

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

# Get author, repo, branch
branch = pop_arg_from_args(input_args, '--branch')

if '--url' in input_args:
git_url = pop_arg_from_args(input_args, '--url')
if branch is None:
if '#' in git_url:
ref_fragment = git_url.rsplit('#', 1)[1]
if not ref_fragment:
raise Exception("--url fragment after # is empty")
branch = ref_fragment
Comment on lines +288 to +292
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fragment parsing doesn't validate the extracted branch name. This could allow injection of arbitrary git references that might not be safe branch/tag names.

Copilot uses AI. Check for mistakes.
else:
branch = default_branch
if '#' in git_url:
git_url = git_url.split('#', 1)[0]
return None, None, branch, git_url

local_author, local_repo = get_git_author_and_repo(git_path)
local_branch = get_git_branch(git_path)

# Set author, repo, branch
data = GetAuthorRepoBranchFromArgs(input_args)
need_author = data.get("author")
need_repo = data.get("repo")
need_branch = data.get("branch")
need_branch = data.get("branch") or branch

# Check if remote repo is different from default
if ((need_author is None and local_author != default_author) or
Expand All @@ -306,7 +321,7 @@ def check_git(input_args, default_repo, text, default_branch='master'):
if need_branch is None:
need_branch = local_branch
check_branch_exists(need_author, need_repo, need_branch)
return need_author, need_repo, need_branch
return need_author, need_repo, need_branch, None
#end define

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

def Update(local, args):
repo = "mytonctrl"
author, repo, branch = check_git(args, repo, "update")

author, repo, branch, _ = check_git(args, repo, "update") # todo: implement --url for update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yungwine I propose to remove # todo: implement --url for update as whole idea of that PR to keep upstream MTC for custom TON nodes.

# Run script
update_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/update.sh')
runArgs = ["bash", update_script_path, "-a", author, "-r", repo, "-b", branch]
Comment on lines +341 to 344
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO comment indicates incomplete implementation. The Update function doesn't support the --url parameter that was added to check_git, creating inconsistent functionality between update and upgrade operations.

Suggested change
author, repo, branch, _ = check_git(args, repo, "update") # todo: implement --url for update
# Run script
update_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/update.sh')
runArgs = ["bash", update_script_path, "-a", author, "-r", repo, "-b", branch]
author, repo, branch, git_url = check_git(args, repo, "update") # implemented --url for update
# Run script
update_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/update.sh')
if git_url is not None:
runArgs = ["bash", update_script_path, "-u", git_url, "-b", branch]
else:
runArgs = ["bash", update_script_path, "-a", author, "-r", repo, "-b", branch]

Copilot uses AI. Check for mistakes.
Expand All @@ -345,8 +359,8 @@ def Upgrade(local, ton, args: list):
branch = args[args.index('--btc-teleport') + 1]
upgrade_btc_teleport(local, ton, reinstall=True, branch=branch, user=user)
return
repo = "ton"
author, repo, branch = check_git(args, repo, "upgrade")

author, repo, branch, git_url = check_git(args, default_repo="ton", text="upgrade")

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

# Run script
upgrade_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/upgrade.sh')
runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch]
if git_url:
runArgs = ["bash", upgrade_script_path, "-g", git_url, "-b", branch]
else:
runArgs = ["bash", upgrade_script_path, "-a", author, "-r", repo, "-b", branch]

exitCode = run_as_root(runArgs)
if ton.using_validator():
upgrade_btc_teleport(local, ton)
Expand Down
12 changes: 9 additions & 3 deletions mytonctrl/scripts/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ bindir="/usr/bin/"
tmpdir="/tmp/ton_src/"

# Get arguments
while getopts a:r:b: flag
while getopts a:r:b:g: flag
do
case "${flag}" in
a) author=${OPTARG};;
r) repo=${OPTARG};;
b) branch=${OPTARG};;
g) git_url=${OPTARG};;
esac
done

remote_url="https://github.com/${author}/${repo}.git"
if [ -n "${git_url}" ]; then
remote_url="${git_url}"
fi

# Цвета
COLOR='\033[92m'
ENDC='\033[0m'
Expand Down Expand Up @@ -63,8 +69,8 @@ fi
rm -rf ${tmpdir}/${repo}
mkdir -p ${tmpdir}/${repo}
cd ${tmpdir}/${repo}
echo "https://github.com/${author}/${repo}.git -> ${branch}"
git clone --recursive https://github.com/${author}/${repo}.git . || exit 1
echo "${remote_url} -> ${branch}"
git clone --recursive ${remote_url} . || exit 1

# Go to work dir
cd ${srcdir}/${repo}
Expand Down
16 changes: 11 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ repo="mytonctrl"
branch="master"
network="mainnet"
ton_node_version="master" # Default version

ton_node_git_url="https://github.com/ton-blockchain/ton.git"
config_overridden=false

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

while getopts ":c:tidola:r:b:m:n:v:u:p:h" flag; do
while getopts ":c:tidola:r:b:m:n:v:u:p:g:h" flag; do
case "${flag}" in
c) config=${OPTARG};;
c) config=${OPTARG}; config_overridden=true;;
t) telemetry=false;;
i) ignore=true;;
d) dump=true;;
a) author=${OPTARG};;
r) repo=${OPTARG};;
g) ton_node_git_url=${OPTARG};;
b) branch=${OPTARG};;
m) mode=${OPTARG};;
n) network=${OPTARG};;
Expand Down Expand Up @@ -100,7 +103,10 @@ fi

# Set config based on network argument
if [ "${network}" = "testnet" ]; then
config="https://ton-blockchain.github.io/testnet-global.config.json"
if [ "${config_overridden}" = false ]; then
config="https://ton-blockchain.github.io/testnet-global.config.json"
fi

cpu_required=8
mem_required=16000000 # 16GB in KB
fi
Expand Down Expand Up @@ -144,7 +150,7 @@ file3=${BIN_DIR}/ton/validator-engine-console/validator-engine-console
if [ ! -f "${file1}" ] || [ ! -f "${file2}" ] || [ ! -f "${file3}" ]; then
echo "TON does not exists, building"
wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/ton_installer.sh -O /tmp/ton_installer.sh
bash /tmp/ton_installer.sh -c ${config} -v ${ton_node_version}
bash /tmp/ton_installer.sh -c ${config} -g ${ton_node_git_url} -v ${ton_node_version}
fi

# Cloning mytonctrl
Expand Down
7 changes: 5 additions & 2 deletions scripts/ton_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ if [ "$(id -u)" != "0" ]; then
exit 1
fi

while getopts ":c:v:h" flag; do
repo_git_url="https://github.com/ton-blockchain/ton.git"

while getopts ":c:v:g:h" flag; do
case "${flag}" in
g) repo_git_url=${OPTARG};;
c) config=${OPTARG};;
v) ton_node_version=${OPTARG};;
h) show_help_and_exit;;
Expand Down Expand Up @@ -108,7 +111,7 @@ make build_libs -j$(nproc)
echo -e "${COLOR}[3/6]${ENDC} Preparing for compilation"
cd $SOURCES_DIR
rm -rf $SOURCES_DIR/ton
git clone --recursive https://github.com/ton-blockchain/ton.git
git clone --recursive $repo_git_url $SOURCES_DIR/ton
Comment on lines 113 to +114
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git clone command should specify the target directory as the last argument after the URL. Currently it's cloning to $SOURCES_DIR/ton which creates a nested directory structure. It should be git clone --recursive $repo_git_url ton and then cd ton.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We force clone into $SOURCES_DIR/ton to keep a deterministic path since repo names may vary.


echo "checkout to ${ton_node_version}"

Expand Down