0

I need to deploy teamviewer on the system I have installed (raspberry pi4 with raspbian).

I need a simplicity in, fact I send an USB-stick to my client, and they click on file to launch install.

I can't go on different site. I want to use python to deploy

My Python script:

#!/usr/bin/env python3

import subprocess
import os
import stat

st = os.stat('./team.sh')
os.chmod('./team.sh', st.st_mode | stat.S_IEXEC)
subprocess.call("./team.sh")

and my bash script:

#!/bin/bash
sudo apt-get -y update;
sudo apt-get -y upgrade;
wget https://download.teamviewer.com/download/linux/teamviewer-host_armhf.deb;
ls | grep teamviewer-host_armhf.deb;
sudo dpkg -i teamviewer-host_armhf.deb;
sudo apt --fix-broken install;
sudo teamviewer passwd myspassword;
teamviewer info;

The Bash script work perfectly.

But i have a problem with Python. When I run it, I get

FileNotFoundError: [Errno 2] No such file or directory: 'team.sh'

I don't understand because all files are in the same directory.

Sven Eberth
  • 3,057
  • 12
  • 24
  • 29
  • Since this is on a USB drive and file attributes will be preserved, why not just make `test.sh` executable and ask client to run it instead of a Python script? You can even rename it to something like `install` (sh extension is not required because of the shebang line) – Marat Sep 03 '21 at 14:12

1 Answers1

0

Are you sure you're running your Python script from the same directory as its located?

If your Python script is in the same directory than your bash script, then you could use:

#!/usr/bin/env python3
import os
import pathlib
import subprocess
import stat

CURRENT_DIR = pathlib.Path(__file__).parent.resolve()  # parent path of the current file
EXECUTABLE = f"{CURRENT_DIR}/team.sh"

st = os.stat(EXECUTABLE)
os.chmod(EXECUTABLE, st.st_mode | stat.S_IEXEC)
subprocess.run(["bash", EXECUTABLE])
smallwat3r
  • 1,037
  • 1
  • 8
  • 28