diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index cd6dbd38..1b11c086 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -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 @@ -280,7 +280,22 @@ 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 + 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) @@ -288,7 +303,7 @@ def check_git(input_args, default_repo, text, default_branch='master'): 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 @@ -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): @@ -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 # Run script update_script_path = pkg_resources.resource_filename('mytonctrl', 'scripts/update.sh') runArgs = ["bash", update_script_path, "-a", author, "-r", repo, "-b", branch] @@ -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") @@ -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) diff --git a/mytonctrl/scripts/upgrade.sh b/mytonctrl/scripts/upgrade.sh index fb22dad2..b2e631e5 100644 --- a/mytonctrl/scripts/upgrade.sh +++ b/mytonctrl/scripts/upgrade.sh @@ -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' @@ -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} diff --git a/scripts/install.sh b/scripts/install.sh index 12dec025..abd5af18 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -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:' @@ -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)' @@ -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};; @@ -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 @@ -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 diff --git a/scripts/ton_installer.sh b/scripts/ton_installer.sh index 5dc962cf..552b3458 100644 --- a/scripts/ton_installer.sh +++ b/scripts/ton_installer.sh @@ -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;; @@ -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 echo "checkout to ${ton_node_version}"