Merge branch 'master' of ssh://apo.geoffray-levasseur.org/share/services/git/legos
This commit is contained in:
21
README.md
21
README.md
@@ -2,7 +2,7 @@
|
||||
**init.sh** is an automated configurator for system administrators. It's fully
|
||||
written using Bash scripting and aims to be platform independent. Nevertheless,
|
||||
it's requirements turns it naturally to Linux systems. It have long been tested
|
||||
using Debian GNU/Linux, Devuan and different flavor of Ubuntu.
|
||||
using Debian GNU/Linux, Devuan and different flavors of Ubuntu.
|
||||
|
||||
## Getting started
|
||||
You should consider reading that document entirely before use. If you need
|
||||
@@ -60,15 +60,18 @@ be customized using the LOGFILE environement variable.
|
||||
- **-v, --version**: Display version information, including available module
|
||||
list and their version.
|
||||
|
||||
The options cannot be concatenated like most of Unix binaries allows. For
|
||||
exemple you cannot write "*-rR*", you have to write "*-r -R*".
|
||||
|
||||
### Loading order and process
|
||||
|
||||
The first thing the script do is loading its libraries contained in the "lib"
|
||||
The first thing the script do is loading its libraries contained in the "*lib*"
|
||||
directory. Any file situated in that directory ending with the .sh extention
|
||||
will be loaded in alphabetical order. For that reason, error management
|
||||
functions are placed in a file called aaa_error.sh, so it can be loaded first
|
||||
and catch errors that could occurs while loading library files. In the opposite
|
||||
the zzz_main_fct.sh file have to be loaded last, because it's widely using
|
||||
previously declared libraries.
|
||||
and catch errors that could occurs while loading others library files. In the
|
||||
opposite the zzz_main_fct.sh file have to be loaded last, because it's widely
|
||||
using previously declared libraries.
|
||||
|
||||
After that, a basic command line parameter treatment is done. That allows the
|
||||
use of --version and --help options in user space. Those options just display
|
||||
@@ -84,9 +87,9 @@ Finally checking processes are launched in their declaration order (cf.
|
||||
configuration file). If no error occurs and after a confirmation prompt, final
|
||||
treatment processes, those that actually makes changes, are launched.
|
||||
|
||||
Without the --keep-going option any error will imediatelly stop execution. Some
|
||||
errors that could make the script impossible to execute will stop execution,
|
||||
even if the --keep-going option is provided.
|
||||
Without the *--keep-going* option any error will imediatelly stop execution.
|
||||
Some errors that could make the script impossible to execute will stop
|
||||
execution, even if the *--keep-going* option is provided.
|
||||
|
||||
### Main configuration file
|
||||
|
||||
@@ -102,7 +105,7 @@ module you will use. Please refer to module header to see what's available for
|
||||
your use case.
|
||||
|
||||
After a module version upgrade you should check again headers as variable name
|
||||
or stucture might change. A variable ca also be deleted, new variables could
|
||||
or stucture might change. A variable can also be deleted, new variables could
|
||||
appears, and so on.
|
||||
|
||||
It is heavily recommended to use includes technique to shorten your
|
||||
|
||||
113
doc/dev.md
113
doc/dev.md
@@ -1,14 +1,14 @@
|
||||
# init.sh developper's reference
|
||||
|
||||
## Getting started
|
||||
This is a programmer reference. It's not intended to be a manual, but a reference
|
||||
for all internal functions, so you can easily build your own modules. This
|
||||
suppose you already read the [Readme file](../README.md). Creating modules
|
||||
## 1. Getting started
|
||||
This is a developper's reference. It's not intended to be a manual, but a
|
||||
reference for all internal functions, so you can easily build your own modules.
|
||||
This suppose you already read the [Readme file](../README.md). Creating modules
|
||||
will also requires some good knowledge of Bash programming.
|
||||
|
||||
## The aaa_error.sh file
|
||||
### Functions
|
||||
#### check_root
|
||||
## 2. The aaa_error.sh file
|
||||
### 2.1. Functions
|
||||
#### 2.1.1. check_root
|
||||
Check if user is root. If user is not root, script execution is interupted and
|
||||
exit with error.
|
||||
|
||||
@@ -17,42 +17,48 @@ This function have no parameter.
|
||||
If the variable NO_ROOT_CHECK is set to true the function always exit without
|
||||
error and no check is done.
|
||||
|
||||
#### die
|
||||
#### 2.1.2. die [--force] \<exitcode\>
|
||||
Trigger an error, print a backtrace and exit the script, unless KEEPGOING
|
||||
variable is set to true. In that situation we just display a warning.
|
||||
|
||||
If the parameter --force is given, we exit even if the KEEPGOING variable is set
|
||||
to true.
|
||||
If the parameter *--force* is given, we exit even if the KEEPGOING variable is
|
||||
set to true.
|
||||
|
||||
#### noerror
|
||||
Allow te execution of a command bypassing the error management system. The purpose
|
||||
is to allow execution of test returning normally a non zero value without
|
||||
triggering an error and the following exit.
|
||||
#### 2.1.3. noerror [--noout] \<command\>
|
||||
Allow the execution of a command bypassing the error management system. The
|
||||
purpose is to allow execution of test returning normally a non zero value
|
||||
without triggering an error and the exit comming with.
|
||||
|
||||
If the first parameter is --noout all the outputs are disabled. The other
|
||||
parameters are the raw command line to execute.
|
||||
If the first parameter is *--noout* any outputs on standard and error console
|
||||
are disabled. The other parameters is the raw command line to execute.
|
||||
|
||||
The function echoes the error code returned by the executed command.
|
||||
In any case the function echoes the error code returned by the executed command.
|
||||
|
||||
### Other functionnalities
|
||||
The simple integration of aaa_error.sh file into a script, will change the script
|
||||
behaviour. The following Bash signals will be trapped:
|
||||
### 2.2. Other functionnalities
|
||||
The simple integration of aaa_error.sh file into a script, will change the
|
||||
entire script behaviour regarding errors. The following Bash signals will be
|
||||
trapped:
|
||||
- **ERR**: The ERR signal is triggered every time Bash encounter an error or if
|
||||
a command return a non zero value. The function called on that signal will stop
|
||||
execution of the script displaying an error message with error code and a backtrace
|
||||
to help identify the error origin.
|
||||
- **SIGINT**: That signal is trigerred when Ctrl + C is pressed by the user. That
|
||||
signal will be interpreted only if the command is a Bash internal. If an executable
|
||||
receive the signal it will be interpreted with the own executable mechanisms. We
|
||||
will exit after cleanup.
|
||||
- **SIGTERM**: That signal is typically the result of an external kill of the bash
|
||||
process running the script. We will exit after cleanup.
|
||||
execution of the script displaying an error message with error code and a
|
||||
backtrace to help identify the error origin. Because of this behaviour, the
|
||||
function superseed the internal "**errexit**" Bash configuration switch, unless
|
||||
the *noerror* function is used.
|
||||
- **SIGINT**: That signal is trigerred when Ctrl + C is pressed by the user.
|
||||
That signal will be interpreted only if the command being executed when the
|
||||
event occurs is a Bash internal. If an executable program receive the signal it
|
||||
will be interpreted with its own mechanisms, generally resulting in an execution
|
||||
error that will trigger an **ERR** signal as described above. The script will
|
||||
exit after cleanup when that signal is trapped.
|
||||
- **SIGTERM**: That signal is typically the result of an external kill of the
|
||||
bash process running the script. The kill signal can comes from the kernel or
|
||||
through the use of a *kill* command. The script will exit after cleanup.
|
||||
|
||||
## The display.sh file
|
||||
### Functions
|
||||
#### prnt
|
||||
## 3. The display.sh file
|
||||
### 3.1. Functions
|
||||
#### 3.1.1. prnt [I|W|E|m] \<message\>
|
||||
Print a message with timestamp and header. The header depends on first parameter
|
||||
will be collored and have a fixed lenght so text is always alligned.
|
||||
will be collored and have a fixed length so the messages will always be alligned.
|
||||
|
||||
The first parameter is the header type, having those possible values:
|
||||
- **I**: Display an informative message in green
|
||||
@@ -63,16 +69,45 @@ The first parameter is the header type, having those possible values:
|
||||
|
||||
Second parameter is the message to display.
|
||||
|
||||
### Other functionnalities
|
||||
### 3.2. Other functionnalities
|
||||
Using that script will declare many easy to remember variables containing Bash
|
||||
color codes :
|
||||
|
||||
- Standard codes depending on your environment: DEFAULTFG, DEFAULTBG, DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
||||
- Regular Colors: Black, Red, Green, Yellow, Blue, Purple, Cyan, White
|
||||
- Standard codes depending on your environment: DEFAULTFG,
|
||||
DEFAULTBG, DEFAULTCOL=*${DEFAULTBG}${DEFAULTFG}*
|
||||
- Regular colors: Black, Red, Green, Yellow, Blue, Purple, Cyan, White
|
||||
- Bold: BBlack, BRed, BGreen, BYellow, BBlue, BPurple, BCyan, BWhite
|
||||
- Underline: UBlack, URed, UGreen, UYellow, UBlue, UPurple, UCyan, UWhite
|
||||
- Background: On_Black, On_Red, On_Green, On_Yellow, On_Blue, On_Purple, On_Cyan, On_White
|
||||
- High Intensity: IBlack, IRed, IGreen, IYellow, IBlue, IPurple, ICyan, IWhite
|
||||
- Bold High Intensity: BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple, BICyan, BIWhite
|
||||
- High Intensity backgrounds: On_IBlack, On_IRed, On_IGreen, On_IYellow, On_IBlue, On_IPurple, On_ICyan, On_IWhite
|
||||
- Background: On_Black, On_Red, On_Green, On_Yellow, On_Blue, On_Purple,
|
||||
On_Cyan, On_White
|
||||
- High intensity: IBlack, IRed, IGreen, IYellow, IBlue, IPurple, ICyan, IWhite
|
||||
- Bold high intensity: BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple,
|
||||
BICyan, BIWhite
|
||||
- High intensity backgrounds: On_IBlack, On_IRed, On_IGreen, On_IYellow,
|
||||
On_IBlue, On_IPurple, On_ICyan, On_IWhite
|
||||
|
||||
For exemple if you what to wite "ATTENTION: this is a warning!" in red with
|
||||
"ATTENTION:" on yellow background, you should write:
|
||||
```shell
|
||||
echo -e "${IRed}${On_IYellow}ATTENTION:${DEFAULTBG} this is a warning!${DEFAULTCOL}"
|
||||
```
|
||||
|
||||
## 4. The filefct.sh file
|
||||
### 4.1. Functions
|
||||
#### 4.1.1. stdtime
|
||||
Display date and time based on RFC 3339 standard but slightly modified so it can
|
||||
be used in filename.
|
||||
|
||||
That fonction takes no parameters and return its result on standard output.
|
||||
|
||||
#### 4.1.2. backupdist \<list_of_files_or_dirs\>
|
||||
That fuckyion will provide a backup of any given files or directories given in
|
||||
command line. The backup will be named name.dist-timestamp, where name is the
|
||||
original file or directory name and timestamp the date and time of the backup
|
||||
as retuned by the ***stdtime*** function. If a file given in parameter don't
|
||||
exists the function will issue a warning and continue to the next.
|
||||
|
||||
The function don't take any other parameters than file and/or directory names.
|
||||
|
||||
#### 4.1.3. installfile \<sources\> \<destination\>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user