18
eggsh.com @ gitlab.eggsh.com @ @eggsh_com Eggsh: Powerful Bash Scripting Made Easy Steve Amerige & Firas Khasawneh SAS Institute

Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

eggsh.com @ gitlab.eggsh.com @ @eggsh_com

Eggsh:Powerful Bash Scripting Made Easy

Steve Amerige & Firas KhasawnehSAS Institute

Page 2: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

What is Eggsh?

Eggsh (“Egg Shell”)

• Wraps Bash functionality with a thin shell

• Enables Bash scripts to be reusable

• Extends Bash to include powerful new features

• Turns Bash into a platform• for 360° release engineering lifecycle

• for enterprise-grade software development

• for built-in documentation and testing needs

Take a look inside: Eggsh is meant to be cracked open!

Page 3: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Why do this?

Problems

• Flat namespace

• Only simple data types

• No built-in help

• Difficult to share code

Solutions

• Package namespace

• JSON data

• Help is built in

• Release lifecycle

Page 4: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Getting Started

Developers

• git clone https://gitlab.eggsh.com/eggsh/<project>

IT Administrators

• wget https://repo.eggsh.com/eggsh/<project>.binbash <project>.bin

Users

• No action needed, just use Eggsh installed to network path

Documentation

• https://eggsh.com

Page 5: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Eggsh Architecture

Eggsh Parser & Variables

Arr

ay

Ob

ject

Toke

niz

er

JSO

N

Secu

rity

Hel

p

Stri

ng

Form

at

Co

nf

Dif

f

Git …

Package Package

Package

Package Package Package

Package Package

Co

reC

om

po

ne

nts

Use

rP

ack

ag

es

Page 6: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Directory Structure

Source Distributions

Source code is under a common source directory• $_sourceDir/<project>/

Packages are named using reversed domain names• …/packages.d/<tld.package.name>/

Code is organized into components• …/<component>/<code>…/version.json

Release Distributions

• $_releaseDir/packages.d/<package.name.tld>/<component>/…• Same as a Source Distribution, but without the <project> directory

Page 7: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Using Eggsh

Eggsh parses commands to call functions

Function Definition

show_me(){

# Usage: [–n <numberOfTimes>] message…}

Command Execution with Output

% egg show me –n 3 "Hello World"

Hello WorldHello WorldHello World%

Page 8: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Function Collisions

Different packages can implement the same function

File: packages.d/com.acme/show/show.sh

# The com.acme implementation of show me:show_me(){

# Usage: [–n <numberOfTimes>] message…}

File: packages.d/com.abc/display/display.sh

# The com.abc implementation of show me:show_me(){

# Usage: message…}

Which function above would be called?

% eggsh show me

Page 9: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Namespace Protection

Solving function and variable name collisionsSpecify package ordering on the command line

• egg –p com.acme –p com.abc show me –n 3 "Hello World"

Include package qualifiers for functions and variables

• @ show_me()

{

(@)_VarName="Hello World"

@ -p com.xyz show me $(@)_VarName

}

Provide a default ordering for packages

• @ __ORDER(){

:package_order –c –p com.acme –p com.abc}

Page 10: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Static Package Substitution

Some strings are replaced when the cache file is created

Source code in packages.d/com.abc/display/display.sh

@ show_me()

{

(@)_VarName="Hello World"

@ -p com.xyz show me $(@)_VarName

}

Cached code in ~/.egg/cache.sh

com.abc::show_me()

{

com_abc__VarName="Hello World"

@ -p com.xyz show me $com_abc__VarName

}

Page 11: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Object Oriented

Instantiate an object and call methods@ show_circle(){

local X=${1:-2} Y=${2:-5} R=${3:-5} # Define defaults for x, y, and recho "Circle: ($X,$Y) r=$R"

:new Circle obj : x $X y $Y z $Z # Instantiate obj and set fields$obj:show "Instantiated Circle: "$obj:move 1 2 # translate origin by (1,2)$obj:show "Translated Circle: "

# Note the + operator means to "chain" using the last returned object# In this case, it is the same as $obj.# So $obj:grow is the same as + :grow+ :grow 3.5 # Scale by 3.5+ :show "Scaled Circle: "

}

Command execution with output% egg show circleCircle: (2,5) r=5Instantiated Circle: Circle center=2, 5, radius=5Translated circle: Circle center=3, 7, radius=5Scaled Circle: Circle center=3, 7, radius=17.5%

Page 12: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

User Packages

Build upon the Core Platform

• Create a dependency hierarchy of User packages

• Demo will include two User packages• com.eggsh.nspawn: builds nspawn container

• com.eggsh.postgresql: installs and configures postgresql inside a container

com.eggsh.nspawn

com.eggsh.postgresql com.eggsh.rabbitmq

Use

rP

ack

ag

es

Eggsh Core

Page 13: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Building a Container

Use JSON Data instead of Bash Variables

Package com.eggsh.nspawn APIs

• centos download packages

• centos create container

JSON Configuration

• Used by APIs CentOS Configuration

PostgreSQL Configuration

Page 14: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Deploy and Run PostgreSQL

Package com.eggsh.postgresql APIs

• Install PostgreSQL, gets JSON configuration and uses:• com.eggsh.nspawn::centos download packages

• com.eggsh.nspawn::centos create container

• Configure PostgreSQL– initialize database, create test user

• Start PostgreSQL• com.eggsh.postgresql::start postgresql

• Stop PostgreSQL• com.eggsh.postgresql::stop postgresql

Page 15: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Cloud is Harder

IaaS (OpenStack, VSphere, Amazon, etc.)VM

Cloud VM

Bare Metal Server

??? Unknown Config??? Installation Restrictions

ContainerFull

Control

Known ConfigurationNo Installation Restrictions

Server Full Control

Direct Access

API Access

Page 16: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Demo Time!

Would you like to see a demo?

Page 17: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Eggsh Vertical: BOSH

Page 18: Eggsh · 2018. 6. 13. · What is Eggsh? Eggsh (“Egg Shell”) •Wraps Bash functionality with a thin shell •Enables Bash scripts to be reusable •Extends Bash to include powerful

Thanks!

Learn more!

• eggsh.com• gitlab.eggsh.com• @eggsh_com @ twitter.com/eggsh_com

Contribute!

[email protected]

SAS Institute is proud to both contribute to and use Open Source software!