Friends of Ba$h. A collection of useful bash functions. Easy to include in your bash scripts.
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.
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.
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
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.
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.
user$ friends-of-bash update
user$ friends-of-bash osName
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
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
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
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.
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!)
user$ friends-of-bash update apache-host-viewer
user$ cd /opt/friends-of-bash/apache-host-viewer
user$ friends-of-bash update .
user$ friends-of-bash update all
user$ friends-of-bash update all -y
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
You will ask for. Please have a look at: "2.5.1) Increase the revision version number in general" (friends-of-bash updateVersion
)
You will ask for. Please have a look at: "2.5.1) Increase the revision version number in general" (friends-of-bash updateVersion
)
You will ask for. Please have a look at: "2.5.1) Increase the revision version number in general" (friends-of-bash updateVersion
)
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
- array
- cert
- checker
- color
- date
- device
- docker
- docker-container
- docker-image
- domain
- file
- filesystem
- general
- git
- install
- json
- network
- output
- screen
- string
- system
- version
MIT © Björn Hempel