SM Framework

The SM framework is a framework for developing, maintaining and sharing scripts, while exposing them for easy automation via a clean, consistent DSL-centric command-line interface.

Core

SM Framework Core (sm) is installed onto a system and is then used to manage that system through extensions.

Dependencies

The primary requirement for sm is zsh (>= 4.2), secondarily are standard unix tools such as {bash (>= 3.2), GNU awk, GNU sed, grep, which, ls, cp, tar, curl, gunzip, bunzip2}. While not a direct dependency, nearly all open source extensions currently install via git (> 1.7).

Installing SM Core

curl -Ls https://install.smf.sh | bash -

Extensions ( Modules )

SM is a tool install, manage and execute extensions. All system management functionality happens through extensions.

Extensions are directories that contain a bin and/or shell directory at minimum. Executable scripts within this directory's bin directory are exposed on the sm command line once the extension is installed.

Hello World Extension

Traditionally we write hello world to show features of a language, so lets use this idea in the context of an sm extension.

mkdir -p example/bin
echo '#!/bin/sh' > example/bin/world 
echo "echo '~> Hello World!'" >> example/bin/world
chmod +x example/bin/world

Then with sm (see sm install section below) we install the extension from the 'example' directory we just created

sm ext install hello ./example
Now we can call the 'world' script in the 'hello' extension via sm:

sm hello world
~> Hello World!

Extension Directory Layout

Extensions can have any arbitrary subdirectories that you deem necessary. There are a few that have special meaning if using the shell scripting APIs. Let's look at a directory tree of an example extension.

example/
├── bin/
├── config/
│   ├── defaults
├── shell/
│   ├── functions
│   ├── includes
│   └── initialize
└── templates/

Executable files exposed from within the bin directory can be of any type that can be executed/interpreted by the target system. For example they can be binary, shell, or other scripting languages. If you write the scripts as shell scripts they will be interpreted by zsh and you can include any shell language APIs you'd like to make your scripts more readable and debuggable.

The shell/ directory is used with the shell language APIs to run scripts in bin/. When running a shell bin script first any shell language API's you would like to include (next section) are included in the shell/includes file, one per line. Any functions you define in the shell/functions file are sourced next. After functions are loaded the shell/initilize file is sourced next. Finally after the above are complete your bin shell script is sourced within the context of the APIs, functions and initialize scripts.

This gives you a simple mechanism for sharing code across the bin shell scripts within the extension.

Depending on what you are doing you may want to store configuration defaults. This can be done in the config/defaults file.

Langauge APIs

A core concept with the SM framework is that of creating language specific APIs to make system scripting and management simpler, debuggable and os agnostic (to the extent possible). The most robust example of this to date is the shell API.

Repositories

All Open Source SM Framework repositories can be found in the github sm organization.

Core Repositories

Core repositories are sm, and sm-util, the version 1.0.0 repository is forthcoming and is written in go.

Extension Repositories

Single extension repositories are separated with an underscore "sm_" while sets of extensions (a directory with extensions as sub directories) are separated with a hyphen "sm-".

Community

IRC Channel is #smf.sh on irc.freenode.net where you can ask questions and participate.