dev.md: added service.sh doc
This commit is contained in:
66
README.md
66
README.md
@@ -5,16 +5,18 @@ its requirements turn it naturally to Linux systems. It has long been tested
|
|||||||
using Debian GNU/Linux, Devuan and different flavors of Ubuntu.
|
using Debian GNU/Linux, Devuan and different flavors of Ubuntu.
|
||||||
|
|
||||||
## Table of content
|
## Table of content
|
||||||
* [1. Getting started](#1-getting-started)
|
- [init.sh](#initsh)
|
||||||
* [2. Design](#2-design)
|
- [1. Getting started](#1-getting-started)
|
||||||
+ [2.1. Command line](#21-command-line)
|
- [2. Design](#2-design)
|
||||||
+ [2.2. Loading order and process](#22-loading-order-and-process)
|
- [2.1. Command line](#21-command-line)
|
||||||
+ [2.3. Main configuration file](#23-main-configuration-file)
|
- [2.2. Loading order and process](#22-loading-order-and-process)
|
||||||
+ [2.4. Naming conventions](#24-naming-conventions)
|
- [2.3. Configuration files](#23-configuration-files)
|
||||||
+ [2.5. Basic module structure](#25-basic-module-structure)
|
- [2.3.1. Main configuration file](#231-main-configuration-file)
|
||||||
* [3. Error code table](#3-error-code-table)
|
- [2.3.2. Automatically loaded configuration files](#232-automatically-loaded-configuration-files)
|
||||||
* [4. Contact and more information](#4-contact-and-more-information)
|
- [2.4. Naming conventions](#24-naming-conventions)
|
||||||
|
- [2.5. Basic module structure](#25-basic-module-structure)
|
||||||
|
- [3. Error code table](#3-error-code-table)
|
||||||
|
- [4. Contact and more information](#4-contact-and-more-information)
|
||||||
|
|
||||||
## 1. Getting started
|
## 1. Getting started
|
||||||
You should consider reading that document entirely before use. If you need
|
You should consider reading that document entirely before use. If you need
|
||||||
@@ -87,14 +89,18 @@ opposite the zzz_main_fct.sh file have to be loaded last, because it's widely
|
|||||||
using previously declared libraries.
|
using previously declared libraries.
|
||||||
|
|
||||||
After that, a basic command line parameter treatment is done. That allows the
|
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
|
use of *--version* and *--help* options in user space. Those options display
|
||||||
information and don't require any superuser rights and exit at that point of
|
information and don't require any superuser rights and exit at that point of
|
||||||
execution. Everything after that will require administrator rights and the
|
execution. Everything after that will require administrator rights and the
|
||||||
script will exit with error at that point if not superuser.
|
script will exit with error at that point if not superuser, unless the
|
||||||
|
*--no-root-check* option have been given.
|
||||||
|
|
||||||
Next will be the log file creation and the loading of configuration files. At
|
Next will be the log file creation and the loading of configuration files.
|
||||||
this point a deeper analysis of command line option will be done, triggering
|
Configuration files exists in two distinct categories. First system dependant
|
||||||
errors in case of inconsistency or incompatible options.
|
configuration will be loaded automatically depending on your platform, then
|
||||||
|
your own configuration. At this point a deeper analysis of command line option
|
||||||
|
will be done, triggering errors in case of inconsistency or incompatible
|
||||||
|
options.
|
||||||
|
|
||||||
Finally, checking processes are launched in their declaration order (cf.
|
Finally, checking processes are launched in their declaration order (cf.
|
||||||
configuration file). If no error occurs and after a confirmation prompt, final
|
configuration file). If no error occurs and after a confirmation prompt, final
|
||||||
@@ -104,7 +110,8 @@ Without the *--keep-going* option, any error will immediately stop execution.
|
|||||||
Some errors that could make the script impossible to execute will stop
|
Some errors that could make the script impossible to execute will stop
|
||||||
execution, even if the *--keep-going* option is provided.
|
execution, even if the *--keep-going* option is provided.
|
||||||
|
|
||||||
### 2.3. Main configuration file
|
### 2.3. Configuration files
|
||||||
|
#### 2.3.1. Main configuration file
|
||||||
|
|
||||||
The main configuration file can be two different files. Either it's completely
|
The main configuration file can be two different files. Either it's completely
|
||||||
generic and will be named **init.conf.sh** in the "conf" directory, either it
|
generic and will be named **init.conf.sh** in the "conf" directory, either it
|
||||||
@@ -128,6 +135,32 @@ so you can declare something on your organization configuration file and
|
|||||||
supersede it in your host configuration file. The only limit will be Bash
|
supersede it in your host configuration file. The only limit will be Bash
|
||||||
capabilities in terms of variable manipulation.
|
capabilities in terms of variable manipulation.
|
||||||
|
|
||||||
|
#### 2.3.2. Automatically loaded configuration files
|
||||||
|
Those file are basically the system dependent part that assure compatibility
|
||||||
|
with different Linux distributions. Some of those files are shipped with
|
||||||
|
init.sh but you can add what you want to improve possibilities or to add support
|
||||||
|
for a new distribution. init.sh understand the following possibilities in terms
|
||||||
|
of OS detection:
|
||||||
|
|
||||||
|
| Name | Variable | |
|
||||||
|
|:------------|:---------|:----------------------------------------------------|
|
||||||
|
| **arch** | SYS_ARCH | This is the system architecture, like x86_64, i386, arm64, etc. |
|
||||||
|
| **dist** | SYS_DIST | The name of the Linux distribution as reported by */etc/os-release*. |
|
||||||
|
| **version** | SYS_VER | Version of the distribution. If you run a rolling release and no version is provided by your */etc/os-release* file, the main version of the Linux kernel will be used (e.g. 5.4 for any version of 5.4. kernel branch). |
|
||||||
|
| **codename**| SYS_CODE | If your distribution profide a version codename, it will be set with it. |
|
||||||
|
|
||||||
|
The configuration files are loaded if exists in the following order:
|
||||||
|
1) arch.conf.sh
|
||||||
|
2) distro.conf.sh
|
||||||
|
3) distro-arch.conf.sh
|
||||||
|
4) distro-version.conf.sh
|
||||||
|
5) distro-codename.conf.sh (if *$SYS_CODE* defined)
|
||||||
|
6) distro-version-arch.conf.sh
|
||||||
|
7) distro-codename-arch.conf.sh (if *$SYS_CODE* defined)
|
||||||
|
|
||||||
|
The loading of those files, if one exists, cannot be avoided. They all must be
|
||||||
|
located in the *conf/auto* directory of the init.sh tree.
|
||||||
|
|
||||||
### 2.4. Naming conventions
|
### 2.4. Naming conventions
|
||||||
|
|
||||||
Because of internal mechanics, the dash character is forbidden in module names.
|
Because of internal mechanics, the dash character is forbidden in module names.
|
||||||
@@ -229,6 +262,7 @@ The following table is giving a list of error code with explanation:
|
|||||||
| 5 | Malformed module list |
|
| 5 | Malformed module list |
|
||||||
| 6 | Unable to find configuration |
|
| 6 | Unable to find configuration |
|
||||||
| 7 | Misuse of script internal function |
|
| 7 | Misuse of script internal function |
|
||||||
|
| 8 | Can't determine OS version |
|
||||||
| 11 | Bad function call |
|
| 11 | Bad function call |
|
||||||
| 12 | Error copying files |
|
| 12 | Error copying files |
|
||||||
| 13 | Bad target file system |
|
| 13 | Bad target file system |
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
# Configuration propre à Debian
|
# ------------------------------------------------------------------------------
|
||||||
|
# Declaration specific to Debian GNU/Linux
|
||||||
|
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# This file is distributed under 3-clause BSD license.
|
||||||
|
# The complete license agreement can be obtained at:
|
||||||
|
# https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Conf gestionnaire de paquet
|
# Conf gestionnaire de paquet
|
||||||
export PKG_MAN="apt-get"
|
export PKG_MAN="apt-get"
|
||||||
30
conf/auto/devuan.conf.sh
Normal file
30
conf/auto/devuan.conf.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Declaration specific to Devuan
|
||||||
|
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# This file is distributed under 3-clause BSD license.
|
||||||
|
# The complete license agreement can be obtained at:
|
||||||
|
# https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Conf gestionnaire de paquet
|
||||||
|
export PKG_MAN="apt-get"
|
||||||
|
export COM_INSTALL="install -y"
|
||||||
|
export COM_UPDATE="update"
|
||||||
|
export COM_UPGRADE="full-upgrade -y"
|
||||||
|
export COM_REMOVE="remove --purge -y"
|
||||||
|
export COM_AUTOREM="autoremove --purge -y"
|
||||||
|
|
||||||
|
# Special variable for apt tools to disable any interactive behaviour
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
# Conf chemin
|
||||||
|
export RC_SCRIPTS_PATH="/etc/init.d"
|
||||||
|
|
||||||
|
# Conf init
|
||||||
|
# Init SystemV ou OpenRC:
|
||||||
|
export INIT_COM="$RC_SCRIPTS_PATH/%srv% %com%"
|
||||||
|
# Init Systemd:
|
||||||
|
#export INIT_COM="systemctl %comm% %srv%"
|
||||||
|
# Init Upstart (plus ou moins universel)
|
||||||
|
#export INIT_COM="service %srv% %com%"
|
||||||
30
conf/auto/ubuntu.conf.sh
Normal file
30
conf/auto/ubuntu.conf.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Declaration specific to Ubuntu and derivate (eg. Kubuntu)
|
||||||
|
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# This file is distributed under 3-clause BSD license.
|
||||||
|
# The complete license agreement can be obtained at:
|
||||||
|
# https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Conf gestionnaire de paquet
|
||||||
|
export PKG_MAN="apt-get"
|
||||||
|
export COM_INSTALL="install -y"
|
||||||
|
export COM_UPDATE="update"
|
||||||
|
export COM_UPGRADE="full-upgrade -y"
|
||||||
|
export COM_REMOVE="remove --purge -y"
|
||||||
|
export COM_AUTOREM="autoremove --purge -y"
|
||||||
|
|
||||||
|
# Special variable for apt tools to disable any interactive behaviour
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
# Conf chemin
|
||||||
|
export RC_SCRIPTS_PATH="/etc/init.d"
|
||||||
|
|
||||||
|
# Conf init
|
||||||
|
# Init SystemV ou OpenRC:
|
||||||
|
#export INIT_COM="$RC_SCRIPTS_PATH/%srv% %comm%"
|
||||||
|
# Init Systemd:
|
||||||
|
#export INIT_COM="systemctl %comm% %srv%"
|
||||||
|
# Init Upstart (plus ou moins universel)
|
||||||
|
export INIT_COM="service %srv% %com%"
|
||||||
@@ -16,4 +16,4 @@ export SYSLOCALE="fr_FR.UTF-8"
|
|||||||
#export CALCMOUNTPOINT="/calcul/$HOSTNAME"
|
#export CALCMOUNTPOINT="/calcul/$HOSTNAME"
|
||||||
|
|
||||||
# Liste des serveurs NTP
|
# Liste des serveurs NTP
|
||||||
export NTPSERVERS="ntp1.$MAINDOM ntp2.$MAINDOM"
|
#export NTPSERVERS="ntp1.$MAINDOM ntp2.$MAINDOM"
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
# Importe les paramètres spécifiques LEGOS
|
# Importe les paramètres spécifiques LEGOS
|
||||||
. $MYPATH/conf/includes/legos.conf.sh
|
. $MYPATH/conf/includes/legos.conf.sh
|
||||||
|
|
||||||
# Importe les paramètres pour Debian et Ubuntu
|
|
||||||
. $MYPATH/conf/includes/debian.conf.sh
|
|
||||||
|
|
||||||
# Importe la sélection de paquets par défaut
|
# Importe la sélection de paquets par défaut
|
||||||
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
# Importe les paramètres spécifiques LEGOS
|
# Importe les paramètres spécifiques LEGOS
|
||||||
. $MYPATH/conf/includes/legos-bas.conf.sh
|
. $MYPATH/conf/includes/legos-bas.conf.sh
|
||||||
|
|
||||||
# Importe les paramètres pour Debian et Ubuntu
|
|
||||||
. $MYPATH/conf/includes/debian.conf.sh
|
|
||||||
|
|
||||||
# Importe la sélection de paquets par défaut
|
# Importe la sélection de paquets par défaut
|
||||||
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
||||||
|
|
||||||
|
|||||||
53
doc/dev.md
53
doc/dev.md
@@ -1,25 +1,37 @@
|
|||||||
# init.sh developer's reference
|
# init.sh developer's reference
|
||||||
|
|
||||||
## Table of content
|
## Table of content
|
||||||
* [1. Getting started](#1-getting-started)
|
- [init.sh developer's reference](#initsh-developers-reference)
|
||||||
* [2. The aaa_error.sh file](#2-the-aaa_errorsh-file)
|
- [1. Getting started](#1-getting-started)
|
||||||
+ [2.1. Functions](#21-functions)
|
- [2. The aaa_error.sh file](#2-the-aaa_errorsh-file)
|
||||||
|
- [2.1. Functions](#21-functions)
|
||||||
- [2.1.1. check_root](#211-check_root)
|
- [2.1.1. check_root](#211-check_root)
|
||||||
- [2.1.2. die [--force] \<exitcode\>](#212-die---force-exitcode)
|
- [2.1.2. die [--force] \<exitcode\>](#212-die---force-exitcode)
|
||||||
- [2.1.3. noerror [--noout] \<command\>](#213-noerror---noout-command)
|
- [2.1.3. noerror [--noout] \<command\>](#213-noerror---noout-command)
|
||||||
+ [2.2. Other functionalities](#22-other-functionalities)
|
- [2.2. Other functionalities](#22-other-functionalities)
|
||||||
* [3. The display.sh file](#3-the-displaysh-file)
|
- [3. The display.sh file](#3-the-displaysh-file)
|
||||||
+ [3.1. Functions](#31-functions)
|
- [3.1. Functions](#31-functions)
|
||||||
- [3.1.1. prnt [I|W|E|m] \<message\>](#311-prnt-iwem-message)
|
- [3.1.1. prnt [I|W|E|m] \<message\>](#311-prnt-iwem-message)
|
||||||
+ [3.2. Other functionalities](#32-other-functionalities)
|
- [3.2. Other functionalities](#32-other-functionalities)
|
||||||
* [4. The filefct.sh file](#4-the-filefctsh-file)
|
- [4. The filefct.sh file](#4-the-filefctsh-file)
|
||||||
+ [4.1. Functions](#41-functions)
|
- [4.1. Functions](#41-functions)
|
||||||
- [4.1.1. stdtime](#411-stdtime)
|
- [4.1.1. stdtime](#411-stdtime)
|
||||||
- [4.1.2. backupdist \<list_of_files_or_dirs\>](#412-backupdist-list_of_files_or_dirs)
|
- [4.1.2. backupdist \<list_of_files_or_dirs\>](#412-backupdist-list_of_files_or_dirs)
|
||||||
- [4.1.3. installfile \<sources\> \<destination\>](#413-installfile-sources-destination)
|
- [4.1.3. installfile \<sources\> \<destination\>](#413-installfile-sources-destination)
|
||||||
+ [4.2. Other functionalities](#42-other-functionalities)
|
- [4.2. Other functionnalities](#42-other-functionnalities)
|
||||||
* [5. The pkgman.sh file](#5-the-pkgmansh-file)
|
- [5. The pkgman.sh file](#5-the-pkgmansh-file)
|
||||||
|
- [5.1. Global dependencies](#51-global-dependencies)
|
||||||
|
- [5.2. Functions](#52-functions)
|
||||||
|
- [5.2.1. pkgupdt](#521-pkgupdt)
|
||||||
|
- [5.2.2. pkginst \<package_list\>](#522-pkginst-package_list)
|
||||||
|
- [5.2.3. pkgupgd](#523-pkgupgd)
|
||||||
|
- [5.2.4. pkgrem \<package_list\>](#524-pkgrem-package_list)
|
||||||
|
- [5.2.3. pkgupgd](#523-pkgupgd)
|
||||||
|
- [5.3. Other functionnalities](#53-other-functionnalities)
|
||||||
|
- [6. The services.sh files](#6-the-servicessh-files)
|
||||||
|
- [6.1. Global dependencies](#61-global-dependencies)
|
||||||
|
- [6.2. Functions](#62-functions)
|
||||||
|
- [6.2.1. exec_serv \<service\> \<command\>](#621-exec_serv-service-command)
|
||||||
|
|
||||||
## 1. Getting started
|
## 1. Getting started
|
||||||
This is a developer's reference. It's not intended to be a manual, but a
|
This is a developer's reference. It's not intended to be a manual, but a
|
||||||
@@ -98,12 +110,14 @@ color codes:
|
|||||||
- Standard codes depending on your environment: DEFAULTFG,
|
- Standard codes depending on your environment: DEFAULTFG,
|
||||||
DEFAULTBG, DEFAULTCOL=*${DEFAULTBG}${DEFAULTFG}*
|
DEFAULTBG, DEFAULTCOL=*${DEFAULTBG}${DEFAULTFG}*
|
||||||
- Regular colors: Black, Red, Green, Yellow, Blue, Purple, Cyan, White
|
- Regular colors: Black, Red, Green, Yellow, Blue, Purple, Cyan, White
|
||||||
- Bold: BBlack, BRed, BGreen, BYellow, BBlue, BPurple, BCyan, BWhite
|
- Bold (only available in graphical console or some non standard console
|
||||||
|
fonts): BBlack, BRed, BGreen, BYellow, BBlue, BPurple, BCyan, BWhite
|
||||||
- Underline: UBlack, URed, UGreen, UYellow, UBlue, UPurple, UCyan, UWhite
|
- Underline: UBlack, URed, UGreen, UYellow, UBlue, UPurple, UCyan, UWhite
|
||||||
- Background: On_Black, On_Red, On_Green, On_Yellow, On_Blue, On_Purple,
|
- Background: On_Black, On_Red, On_Green, On_Yellow, On_Blue, On_Purple,
|
||||||
On_Cyan, On_White
|
On_Cyan, On_White
|
||||||
- High intensity: IBlack, IRed, IGreen, IYellow, IBlue, IPurple, ICyan, IWhite
|
- High intensity: IBlack, IRed, IGreen, IYellow, IBlue, IPurple, ICyan, IWhite
|
||||||
- Bold high intensity: BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple,
|
- Bold high intensity (only available in graphical console or some non standard
|
||||||
|
console fonts): BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple,
|
||||||
BICyan, BIWhite
|
BICyan, BIWhite
|
||||||
- High intensity backgrounds: On_IBlack, On_IRed, On_IGreen, On_IYellow,
|
- High intensity backgrounds: On_IBlack, On_IRed, On_IGreen, On_IYellow,
|
||||||
On_IBlue, On_IPurple, On_ICyan, On_IWhite
|
On_IBlue, On_IPurple, On_ICyan, On_IWhite
|
||||||
@@ -118,7 +132,8 @@ echo -e "${IRed}${On_IYellow}ATTENTION:${DEFAULTBG} this is a warning!${DEFAULTC
|
|||||||
### 4.1. Functions
|
### 4.1. Functions
|
||||||
#### 4.1.1. stdtime
|
#### 4.1.1. stdtime
|
||||||
Display date and time based on RFC 3339 standard but slightly modified so it can
|
Display date and time based on RFC 3339 standard but slightly modified so it can
|
||||||
be used in filename.
|
be used in filename. Thus spaces are replaced by dash, and comas between hours,
|
||||||
|
minutes and seconds are removed.
|
||||||
|
|
||||||
That function takes no parameters and return its result on standard output.
|
That function takes no parameters and return its result on standard output.
|
||||||
|
|
||||||
@@ -169,7 +184,7 @@ accomplish that function.
|
|||||||
|
|
||||||
That function takes no parameters and any given parameters will be ignored.
|
That function takes no parameters and any given parameters will be ignored.
|
||||||
|
|
||||||
#### 5.2.2. pkginst
|
#### 5.2.2. pkginst \<package_list\>
|
||||||
That function installs using the package manager the packages given in
|
That function installs using the package manager the packages given in
|
||||||
parameters. The list of parameters are all considered as package names.
|
parameters. The list of parameters are all considered as package names.
|
||||||
|
|
||||||
@@ -188,7 +203,7 @@ accomplish that function.
|
|||||||
|
|
||||||
That function takes no parameters and any given parameters will be ignored.
|
That function takes no parameters and any given parameters will be ignored.
|
||||||
|
|
||||||
#### 5.2.4. pkgrem
|
#### 5.2.4. pkgrem \<package_list\>
|
||||||
That function uninstalls using the package manager the packages given in
|
That function uninstalls using the package manager the packages given in
|
||||||
parameters. The list of parameters are all considered as package names.
|
parameters. The list of parameters are all considered as package names.
|
||||||
|
|
||||||
@@ -222,6 +237,7 @@ the originally UpStart "service" program tend to be available on many systems
|
|||||||
and is privileged.
|
and is privileged.
|
||||||
|
|
||||||
### 6.2. Functions
|
### 6.2. Functions
|
||||||
|
<<<<<<< HEAD
|
||||||
#### 6.2.1. exec_serv
|
#### 6.2.1. exec_serv
|
||||||
That function execute the given action to the given service. The service have
|
That function execute the given action to the given service. The service have
|
||||||
to be the first parameter and the action, the second parameter. No more
|
to be the first parameter and the action, the second parameter. No more
|
||||||
@@ -255,4 +271,7 @@ That function relies on the previously documented exec_serv function.
|
|||||||
|
|
||||||
### 6.3. Other functionnalities
|
### 6.3. Other functionnalities
|
||||||
That file don't profide any other things that the previously listed functions.
|
That file don't profide any other things that the previously listed functions.
|
||||||
|
=======
|
||||||
|
#### 6.2.1. exec_serv \<service\> \<command\>
|
||||||
|
>>>>>>> 0ed780d80de8e1be1d0d99d045c8d4b4d27d52ac
|
||||||
|
|
||||||
|
|||||||
19
init.sh
19
init.sh
@@ -36,14 +36,17 @@ export LC_ALL=C
|
|||||||
export LANG=C
|
export LANG=C
|
||||||
|
|
||||||
# Version of init
|
# Version of init
|
||||||
export VERSION="0.99.7"
|
export VERSION="0.99.8"
|
||||||
|
|
||||||
# Store script's path
|
# Store script's path (realpath -s resolve symlinks if init.sh is a symlink)
|
||||||
export MYPATH=$(dirname $0)
|
export MYPATH=$(dirname $(realpath -s $0))
|
||||||
|
|
||||||
# Get hostname
|
# Get hostname
|
||||||
export HOSTNAME=$(hostname)
|
export HOSTNAME=$(hostname)
|
||||||
|
|
||||||
|
# System architecture
|
||||||
|
export SYS_ARCH=$(uname -m)
|
||||||
|
|
||||||
# Load libraries
|
# Load libraries
|
||||||
for lib in $MYPATH/lib/*.sh; do
|
for lib in $MYPATH/lib/*.sh; do
|
||||||
. $lib
|
. $lib
|
||||||
@@ -65,6 +68,9 @@ function_exists prnt || (
|
|||||||
exit 3
|
exit 3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set system dependent vars
|
||||||
|
get_os_version $(read_os_release)
|
||||||
|
|
||||||
# ======================
|
# ======================
|
||||||
# ==== Main Program ====
|
# ==== Main Program ====
|
||||||
# ======================
|
# ======================
|
||||||
@@ -102,9 +108,12 @@ exec > >(tee -a $LOGFILE)
|
|||||||
exec 2> >(tee -a $LOGFILE >&2)
|
exec 2> >(tee -a $LOGFILE >&2)
|
||||||
prnt I "Démarrage d'init version $VERSION."
|
prnt I "Démarrage d'init version $VERSION."
|
||||||
prnt I "Le fichier de log est $LOGFILE."
|
prnt I "Le fichier de log est $LOGFILE."
|
||||||
|
prnt I "Lancé sur $SYS_DIST version $SYS_VER ($SYS_CODE) architecture $SYS_ARCH"
|
||||||
|
|
||||||
# -- Cannot be a function ends here
|
# -- Cannot be a function ends here
|
||||||
|
|
||||||
|
load_autoconf
|
||||||
|
|
||||||
load_configuration
|
load_configuration
|
||||||
|
|
||||||
process_commandline_and_vars
|
process_commandline_and_vars
|
||||||
@@ -127,7 +136,7 @@ done
|
|||||||
|
|
||||||
if [[ $RUN_SHELL == true ]]; then
|
if [[ $RUN_SHELL == true ]]; then
|
||||||
prnt I "Lancement d'un shell intéractif..."
|
prnt I "Lancement d'un shell intéractif..."
|
||||||
bash -i --rcfile $MYPATH/bash.rc
|
bash --rcfile $MYPATH/bash.rc -i
|
||||||
prnt I "Sortie du script après exécution du shell."
|
prnt I "Sortie du script après exécution du shell."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -185,3 +194,5 @@ fi
|
|||||||
|
|
||||||
prnt I "That's all folks !"
|
prnt I "That's all folks !"
|
||||||
rm -f $STAGEFILE
|
rm -f $STAGEFILE
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -93,23 +93,23 @@ export On_IWhite='\e[0;107m'
|
|||||||
prnt() {
|
prnt() {
|
||||||
case $1 in
|
case $1 in
|
||||||
"I")
|
"I")
|
||||||
HEADS="[ ${IGreen}info${DEFAULTFG} ]"
|
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||||
shift ##
|
shift ##
|
||||||
;;
|
;;
|
||||||
"W")
|
"W")
|
||||||
HEADS="[${IYellow}Attention${DEFAULTFG}]"
|
local heads="[${IYellow}Attention${DEFAULTFG}]"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
"E")
|
"E")
|
||||||
HEADS="[ ${IRed}ERREUR${DEFAULTFG} ]"
|
local heads="[ ${IRed}ERREUR${DEFAULTFG} ]"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
"m")
|
"m")
|
||||||
HEADS=" "
|
local heads=" "
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
echo -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${HEADS} $@"
|
echo -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${heads} $@"
|
||||||
}
|
}
|
||||||
export -f prnt
|
export -f prnt
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ backupdist()
|
|||||||
|
|
||||||
for file in $@; do
|
for file in $@; do
|
||||||
local tmstmp=$(stdtime)
|
local tmstmp=$(stdtime)
|
||||||
if [[ -f ${file} ]]; then
|
if [[ - L ${file} ]]; then
|
||||||
|
# With symbolik links we call again backupdist to treat target
|
||||||
|
backupdist $(readlink -f ${file})
|
||||||
|
elif [[ -f ${file} ]]; then
|
||||||
prnt I "Création d'une sauvegarde de ${file} du $tmstmp..."
|
prnt I "Création d'une sauvegarde de ${file} du $tmstmp..."
|
||||||
cp -av $file ${file}.dist.${tmstmp}
|
cp -av $file ${file}.dist.${tmstmp}
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
@@ -80,12 +83,12 @@ installfile()
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Empty for just to obtain the target which is the last element of the list
|
# Empty to just obtain the target which is the last element of the list
|
||||||
for i in $filelist; do
|
for i in $filelist; do
|
||||||
:
|
:
|
||||||
done
|
done
|
||||||
if [[ ! $i == /* ]]; then
|
if [[ ! $i == /* ]]; then
|
||||||
prnt E "installfile(): Target must be on the root filesystem and fuul path must be provided."
|
prnt E "installfile(): Target must be on the root filesystem and full path must be provided."
|
||||||
die 13
|
die 13
|
||||||
fi
|
fi
|
||||||
if [[ -d $(dirname $i) ]]; then
|
if [[ -d $(dirname $i) ]]; then
|
||||||
@@ -105,4 +108,30 @@ installfile()
|
|||||||
}
|
}
|
||||||
export -f installfile
|
export -f installfile
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# determine if a directory is empty
|
||||||
|
isdirempty()
|
||||||
|
{
|
||||||
|
dir=$1
|
||||||
|
|
||||||
|
if [[ ! -d $dir ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
nbfiles=$(ls -a1 $dir | egrep -v '^.$|^..$' | wc -l)
|
||||||
|
if [[ $nbfiles -eq 0 ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# patch a file replacing all @var@ by the corresponding value in environment
|
||||||
|
patchfile()
|
||||||
|
{
|
||||||
|
: # todo
|
||||||
|
}
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
56
lib/version.sh
Normal file
56
lib/version.sh
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Version determination function
|
||||||
|
# This file is part of the init.sh project
|
||||||
|
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# This file is distributed under 3-clause BSD license.
|
||||||
|
# The complete license agreement can be obtained at:
|
||||||
|
# https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Return on stdout $distro $version $codename
|
||||||
|
read_os_release()
|
||||||
|
{
|
||||||
|
if [[ ! -f /etc/os-release ]]; then
|
||||||
|
prnt E "Your distribution doesn't have the needed os-release file."
|
||||||
|
die 8 --force
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create a sub-shell to avoid polluting the environnement
|
||||||
|
(
|
||||||
|
# Iniitalise version codename in case the var don't exists
|
||||||
|
VERSION_CODENAME="NULL"
|
||||||
|
|
||||||
|
# Import the file in the environment
|
||||||
|
source /etc/os-release
|
||||||
|
|
||||||
|
if [[ -z $ID || -z $VERSION_ID ]]; then
|
||||||
|
prnt E "Your /etc/os-release file mises some vital information."
|
||||||
|
die --force 8
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Return values on standard stdout
|
||||||
|
echo ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,}
|
||||||
|
#prnt I "OS is: ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export read_os_release
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Create system related variables
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
get_os_version()
|
||||||
|
{
|
||||||
|
if [[ $# -ne 3 ]]; then
|
||||||
|
prnt E "get_os_version(): incorect number of parameters ($@)."
|
||||||
|
die 7 --force
|
||||||
|
fi
|
||||||
|
|
||||||
|
export SYS_DIST=$1
|
||||||
|
export SYS_VER=$2
|
||||||
|
if [[ $3 != "null" ]]; then
|
||||||
|
export SYS_CODE=$3
|
||||||
|
fi
|
||||||
|
}
|
||||||
@@ -115,6 +115,45 @@ read_commandline()
|
|||||||
export -f read_commandline
|
export -f read_commandline
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Automatically load system specific configuration if file exist in the
|
||||||
|
# following order:
|
||||||
|
# 1) auto/arch.conf.sh
|
||||||
|
# 2) auto/distro.conf.sh
|
||||||
|
# 3) auto/distro-arch.conf.sh
|
||||||
|
# 4) auto/distro-version.conf.sh
|
||||||
|
# 5) auto/distro-codename.conf.sh (if sys_code defined)
|
||||||
|
# 6) auto/distro-version-arch.conf.sh
|
||||||
|
# 7) auto/distro-codename-arch.conf.sh (if sys_code defined)
|
||||||
|
load_autoconf()
|
||||||
|
{
|
||||||
|
local prefix="$MYPATH/conf/auto"
|
||||||
|
|
||||||
|
if [[ -e $prefix/$SYS_ARCH.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_ARCH.conf.sh
|
||||||
|
fi
|
||||||
|
if [[ -e $prefix/$SYS_DIST.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_DIST.conf.sh
|
||||||
|
fi
|
||||||
|
if [[ -e $prefix/$SYS_DIST-$SYS_ARCH.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_DIST-$SYS_ARCH.conf.sh
|
||||||
|
fi
|
||||||
|
if [[ -e $prefix/$SYS_DIST-$SYS_VER.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_DIST-$SYS_VER.conf.sh
|
||||||
|
fi
|
||||||
|
if [[ -n $SYS_CODE && -e $prefix/$SYS_DIST-$SYS_CODE.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_DIST-$SYS_CODE.conf.sh
|
||||||
|
fi
|
||||||
|
if [[ -e $prefix/$SYS_DIST-$SYS_VER-$SYS_ARCH.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_DIST-$SYS_VER-$SYS_ARCH.conf.sh
|
||||||
|
fi
|
||||||
|
if [[ -n $SYS_CODE && -e $prefix/$SYS_DIST-$SYS_CODE-$SYS_ARCH.conf.sh ]]; then
|
||||||
|
. $prefix/$SYS_DIST-$SYS_CODE-$SYS_ARCH.conf.sh
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f load_autoconf
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Load configuration with the following priorities:
|
# Load configuration with the following priorities:
|
||||||
# 1) Those given on command line, if any
|
# 1) Those given on command line, if any
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
# * PROXYAPTPORT: Working port for APT proxy
|
# * PROXYAPTPORT: Working port for APT proxy
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
export VER_upgrade_dist="0.0.10"
|
export VER_upgrade_dist="0.0.11"
|
||||||
|
|
||||||
# The following var must stay empty
|
# The following var must stay empty
|
||||||
export DEP_upgrade_dist=""
|
export DEP_upgrade_dist=""
|
||||||
@@ -40,9 +40,7 @@ upgrade_dist()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Remplace source.list from dist with ours (be smarter)
|
# Remplace source.list from dist with ours (be smarter)
|
||||||
if [[ -n $APT_LIST_FILE ]]; then
|
installfile "${SYS_DIST}_${SYS_VER}.list" /etc/apt/sources.list
|
||||||
installfile $APT_LIST_FILE /etc/apt/sources.list
|
|
||||||
fi
|
|
||||||
|
|
||||||
prnt I "Mise à jour de la liste des paquets..."
|
prnt I "Mise à jour de la liste des paquets..."
|
||||||
pkgupdt
|
pkgupdt
|
||||||
|
|||||||
Reference in New Issue
Block a user