Linecook

A shell script generator.

Description

Linecook generates shell scripts using an extensible set of ERB helpers. The shell scripts and associated resources (files, subscripts, etc) make up packages that can be used, for example, to provision servers.

Linecook provides a command line tool to manage development servers, generate scripts, and run scripts on servers. Helpers and recipes can be shared as gems; the canonical shell helpers are available through Linebook.

See the documentation for help to:

Usage

Generate a project.

% linecook init chalkboard
% cd chalkboard

Define default attributes.

[attributes/chalkboard.rb]
attrs['chalkboard']['n'] = 3
attrs['chalkboard']['color'] = 'white'
attrs['chalkboard']['message'] = 'I will not manually configure my server'

Define a helper.

[helpers/chalkboard/echo_in_color.erb]
Echo a string in color.
(color, str)
  color_codes = Hash[*%W{
    black       0;30   red         0;31
    white       1;37   green       0;32
    light_gray  0;37   blue        0;34
  }]
--
echo -e '\033[<%= color_codes[color.to_s] %>m<%= str %>\033[0m'

Use both in a recipe.

[recipes/chalkboard.rb]
attributes "chalkboard"
helpers "chalkboard"

attrs['chalkboard']['n'].times do
  echo_in_color attrs['chalkboard']['color'], attrs['chalkboard']['message']
end

Define a package to use the recipe; set non-default attributes as needed.

[packages/chalkboard.yml]
chalkboard:
  n: 5
  color: blue

Generate the package from the attributes, helpers, and recipe.

% linecook build

Check the packages directory to see the resulting script.

% cat packages/chalkboard/run
echo -e '\033[0;34mI will not manually configure my server\033[0m'
echo -e '\033[0;34mI will not manually configure my server\033[0m'
echo -e '\033[0;34mI will not manually configure my server\033[0m'
echo -e '\033[0;34mI will not manually configure my server\033[0m'
echo -e '\033[0;34mI will not manually configure my server\033[0m'

Now run the package.

% linecook run

The package can be run on any server accessible via ssh. See the generated ‘config/ssh’ file as well as the documentation for Running Scripts on Servers.

Composition

Linecook consists of the following.

= Components =
attributes
helpers
|-----> recipes -> packages -a-> (scripts) -b-> (servers) <-c- server setup
files
templates

= Commands =
ex: 'linecook build' on the command line

a) env, helper, package, build        # build scripts
b) run                                # run scripts
c) start, stop, ssh, snapshot, reset  # server setup/control

Everything to the left of ‘scripts’ has to do with generating scripts; everything to the right with running scripts on servers.

Installation

Linecook is available as a gem.

% gem install linecook

Info

Developer

Simon Chiang

License

MIT-Style