Skip to content

Commit f34df26

Browse files
authored
Merge pull request #3 from tonstakers/env-var-support
test support vars
2 parents e2d6464 + 80dc5a2 commit f34df26

File tree

3 files changed

+74
-47
lines changed

3 files changed

+74
-47
lines changed

scripts/install.sh

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,73 @@ author="tonstakers"
2121
repo="mytonctrl-v2"
2222
branch="master"
2323
mode="validator"
24+
network="mainnet"
25+
ton_node_version="master" # Default version
26+
2427

2528
show_help_and_exit() {
26-
echo 'Supported argumets:'
29+
echo 'Supported arguments:'
2730
echo ' -c PATH Provide custom config for toninstaller.sh'
2831
echo ' -t Disable telemetry'
29-
echo ' -i Ignore minimum reqiurements'
32+
echo ' -i Ignore minimum requirements'
3033
echo ' -d Use pre-packaged dump. Reduces duration of initial synchronization.'
3134
echo ' -a Set MyTonCtrl git repo author'
32-
echo ' -r Set MyTonCtrl git repo'
33-
echo ' -b Set MyTonCtrl git repo branch'
34-
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
35-
echo ' -h Show this help'
36-
exit
35+
echo ' -r Set MyTonCtrl git repo'
36+
echo ' -b Set MyTonCtrl git repo branch'
37+
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
38+
echo ' -n NETWORK Specify the network (mainnet or testnet)'
39+
echo ' -v VERSION Specify the ton node version (commit, branch, or tag)'
40+
echo ' -h Show this help'
41+
exit
3742
}
3843

3944
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
4045
show_help_and_exit
4146
fi
4247

4348
# node install parameters
44-
# todo support parametr
45-
#config="https://ton-blockchain.github.io/global.config.json"
46-
config="https://ton-blockchain.github.io/testnet-global.config.json"
47-
49+
config="https://ton-blockchain.github.io/global.config.json"
4850
telemetry=true
4951
ignore=false
5052
dump=false
51-
52-
53-
54-
while getopts c:tida:r:b:m: flag
55-
do
56-
case "${flag}" in
57-
c) config=${OPTARG};;
58-
t) telemetry=false;;
59-
i) ignore=true;;
60-
d) dump=true;;
61-
a) author=${OPTARG};;
62-
r) repo=${OPTARG};;
63-
b) branch=${OPTARG};;
64-
m) mode=${OPTARG};;
65-
h) show_help_and_exit;;
66-
*)
53+
cpu_required=16
54+
mem_required=64000000 # 64GB in KB
55+
56+
while getopts ":c:tida:r:b:m:n:v:h" flag; do
57+
case "${flag}" in
58+
c) config=${OPTARG};;
59+
t) telemetry=false;;
60+
i) ignore=true;;
61+
d) dump=true;;
62+
a) author=${OPTARG};;
63+
r) repo=${OPTARG};;
64+
b) branch=${OPTARG};;
65+
m) mode=${OPTARG};;
66+
n) network=${OPTARG};;
67+
v) ton_node_version=${OPTARG};;
68+
h) show_help_and_exit;;
69+
*)
6770
echo "Flag -${flag} is not recognized. Aborting"
6871
exit 1 ;;
69-
esac
72+
esac
7073
done
7174

75+
# Set config based on network argument
76+
if [ "${network}" = "testnet" ]; then
77+
config="https://ton-blockchain.github.io/testnet-global.config.json"
78+
cpu_required=8
79+
mem_required=16000000 # 16GB in KB
80+
fi
81+
7282
# check machine configuration
7383
echo -e "${COLOR}[1/5]${ENDC} Checking system requirements"
7484

7585
cpus=$(lscpu | grep "CPU(s)" | head -n 1 | awk '{print $2}')
7686
memory=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
7787

7888
echo "This machine has ${cpus} CPUs and ${memory}KB of Memory"
79-
if [ "$ignore" = false ] && ([ "${cpus}" -lt 16 ] || [ "${memory}" -lt 64000000 ]); then
80-
echo "Insufficient resources. Requires a minimum of 16 processors and 64Gb RAM."
89+
if [ "$ignore" = false ] && ([ "${cpus}" -lt "${cpu_required}" ] || [ "${memory}" -lt "${mem_required}"]); then
90+
echo "Insufficient resources. Requires a minimum of "${cpu_required}" processors and "${mem_required}" RAM."
8191
exit 1
8292
fi
8393

@@ -99,10 +109,8 @@ file3=${BIN_DIR}/ton/validator-engine-console/validator-engine-console
99109

100110
if [ ! -f "${file1}" ] || [ ! -f "${file2}" ] || [ ! -f "${file3}" ]; then
101111
echo "TON does not exists, building"
102-
# wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/ton_installer.sh -O /tmp/ton_installer.sh
103-
wget https://raw.githubusercontent.com/tonstakers/mytonctrl-v2/master/scripts/ton_installer.sh -O /tmp/ton_installer.sh
104-
# todo set vas scrip patch
105-
bash /tmp/ton_installer.sh -c ${config}
112+
wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/ton_installer.sh -O /tmp/ton_installer.sh
113+
bash /tmp/ton_installer.sh -c ${config} -v ${ton_node_version}
106114
fi
107115

108116
# Cloning mytonctrl
@@ -139,5 +147,10 @@ mkdir -p ${version_dir}
139147
echo ${migrate_version} > ${version_path}
140148
chown ${user}:${user} ${version_dir} ${version_path}
141149

150+
# create symbolic link if branch not eq mytonctrl
151+
if [ "${repo}" != "mytonctrl" ]; then
152+
ln -sf ${SOURCES_DIR}/${repo} ${SOURCES_DIR}/mytonctrl
153+
fi
154+
142155
echo -e "${COLOR}[5/5]${ENDC} Mytonctrl installation completed"
143156
exit 0

scripts/ton_installer.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@
22
#!/bin/bash
33
set -e
44

5+
#todo remove - debug only
6+
# fork tonstackers
7+
8+
59
# Проверить sudo
610
if [ "$(id -u)" != "0" ]; then
711
echo "Please run script as root"
812
exit 1
913
fi
1014

11-
# Get arguments
12-
# todo set vars
13-
#config=https://ton-blockchain.github.io/global.config.json
14-
config="https://ton-blockchain.github.io/testnet-global.config.json"
15-
while getopts c: flag
16-
do
17-
case "${flag}" in
18-
c) config=${OPTARG};;
19-
esac
15+
while getopts ":c:v:h" flag; do
16+
case "${flag}" in
17+
c) config=${OPTARG};;
18+
v) ton_node_version=${OPTARG};;
19+
h) show_help_and_exit;;
20+
*)
21+
echo "Flag -${flag} is not recognized. Aborting"
22+
exit 1 ;;
23+
esac
2024
done
2125

26+
echo " config 42: ${config}"
27+
echo "checkout to ${ton_node_version}"
28+
2229
# Цвета
2330
COLOR='\033[95m'
2431
ENDC='\033[0m'
@@ -73,7 +80,7 @@ elif [[ "$OSTYPE" =~ darwin.* ]]; then
7380

7481
echo "Please, write down your username, because brew package manager cannot be run under root user:"
7582
read LOCAL_USERNAME
76-
83+
7784
su $LOCAL_USERNAME -c "brew update"
7885
su $LOCAL_USERNAME -c "brew install openssl cmake llvm"
7986
elif [ "$OSTYPE" == "freebsd"* ]; then
@@ -106,9 +113,15 @@ echo -e "${COLOR}[3/6]${ENDC} Preparing for compilation"
106113
cd $SOURCES_DIR
107114
rm -rf $SOURCES_DIR/ton
108115
git clone --recursive https://github.com/ton-blockchain/ton.git
109-
cd $SOURCES_DIR/ton
110-
git checkout 5380e6f
111-
cd ../
116+
117+
echo "checkout to ${ton_node_version}"
118+
119+
if [ "${ton_node_version}" != "master" ]; then
120+
cd $SOURCES_DIR/ton
121+
git checkout ${ton_node_version}
122+
cd ../
123+
fi
124+
112125
git config --global --add safe.directory $SOURCES_DIR/ton
113126

114127
# Подготавливаем папки для компиляции

scripts/uninstall.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if $full; then
4141
fi
4242

4343
rm -rf /usr/src/mytonctrl
44+
rm -rf /usr/src/mytonctrl-v2 #todo remove
4445
rm -rf /usr/src/mtc-jsonrpc
4546
rm -rf /usr/src/pytonv3
4647
rm -rf /tmp/myton*

0 commit comments

Comments
 (0)