Skip to content

bjoern-hempel/friends-of-bash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

friends-of-bash

Friends of Ba$h. A collection of useful bash functions. Easy to include in your bash scripts.

0.) Requirements

You need bash with version 4 at least, because it supports associative arrays and other stuff (https://www.admon.org/scripts/new-features-in-bash-4-0/):

user$ bash --version
GNU bash, Version 4.4.12(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
...

If you have a version lower than the version 4 (for example on mac):

user$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.

You have to update your bash version first.

0.1) Update bash on mac to version 4

user$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
user$ brew update && brew install bash

Reopen your terminal and check again:

user$ bash --version
GNU bash, Version 4.4.19(1)-release (x86_64-apple-darwin17.3.0)
Copyright (C) 2016 Free Software Foundation, Inc.
...

Add the new shell to the list of allowed shells:

user$ sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'

Change the shell:

user$ chsh -s /usr/local/bin/bash

Check the used shell locations:

user$ which -a bash
/usr/local/bin/bash
/bin/bash

Looks good. Now you are ready to use this library on your mac as well.

1.) First usage

1.1) Installation & show version

user$ cd ~ && git clone git@github.com:bjoern-hempel/friends-of-bash.git && cd friends-of-bash
user$ sudo -E bin/install
user$ cd .. && rm -rf friends-of-bash
user$ friends-of-bash --version
friends-of-bash/v0.0.51

1.2) Show help

user$ friends-of-bash --help

"friends of bash": A bash function library (v0.0.51) by Björn Hempel <bjoern@hempel.li>.

Usage: /usr/local/bin/friends-of-bash [options...] {install|status|update|version|list|updateAvailable|osName}
 -y,    --yes                     Auto yes. Don't answer to update questions.

 -s,    --short                   Try to shorten the output.

 -r,    --remote                  Do a remote check.

 -h,    --help                    Shows this help.

 -v,    --version                 Shows the version number.

1.3) Show status

user$ friends-of-bash status

friends-of-bash
---------------

Currently installed version:   v0.0.51
Available version:             v0.0.51

Currently installed changeset: 2e86d582411c2df92ddefb0acd41e0bc5cd0a01b
Available changeset:           2e86d582411c2df92ddefb0acd41e0bc5cd0a01b

Your "/opt/friends-of-bash/friends-of-bash" version is up to date. Nothing to do here.

1.4) Update friends-of-bash library

user$ friends-of-bash update

1.5) Show os name and version

user$ friends-of-bash osName

2.) Manage other repositories

2.1) Installation & show version

Use the parameter -E to pass through your ssh private key while doing a sudo git clone:

user$ sudo -E friends-of-bash install "git@github.com:bjoern-hempel/apache-host-viewer.git"

or

user$ sudo -E friends-of-bash install "git@github.com:bjoern-hempel/hello-world.git"

With this technique you can install any git repository you want to. After installation via friends-of-bash install you can do the versioning handling with the friends-of-bash helper (see next chapters). Showing the version numbers:

user$ friends-of-bash version apache-host-viewer
apache-host-viewer/v0.0.2

or

user$ friends-of-bash version hello-world
hello-world/v1.0.0

All installed repositories you will find below the directory /opt/friends-of-bash. The installer will execute an install file (if exists). The install file must be located directly within the root folder of your repository by the name of install. Alternatively you can create an install folder with some symlinks linked to existing files within your repository. They all will be installed at /usr/local/bin. Go here https://github.com/bjoern-hempel/apache-host-viewer/tree/master/install to see an example that will create a symlink like this:

user$ ls -l /usr/local/bin/.
insgesamt 12
lrwxrwxrwx 1 root staff  62 Jun  4 20:01 apache-host-viewer -> /opt/friends-of-bash/apache-host-viewer/bin/apache-host-viewer
...

You can execute the above mentioned symlink apache-host-viewer from anywhere you want to like this:

user$ apache-host-viewer --version
apache-host-viewer/v0.0.2

2.2) list all packages installed via friends-of-bash install

2.2.1) Full output

user$ friends-of-bash list
apache-host-viewer - apache-host-viewer/v0.0.40
backup-mysql - backup-mysql/v0.0.3
friends-of-bash - friends-of-bash/v0.0.51
hello-world - hello-world/v1.0.8
project-analyser - project-analyser/v0.0.10
service-checker - service-checker/v0.0.18

2.2.2) Short output

user$ friends-of-bash list --short
apache-host-viewer/v0.0.40
backup-mysql/v0.0.3
friends-of-bash/v0.0.51
hello-world/v1.0.8
project-analyser/v0.0.10
service-checker/v0.0.18

2.3) Show status

2.3.1) From a single application

user$ friends-of-bash status apache-host-viewer

apache-host-viewer
------------------

Currently installed version:   v0.0.40
Available version:             v0.0.40

Currently installed changeset: 674c4a6854c45d73bdfa1f43a077f1b5d538449f
Available changeset:           674c4a6854c45d73bdfa1f43a077f1b5d538449f

Your "/opt/friends-of-bash/apache-host-viewer" version is up to date. Nothing to do here.

2.3.2) From all applications

user$ friends-of-bash status all
apache-host-viewer - apache-host-viewer/v0.0.39 - new version is available (v0.0.40)
backup-mysql - backup-mysql/v0.0.3 - application is up to date
friends-of-bash - friends-of-bash/v0.0.51 - application is up to date
hello-world - hello-world/v1.0.8 - application is up to date
project-analyser - project-analyser/v0.0.10 - application is up to date (Attention: 3 changed files found!)
service-checker - service-checker/v0.0.18 - application is up to date (Attention: 1 changed files found!)

2.4) Update friends-of-bash application

2.4.1) Individual (Example I)

user$ friends-of-bash update apache-host-viewer

2.4.2) Individual (Example II)

user$ cd /opt/friends-of-bash/apache-host-viewer
user$ friends-of-bash update .

2.4.3) Update all applications

user$ friends-of-bash update all

2.4.4) Don't ask. Update immediately (-y)

user$ friends-of-bash update all -y

2.5) Update version number

2.5.1) Increase the revision version number in general

This technique works with each friends-of-bash application.

user$ cd /opt/friends-of-bash/friends-of-bash
user$ friends-of-bash updateVersion .
name:            friends-of-bash
directory:       /opt/friends-of-bash/friends-of-bash
current version: v0.0.51

Which new version number do you want to use? (1) - v1.0.0, (2) - v0.1.0 or (3) v0.0.52

Choose (1), (2) or (3): 3

This will set the current version number v0.0.51 to v0.0.52. Do you want to continue? Type (y)es or (no): y

2.5.2) Increase the revision number

You will ask for. Please have a look at: "2.5.1) Increase the revision version number in general" (friends-of-bash updateVersion)

2.5.3) Increase the minor number

You will ask for. Please have a look at: "2.5.1) Increase the revision version number in general" (friends-of-bash updateVersion)

2.5.4) Increase the major number

You will ask for. Please have a look at: "2.5.1) Increase the revision version number in general" (friends-of-bash updateVersion)

3.) Usage

TODO: Describe the general usage of this library here. A basic usage application using this libraries you will find here: https://github.com/bjoern-hempel/hello-world

4.) Libraries

  1. array
  2. cert
  3. checker
  4. color
  5. date
  6. device
  7. docker
  8. docker-container
  9. docker-image
  10. domain
  11. file
  12. filesystem
  13. general
  14. git
  15. install
  16. json
  17. mail
  18. network
  19. output
  20. screen
  21. string
  22. system
  23. version

License

MIT © Björn Hempel