Skip to content

Blueprints Scripts

Levi Smith edited this page Apr 20, 2024 · 1 revision

The Scripts blueprint allows you to execute scripts as part of the configuration process in Rinse, Wash, Repeat (RWR). This blueprint is useful for running custom scripts, setting up environment-specific configurations, or performing any additional tasks that are not covered by other blueprint types.

Blueprint Structure

The Scripts blueprint follows the same structure as other blueprints in RWR. It can be defined in YAML, JSON, or TOML format.

YAML Example

scripts:
  - name: example_script
    description: "An example script"
    source: scripts/example.sh
    action: run
    elevated: true
  - name: another_script
    description: "Another example script"
    content: |
      #!/bin/bash
      echo "Hello, World!"
    action: run

JSON Example

{
  "scripts": [
    {
      "name": "example_script",
      "description": "An example script",
      "source": "scripts/example.sh",
      "action": "run",
      "elevated": true
    },
    {
      "name": "another_script",
      "description": "Another example script",
      "content": "#!/bin/bash\necho \"Hello, World!\"",
      "action": "run"
    }
  ]
}

TOML Example

[[scripts]]
name = "example_script"
description = "An example script"
source = "scripts/example.sh"
action = "run"
elevated = true

[[scripts]]
name = "another_script"
description = "Another example script"
content = """
#!/bin/bash
echo "Hello, World!"
"""
action = "run"

Blueprint Fields

The Scripts blueprint supports the following fields:

Field Required Description

name

Yes

The name of the script.

description

No

A description of the script.

source

No

The path to the script file.

content

No

The inline content of the script.

action

Yes

The action to perform with the script. Currently, only run is supported.

elevated

No

Whether to run the script with elevated privileges. Default is false.

Note
Either the source or content field must be provided. If both are present, source takes precedence.

Script Execution

When the Scripts blueprint is processed, RWR will execute the specified scripts in the order they are defined. The scripts can be provided either as separate files using the source field or as inline content using the content field.

RWR supports executing scripts written in various languages, such as Bash, Python, Ruby, and more. The appropriate interpreter will be used based on the shebang line (!/bin/bash, !/usr/bin/env python, etc.) or file extension.

If the elevated field is set to true, the script will be executed with elevated privileges (e.g., using sudo on Unix-like systems).

Best Practices

  • Keep your scripts concise and focused on specific tasks.

  • Use descriptive names for your scripts to make their purpose clear.

  • Provide a shebang line at the beginning of your scripts to specify the interpreter.

  • Use the elevated field sparingly and only when necessary.

  • Consider using variables and templating to make your scripts more dynamic and reusable.

  • Test your scripts thoroughly before including them in your RWR configuration.

Troubleshooting

If you encounter issues with the Scripts blueprint, consider the following:

  • Ensure that the script files specified in the source field exist and have the correct permissions.

  • Verify that the required interpreters or dependencies for your scripts are installed on the target system.

  • Check the RWR logs for any error messages or output related to script execution.

  • Use the --debug flag when running RWR to enable verbose output and gather more information.

If you need further assistance, please refer to the Troubleshooting section or reach out to the RWR community for support.