|
|
|
import os |
|
import tarfile |
|
|
|
|
|
def run_piper_installer(): |
|
|
|
source_path = "/home/user/app" |
|
|
|
destination_path = "/home/user/piper_installation" |
|
|
|
|
|
print("Step 1: Searching for .tar.gz file in", source_path) |
|
|
|
tar_files = [file for file in os.listdir(source_path) if file == "piper_amd64.tar.gz"] |
|
|
|
if not tar_files: |
|
print("Error: No .tar.gz file found in", source_path) |
|
exit(1) |
|
|
|
tar_file = os.path.join(source_path, tar_files[0]) |
|
print(f"Found tar.gz file: {tar_file}") |
|
|
|
|
|
print("Step 2: Creating directory", destination_path) |
|
os.makedirs(destination_path, exist_ok=True) |
|
print(f"Directory '{destination_path}' is ready.") |
|
|
|
|
|
print("Step 3: Extracting tar.gz file...") |
|
with tarfile.open(tar_file, "r:gz") as tar: |
|
tar.extractall(path=destination_path) |
|
print(f"Extracted contents to {destination_path}") |
|
|
|
|
|
piper_path = os.path.join(destination_path, "piper") |
|
|
|
if not os.path.exists(piper_path): |
|
print(f"Error: 'piper' directory not found in {destination_path}") |
|
exit(1) |
|
|
|
print("Step 4: Setting execution permissions for files in 'piper'") |
|
exec_files = ["piper"] |
|
for file_name in exec_files: |
|
file_path = os.path.join(piper_path, file_name) |
|
if os.path.exists(file_path): |
|
os.chmod(file_path, 0o755) |
|
print(f"Set execute permission for {file_name}") |
|
else: |
|
print(f"Warning: {file_name} not found in {piper_path}") |
|
|
|
|
|
output_files_path = os.path.join(piper_path, "output_files") |
|
print("Step 5: Creating 'output_files' directory") |
|
os.makedirs(output_files_path, exist_ok=True) |
|
os.chmod(output_files_path, 0o777) |
|
print(f"'output_files' directory is ready with read/write permissions at {output_files_path}") |
|
|
|
print("All tasks completed successfully.") |
|
|