mirror of
https://codeberg.org/angestoepselt/imagestack.git
synced 2025-05-24 14:46:16 +00:00
34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
def convert_to_in_target(bash_script_path, target_username):
|
|
try:
|
|
with open(bash_script_path, 'r') as file:
|
|
lines = file.readlines()
|
|
|
|
in_target_commands = []
|
|
|
|
# Construct the script creation command
|
|
script_creation_cmd = f"in-target bash -c 'echo \"#!/bin/bash\" > /home/{target_username}/post_hardware.sh'"
|
|
in_target_commands.append(script_creation_cmd)
|
|
|
|
# Convert each script line into an in-target command
|
|
for line in lines:
|
|
# Strip the line to remove leading/trailing whitespace
|
|
stripped_line = line.strip()
|
|
if stripped_line: # Ignore empty lines
|
|
escaped_line = stripped_line.replace('"', '\\"').replace('$', '\\$')
|
|
cmd = f"in-target bash -c 'echo \"{escaped_line}\" >> /home/{target_username}/post_hardware.sh'"
|
|
in_target_commands.append(cmd)
|
|
|
|
# Add command to make the script executable
|
|
in_target_commands.append(f"in-target chmod +x /home/{target_username}/post_hardware.sh")
|
|
|
|
# Output the generated in-target commands
|
|
for command in in_target_commands:
|
|
print(command)
|
|
|
|
except FileNotFoundError:
|
|
print("The specified bash script file does not exist.")
|
|
|
|
# Usage
|
|
bash_script_path = 'post_hardware.sh' # Replace with the path to your bash script
|
|
target_username = 'computerspende' # Replace with the target user's username
|
|
convert_to_in_target(bash_script_path, target_username)
|