DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on • Edited on

How to Share Simple Bash Tasks with Others by Using Sparrow

Sparrow is a Linux scripting platform to ease the daily scripting jobs and distribution. In this small post I am going to show you how to share simple Bash tasks with the rest of the world.

Install Sparrow

$ sudo yum install curl
$ cpanm -q --notest Sparrow 
Enter fullscreen mode Exit fullscreen mode

Create Bash Task

First of all we need Bash plugin:

$ sparrow index update
$ sparrow plg install bash
Enter fullscreen mode Exit fullscreen mode

Then let's create a task. I always forgot how to install Rvm/Ruby so I want a mnemonic command for this:

$ sparrow project create utils
$ sparrow task add utils ruby-rvm-stable bash 
Enter fullscreen mode Exit fullscreen mode
$ EDITOR=nano && sparrow task ini utils/ruby-rvm-stable
command: "\curl -sSL https://get.rvm.io | bash -s stable --ruby"

Enter fullscreen mode Exit fullscreen mode

Share Bash Task

First of all you need to get an account at SparrowHub, because you're going to save your task into the account.

Then having set credentials up:

$ cat ~/sparrowhub.json

{
  "user"  : "melezhik",
  "token" : "*****-****-****-*******-*****"
}

Enter fullscreen mode Exit fullscreen mode

Just upload the task with some useful description:

$ sparrow remote task upload utils/ruby-rvm-stable "Install RVM stable with ruby"
Enter fullscreen mode Exit fullscreen mode

By default your tasks are private so it is only you who can see them. Let's take simple step to changes this:

$ sparrow remote task share utils/ruby-rvm-stable
Enter fullscreen mode Exit fullscreen mode

Running Remote Bash Task

Now the rest of the team could enjoy your little nifty task. To do this they only need Sparrow client installed:

$ sparrow remote task run melezhik@utils/ruby-rvm-stable
Enter fullscreen mode Exit fullscreen mode

Community Remote Tasks

To list SparrowHub community remotes task just say this:

$ sparrow remote task public list
Enter fullscreen mode Exit fullscreen mode

Further reading is Sparrow documentation on remotes tasks.

Conclusion

Sparrow enables creation of scripts in easy and fun manner. Or if you want - "Quick and dirty way to develop some useful script and share with others".

Top comments (2)

Collapse
 
melezhik profile image
Alexey Melezhik • Edited

Hi! Sparrow's support for hosted solutions is limited. Drop me an issue on GH on this and I'll see what can I do to improve this ( should be a big deal as SparrowHub source code is ready to open source, just stored at private GitLab repo )

As workaround you can use gemote Git repositories to host your private sparrow plugins, the example in the paper could be rewritten as:

Create sparrow plugin


$ git init

$ nano story.bash
curl -sSL https://get.rvm.io | bash -s stable --ruby

$ nano sparrow.json
{
  "name" : "ruby-rvm-stable"
}

$ git add story.bash sparrow.json

$ git commit -a -m "my sparrow plugin to install ruby/rvm"
$ git remote add origin https://github.com/melezhik/ruby-rvm-stable.git
$ git push -u origin master

Spin up custom Sparrow repository and add a plugin to index

Then you have to add plugin to the custom Sparrow repository:


$ nestd start --host 192.168.0.1 --port 4441

$ curl \
 -d name=ruby-rvm-stable \
 -d url=https://github.com/melezhik/ruby-rvm-stable.git \
 -L  192.168.0.1:4441/add

Use Sparrow plugin

And then end user need just need this:


$ echo repo: 192.168.0.1:4441 >> ~/sparrow.yaml 
$ sparrow index update
$ sparrow plg install ruby-rvm-stable
$ sparrow plg run ruby-rvm-stable

 
melezhik profile image
Alexey Melezhik • Edited

Sure. Meanwhile here these links:

Let me know if anything else you need. I would be glad to adapt Sparrow for users needs.