Replacing ifconfig with ip

August 12, 2017 Leave a comment
Categories: debian Tags: ,

upstart

August 1, 2017 Leave a comment

Problem:
Well this was more like an irritant. I have a portforwarding script that I manually start. I just got tired of doing that and moved it to a upstart task.

Solution:
Added the following job for upstart to handle.

$ less /etc/init/portforward.conf
description     "Portforward 3141 to devpi server"

author      "Vagrant"

start on runlevel [2345]
stop on runlevel [!2345]

script
    cd /home/vagrant

    export SSHPASS="vagrant"
    sshpass -e ssh -nNL 3141:192.168.38.18:3141 -o ConnectTimeout=10 -o LogLevel=Error -o StrictHostKeyChecking=no vagrant@192.168.38.18
end script
$
$ # Check the syntax
$ init-checkconf /etc/init/portforward.conf
$ # Start the job
$ sudo service portforward start

Source:
https://www.digitalocean.com/community/tutorials/the-upstart-event-system-what-it-is-and-how-to-use-it

Categories: bash Tags: ,

Ansible Galaxy

July 27, 2017 Leave a comment

Ansible Galaxy is Ansible’s official community hub for sharing Ansible roles. A role is the Ansible way of bundling automation content and making it reusable.

If you’re not familiar with the Ansible role concept, think of include files used in a programming language. An include file allows the programmer to organize code into reusable modules. Code can be organized into smaller files and grouped by subject matter or function. These discrete pieces of code can then be included as needed into larger programs like building blocks.

A role is similar. Instead of creating giant playbooks with hundreds of tasks we can use roles to organize tasks, breaking them apart into smaller more discrete units of work. But a role is more than just an include file. A role is all the tasks, variables and handlers needed to complete the unit of work. This allows a role to be completely self contained or encapsulated and completely reusable.

Using roles also allows us to think about node configuration in terms of modeling. For example, given a set of nodes that should be web servers we can simply apply a web server role to them. We don’t have to think about or write all the tasks needed to configure web servers. All the details are already encapsulated in a web server role – a role you downloaded from Galaxy.

https://galaxy.ansible.com/

Categories: ansible Tags: , ,

A Powerline style prompt for your shell

July 23, 2017 Leave a comment

For a hassle free powerline like shell. Works with bash and zsh.

* Shows some important details about the git/svn/hg/fossil branch (see below)
* Changes color if the last command exited with a failure code
* If you’re too deep into a directory tree, shortens the displayed path with an ellipsis
* Shows the current Python virtualenv environment
* It’s easy to customize and extend. See below for details.

https://github.com/banga/powerline-shell

Categories: bash, zsh Tags:

powerline-gitstatus

July 23, 2017 Leave a comment

Problem:
Git status with powerline

Solution:
https://github.com/jaspernbrouwer/powerline-gitstatus

1. pip install –user powerline-gitstatus

Follow the instructions in on site https://github.com/jaspernbrouwer/powerline-gitstatus
2. Add custom highlight groups.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json

Example

{
  "groups": {
    "gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
    "gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
    "gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
    "gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
    "gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
    "gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
    "gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }
  }
}

3. Activate the Gitstatus segment.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json

Example

{
    "function": "powerline_gitstatus.gitstatus",
    "priority": 40
}

4. Show most recent tag reachable in the current branch.

vim .local/lib/python2.7/site-packages/powerline/config_files/themes/shell/__main__.json

Example

"gitstatus": {
    "args": {
        "show_tag": true
    }
}

These are json files. Be careful with syntax. If editing existing files, remember to add the necessary commas where needed.

Source:
https://github.com/jaspernbrouwer/powerline-gitstatus

powerline-status

July 23, 2017 Leave a comment

Problem:
Installing powerline-status

Solution:
1. pip install –user powerline-status
2. Add the following to .bashrc

if [ -d "$HOME/.local/bin" ]; then
    PATH="$HOME/.local/bin:$PATH"
fi

export POWERLINE_COMMAND=powerline
powerline-daemon -q

POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
REPOSITORY_ROOT=/home/rodnee/.local/lib/python2.7/site-packages
. ${REPOSITORY_ROOT}/powerline/bindings/bash/powerline.sh

3. Source .bashrc. It may give some errors. Open up a new terminal and see if the changes have taken effect.

$ source .bashrc
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory

Source:
http://powerline.readthedocs.io/en/master/index.html
https://github.com/powerline/powerline/issues/850

Note:
I could not get it to work with zsh. Opted for https://pseudoscripter.wordpress.com/2017/07/23/a-powerline-style-prompt-for-your-shell/ instead.

Categories: bash Tags: ,

jq – a lightweight and flexible command-line JSON processor

July 17, 2017 Leave a comment

jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine of the same type, and expect it to work.

jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.

https://stedolan.github.io/jq/

Categories: Interesting Tags: , ,