Skip to content

Bash Library

bash-lib icon

This is a collection of helper programs and libraries for administration tool development (mostly in bash). The complete library is build into combined packages, which mostly can be added as single include file to work.

This documentation will show you how to use them.

Installation

Mostly you won't install the bash-lib on a server but create some scripts based on it. But that won't mean you can't or you shouldn't do so. As always it depends on your needs.

See the following chapter for all the possibilities to use it.

First copy the full distribution package or only the parts you need standalone or within your application onto a server. See the downloads page for the latest releases.

Standalone Installation

For a standalone installation move the complete distribution to the to a central position and use it from there. This will often be in /opt/bash-lib and should also be included in the path for the standalone commands to be used:

wget https://alinex.gitlab.io/bash-lib/downloads/bash-lib.tgz
tar -xzvf bash-lib.tgz
cp dist /opt/bash-lib
echo "PATH=\"$PATH:/opt/bash-lib\"" >> ~/.bashrc

But you can also always copy the command directly to any other folder and use it from there.

Some of the commands needs additional helpers, which are not always installed on your server. To check if you have everything working run the checker once directly on your server:

curl https://alinex.gitlab.io/bash-lib/downloads/install | bash

This will give you information what is needed and if possible automatically installs the needed packages.

Including libraries

The most common way is to include the needed library from the release packages within the destination code. That ensures that changes to the bash-lib repository or a central installation won't change the running code. You can update it yourself anytime you want to by overwriting it with a newer version.

As already said, all files are self contained without further references. So copy the needed library as lib.bash to your project and include it relatively:

source_dir=$(dirname $(readlink -f "${BASH_SOURCE[0]:-$(pwd)/x}"))
source "$source_dir/lib.bash"

You can also pick the files directly from the complete distribution or add all of them, it's very small.

Short usage

To only use it in single bash script, put the library directly beside your script:

source_dir=$(dirname $(readlink -f "${BASH_SOURCE[0]:-$(pwd)/x}"))
source "$source_dir/base.bash"

# here you can use it

See also the following Skeleton which gives you a fast start for your own script.

Install and Use

If you want to run a script with the bash lib but don't know if it is already installed, you can always check and install before you use it automatically:

# load bash lib or use alternative log method
log() { echo $2; }
source_dir=$(dirname $(readlink -f "${BASH_SOURCE[0]:-$(pwd)/x}"))
if [ -e "$source_dir/lib/base.bash" ]; then
    source "$source_dir/lib/base.bash"
else
    # update bash lib
    log INFO "Installing bash-lib..."
    rm -rf "$source_dir/lib"
    curl -s https://alinex.gitlab.io/bash-lib/downloads/bash-lib.tgz | tar -xz
    mv dist "$source_dir/lib"
    source "$source_dir/lib/base.bash"
fi

And if you want to always update it to the newest version use:

# load bash lib or use alternative log method
log() { echo $2; }
source_dir=$(dirname $(readlink -f "${BASH_SOURCE[0]:-$(pwd)/x}"))
if [ -e "$source_dir/lib/base.bash" ]; then
    source "$source_dir/lib/base.bash"
fi
# update bash lib
log INFO "Updating bash-lib..."
rm -rf "$source_dir/lib"
curl -s https://alinex.gitlab.io/bash-lib/downloads/bash-lib.tgz | tar -xz
mv dist "$source_dir/lib"
source "$source_dir/lib/base.bash"

Statistics

The following statistics will give you a better understanding about it's complexity. The documentation has 34 pages (in A4 PDF format) and contains 41030 characters.

Download Documentation

If you want to have an offline access to the documentation, feel free to download the 34 pages PDF Documentation.

License

Alinex Bash Library

Copyright 2018-2019 Alexander Schilling (https://gitlab.com/alinex/bash-lib)

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SendMail (Perl)

This utility is included as separate helper tool.

Originally written as SendEmail by: Brandon Zehm caspian@dotconf.net under GPL http://caspian.dotconf.net/menu/Software/SendEmail (version 1.56, Sep 29th 2009)

Modified 2018 by Alexander Schilling 2018 to support environment variables for default settings.

GPLv2

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html.