Skip to content

Commit 92eb83b

Browse files
committed
check user before launch
1 parent b6dfff0 commit 92eb83b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

mytonctrl/mytonctrl.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,27 @@ def inject_globals(func):
176176
local.db.config.logLevel = "debug" if console.debug else "info"
177177
local.db.config.isLocaldbSaving = False
178178
local.run()
179-
#end define
179+
180+
181+
def check_installer_user():
182+
args = ["whoami"]
183+
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
184+
username = process.stdout.decode("utf-8").strip()
185+
186+
args = ["ls", "-lh", "/var/ton-work/keys/"]
187+
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
188+
output = process.stdout.decode("utf-8")
189+
actual_user = output.split('\n')[1].split()[2]
190+
191+
if username != actual_user:
192+
raise Exception(f'mytonctrl was installed by another user. Probably you need to launch mtc with `{actual_user}` user.')
193+
180194

181195
def PreUp(local, ton):
182196
CheckMytonctrlUpdate(local)
197+
check_installer_user()
183198
check_vport(local, ton)
184199
# CheckTonUpdate()
185-
#end define
186200

187201
def Installer(args):
188202
# args = ["python3", "/usr/src/mytonctrl/mytoninstaller.py"]
@@ -208,7 +222,7 @@ def GetAuthorRepoBranchFromArgs(args):
208222
if arg2:
209223
data["branch"] = arg2
210224
return data
211-
#end define
225+
212226

213227
def check_vport(local, ton):
214228
try:
@@ -222,7 +236,6 @@ def check_vport(local, ton):
222236
result = client_socket.connect_ex((ip, addr.port))
223237
if result != 0:
224238
color_print(local.translate("vport_error"))
225-
#end define
226239

227240

228241
def fix_git_config(git_path: str):

0 commit comments

Comments
 (0)