Coder Social home page Coder Social logo

bashible's Introduction

BASHIBLE

Bashible is a deployment/automation tool written in Bash (DSL). Inspired by Ansible. Simplifies things and prevents usual mistakes.

Features:

  • improved readability
  • unhandled failures prevention
  • skipping already done tasks
  • command chaining
  • working directory always as expected
  • variable checking
  • dependencies; calling sub-scripts
  • delayed tasks executed on finish
  • child termination handler; no processes left running
  • modules: template engine, config editing, etc.
  • nice output

At the moment, bashible has been used on Arch linux. It may not be compatible with other platforms, because it internally uses GNU/sed, grep, etc.

Suggestions and bugfixes are welcome! :-)

Example output

Example output

Example script.bash

@ represents a block of tasks, - represents a task. Both @ and - are just bash functions with arguments.

#!/usr/local/bin/bashible

# the working directory is automatically set to the script's
# all tasks will stop execution immediately on failure, unless prefixed by "may_fail"

@ Synchronizing files
  - result synced rsync -av /foo /bar

@ Shutting down the machine
  - when synced
  - when test -f /etc/do-shutdown
  - shutdown -h now

@ Sending an e-mail unless synchronization succeeded
  - when not synced
  - mail [email protected] <<< "synchronzation failed"

Rewritten into pure Bash, the example above could look like this,

#!/bin/bash

cd `dirname $0`
set -eux -o pipefail

echo Synchronizing files
if rsync -av /foo /bar; then
  echo Shutting down the machine
  if test -f /etc/do-shutdown; then
    shutdown -h now
  fi
else
  echo Sending an e-mail unless synchronization succeeded
  mail [email protected] <<< "synchronzation failed"
fi

See also examples in the example directory.

Install & usage

Install bashible and it's modules (sourceable functions - here just one module, "edit"). Copy everything to the same directory.

wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible
wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible.edit
chmod 755 bashible
chmod 755 bashible.edit
mv bashible /usr/local/bin
mv bashible.edit /usr/local/bin

Run the script

bashible my-script.bash ARG1 ARG2 ...

or put she-bang in the beginning of the script and then run it directly

#!/usr/local/bin/bashible

run it

./my-script.bash ARG1 ARG2 ...

Functions

core functions

@ MESSAGE
- COMMAND ARGS ...
absolute_path PATH
always_output_to DEST COMMAND ARGS ...
bashible_version
base_dir PATH
delayed COMMAND ARGS ...
dir_empty PATH
empty COMMAND ARGS ...
evaluate STRING
fail MESSAGE
finish MESSAGE
fill_var VAR COMMAND ARGS ...
halt MESSAGE
not COMMAND ARGS ...
may_fail COMMAND ARGS ...
output_to DEST COMMAND ARGS ...
orig_dir
print_error MSG print_info MSG print_warn MSG quiet COMMAND ARGS ...
reset_base_dir
result NAME COMMAND ARGS ...
run PATH ARGS ...
set_var VAR VALUE
toplevel
var_empty VAR
when COMMAND ARGS ...
unless_already COMMAND ARGS ...
use FEATURES ...

file-editing functions - found in bashible.edit module

add_line LINE PATH
append_line LINE PATH
comment_lines_matching REGEXP PATH
prepend_line LINE PATH
remove_lines_matching REGEX PATH
replace_lines_matching REGEXP STRING PATH
replace_matching REGEXP STRING PATH
uncomment_lines_matching REGEXP PATH

template engine - found in bashible.template module

template TEMPLATE_PATH RESULT_PATH

timeout - found in bashible.timeout module

in_timeout SECS COMMAND ARGS ...

network-oriented functions - found in bashible.net module

wait_for_tcp MATCH up|down

TODO

Write more docs and examples.

Modularize. The bashible core in the version 1.0 should contain only necessary functions and should not ever change. For instance, the delayed and unless_already COMMAND ARGS ... functions now need two temporary files. These files are created on every bashible startup. These functions should go into optional modules instead.

Create tests. Bashible uses GNU/grep, GNU/sed and other programs which may not work properly on all platforms.

Make bashible multiplatform.

Create more modules and/or integrate existing Bash libraries.

bashible's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.