43 stable releases

2.9.0 Nov 11, 2024
2.7.6 Oct 24, 2024
1.10.5 Jul 4, 2024
1.10.1 Feb 23, 2024
0.1.0 May 17, 2020

#713 in Procedural macros

Download history 10/week @ 2024-08-24 10/week @ 2024-08-31 286/week @ 2024-09-07 951/week @ 2024-09-14 143/week @ 2024-09-21 123/week @ 2024-09-28 317/week @ 2024-10-05 32/week @ 2024-10-12 113/week @ 2024-10-19 27/week @ 2024-10-26 106/week @ 2024-11-02 141/week @ 2024-11-09 21/week @ 2024-11-16 8/week @ 2024-11-23 9/week @ 2024-11-30 56/week @ 2024-12-07

99 downloads per month
Used in 2 crates (via rash_core)

Custom license

17KB
86 lines

rash

Build status Documentation crates.io concept-map Rash license Rash Aur package

Declarative shell scripting using Rust native bindings inspired by Ansible

Getting Started & Documentation

For installation and usage, see our Documentation.

Why Rash

Manage your scripts in a declarative style.

If you:

  • think that long bash scripts are difficult to maintain
  • love Ansible syntax to setup your environments

Or use it for your local scripts!

Then keep on reading.

Here is Rash!

Declarative vs imperative

Imperative: entrypoint.sh:

#!/bin/bash
set -e

REQUIRED_PARAMS="
VAULT_URL
VAULT_ROLE_ID
VAULT_SECRET_ID
VAULT_SECRET_PATH
"

for required in $REQUIRED_PARAMS ; do
  [[ -z "${!required}" ]] && echo "$required IS NOT DEFINED" && exit 1
done

echo "[$0] Logging into Vault..."
VAULT_TOKEN=$(curl -s $VAULT_URL/v1/auth/approle/login \
--data '{"role_id": "'$VAULT_ROLE_ID'","secret_id": "'$VAULT_SECRET_ID'"}' \
| jq -r .auth.client_token)

echo "[$0] Getting Samuel API key from Vault..."
export APP1_API_KEY=$(curl -s -H "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_URL/v1/$VAULT_SECRET_PATH | jq -r .data.api_key)


exec "$@"

Declarative: entrypoint.rh

#!/bin/rash

- name: Verify input parameters
  assert:
    that:
      - env.VAULT_URL is defined
      - env.VAULT_ROLE_ID is defined
      - env.VAULT_SECRET_ID is defined
      - env.VAULT_SECRET_PATH is defined

- name: launch docker CMD
  command:
    cmd: { { rash.argv } }
    transfer_pid: yes
  env:
    APP1_API_KEY: "{{ lookup('vault', env.VAULT_SECRET_PATH ) }}"

Docopts

docopt implementation included:

  • Easy to define interfaces for command-line app.
  • Automatically generate a parser from doc.

Example:

#!/usr/bin/env -S rash --
#
# Copy files from source to dest dir
#
# Usage:
#   copy.rh [options] <source>... <dest>
#   copy.rh
#
# Options:
#   -h --help    show this help message and exit
#   --mode MODE  dest file permissions [default: 0644]

- copy:
    src: "{{ item }}"
    dest: "{{ dest }}/{{ item | split('/') | last }}"
    mode: "{{ options.mode }}"
  loop: "{{ source | default ([]) }}"

Lightness

All you need to run Rash is a Linux kernel!

You can use it in your favorite IoT chips running Linux or in containers from scratch!

Status

Stable API with few modules.

Dependencies

~0.2–0.8MB
~19K SLoC