Skip to content

Commit c5264a8

Browse files
authored
feat: Update install.sh to allow passing in USER arg
- Added an optional `-u` argument to install.sh to allow explicitly specifying the user thats passed to `mytoninstaller` and is used for version migration. - Cleaned up formatting
1 parent a467af5 commit c5264a8

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

scripts/install.sh

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ ton_node_version="master" # Default version
2020

2121

2222
show_help_and_exit() {
23-
echo 'Supported arguments:'
24-
echo ' -c PATH Provide custom config for toninstaller.sh'
25-
echo ' -t Disable telemetry'
26-
echo ' -i Ignore minimum requirements'
27-
echo ' -d Use pre-packaged dump. Reduces duration of initial synchronization.'
28-
echo ' -a Set MyTonCtrl git repo author'
29-
echo ' -r Set MyTonCtrl git repo'
30-
echo ' -b Set MyTonCtrl git repo branch'
31-
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
32-
echo ' -n NETWORK Specify the network (mainnet or testnet)'
33-
echo ' -v VERSION Specify the ton node version (commit, branch, or tag)'
34-
echo ' -h Show this help'
35-
exit
23+
echo 'Supported arguments:'
24+
echo ' -c PATH Provide custom config for toninstaller.sh'
25+
echo ' -t Disable telemetry'
26+
echo ' -i Ignore minimum requirements'
27+
echo ' -d Use pre-packaged dump. Reduces duration of initial synchronization.'
28+
echo ' -a Set MyTonCtrl git repo author'
29+
echo ' -r Set MyTonCtrl git repo'
30+
echo ' -b Set MyTonCtrl git repo branch'
31+
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
32+
echo ' -n NETWORK Specify the network (mainnet or testnet)'
33+
echo ' -v VERSION Specify the ton node version (commit, branch, or tag)'
34+
echo ' -u USER Specify the user to be used for MyTonCtrl installation'
35+
echo ' -h Show this help'
36+
exit
3637
}
3738

3839
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
@@ -47,7 +48,7 @@ dump=false
4748
cpu_required=16
4849
mem_required=64000000 # 64GB in KB
4950

50-
while getopts ":c:tida:r:b:m:n:v:h" flag; do
51+
while getopts ":c:tida:r:b:m:n:v:u:h" flag; do
5152
case "${flag}" in
5253
c) config=${OPTARG};;
5354
t) telemetry=false;;
@@ -59,10 +60,11 @@ while getopts ":c:tida:r:b:m:n:v:h" flag; do
5960
m) mode=${OPTARG};;
6061
n) network=${OPTARG};;
6162
v) ton_node_version=${OPTARG};;
63+
u) user=${OPTARG};;
6264
h) show_help_and_exit;;
6365
*)
6466
echo "Flag -${flag} is not recognized. Aborting"
65-
exit 1 ;;
67+
exit 1 ;;
6668
esac
6769
done
6870

@@ -90,8 +92,8 @@ memory=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
9092

9193
echo "This machine has ${cpus} CPUs and ${memory}KB of Memory"
9294
if [ "$ignore" = false ] && ([ "${cpus}" -lt "${cpu_required}" ] || [ "${memory}" -lt "${mem_required}" ]); then
93-
echo "Insufficient resources. Requires a minimum of "${cpu_required}" processors and "${mem_required}" RAM."
94-
exit 1
95+
echo "Insufficient resources. Requires a minimum of "${cpu_required}" processors and "${mem_required}" RAM."
96+
exit 1
9597
fi
9698

9799
echo -e "${COLOR}[2/5]${ENDC} Checking for required TON components"
@@ -100,9 +102,9 @@ BIN_DIR=/usr/bin
100102

101103
# create dirs for OSX
102104
if [[ "$OSTYPE" =~ darwin.* ]]; then
103-
SOURCES_DIR=/usr/local/src
104-
BIN_DIR=/usr/local/bin
105-
mkdir -p ${SOURCES_DIR}
105+
SOURCES_DIR=/usr/local/src
106+
BIN_DIR=/usr/local/bin
107+
mkdir -p ${SOURCES_DIR}
106108
fi
107109

108110
# check TON components
@@ -111,9 +113,9 @@ file2=${BIN_DIR}/ton/lite-client/lite-client
111113
file3=${BIN_DIR}/ton/validator-engine-console/validator-engine-console
112114

113115
if [ ! -f "${file1}" ] || [ ! -f "${file2}" ] || [ ! -f "${file3}" ]; then
114-
echo "TON does not exists, building"
115-
wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/ton_installer.sh -O /tmp/ton_installer.sh
116-
bash /tmp/ton_installer.sh -c ${config} -v ${ton_node_version}
116+
echo "TON does not exists, building"
117+
wget https://raw.githubusercontent.com/${author}/${repo}/${branch}/scripts/ton_installer.sh -O /tmp/ton_installer.sh
118+
bash /tmp/ton_installer.sh -c ${config} -v ${ton_node_version}
117119
fi
118120

119121
# Cloning mytonctrl
@@ -134,10 +136,12 @@ pip3 install -U . # TODO: make installation from git directly
134136
echo -e "${COLOR}[4/5]${ENDC} Running mytoninstaller"
135137
# DEBUG
136138

137-
parent_name=$(ps -p $PPID -o comm=)
138-
user=$(whoami)
139-
if [ "$parent_name" = "sudo" ] || [ "$parent_name" = "su" ] || [ "$parent_name" = "python3" ]; then
140-
user=$(logname)
139+
if [ "${user}" = "" ]; then # no user
140+
parent_name=$(ps -p $PPID -o comm=)
141+
user=$(whoami)
142+
if [ "$parent_name" = "sudo" ] || [ "$parent_name" = "su" ] || [ "$parent_name" = "python3" ]; then
143+
user=$(logname)
144+
fi
141145
fi
142146
echo "User: $user"
143147
python3 -m mytoninstaller -u ${user} -t ${telemetry} --dump ${dump} -m ${mode}

0 commit comments

Comments
 (0)