2024-09-08 20:31:46 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2024-09-10 20:06:33 +02:00
|
|
|
import subprocess
|
|
|
|
from getpass import getpass
|
2024-09-08 20:31:46 +02:00
|
|
|
|
2024-09-10 20:06:33 +02:00
|
|
|
startfile = ['#!/usr/bin/python3',
|
|
|
|
'from subprocess import check_call', '\n',
|
|
|
|
|
|
|
|
'path_to_file = ', '\n',
|
|
|
|
|
|
|
|
'with open(path_to_file, 'r') as file:',
|
|
|
|
' for line in file.readlines(): ',
|
|
|
|
' a_con = line[5:] ',
|
|
|
|
"check_call(['nmcli', 'connection', 'up', a_con])",
|
|
|
|
'file.close()']
|
2024-09-08 20:31:46 +02:00
|
|
|
home = Path.home()
|
|
|
|
# for services file in /lib/systemd/system/
|
|
|
|
path_for_a_con = home / '.config/wire_py/wg_py'
|
2024-09-10 20:06:33 +02:00
|
|
|
# replace in startfile
|
|
|
|
startfile[3] = 'path_to_file = ' "'" + str(path_for_a_con) + "'"
|
|
|
|
|
|
|
|
with open('start_wg.py', 'w') as file_for_a_con:
|
|
|
|
for line in startfile:
|
|
|
|
file_for_a_con.write(line + '\n')
|
|
|
|
file_for_a_con.close()
|
|
|
|
|
2024-09-08 20:31:46 +02:00
|
|
|
# create dir in home
|
|
|
|
mkdir = home / '.config/wire_py'
|
|
|
|
os.makedirs(mkdir, exist_ok=True)
|
|
|
|
|
|
|
|
with open(mkdir / 'wg_py', 'w+') as file:
|
|
|
|
if 'true' not in file:
|
|
|
|
file.write('false')
|
|
|
|
file.close()
|
|
|
|
|
2024-09-10 20:06:33 +02:00
|
|
|
# Prompt the user for the sudo password
|
|
|
|
sudo_password = getpass('Enter sudo password: ')
|
|
|
|
#def cp_files():
|
|
|
|
|
|
|
|
# Define the command to run the Python script with sudo
|
|
|
|
#command = ['sudo', '-S', 'python3', 'script.py']
|
|
|
|
|
|
|
|
# Run the command as a subprocess, passing the sudo password
|
|
|
|
#subprocess.run(command, input=sudo_password.encode(), check=True)
|
|
|
|
|