moved code to new libs, conf moved to subfolder, conf splitted into unit and specific files
This commit is contained in:
23
conf/init.conf.sh
Normal file
23
conf/init.conf.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
. conf/legos.conf.sh
|
||||||
|
|
||||||
|
# Utilisateur de la machine
|
||||||
|
export MAINUSER="levasseu"
|
||||||
|
|
||||||
|
# Booléen indiquant une ou plusieurs futures VM
|
||||||
|
export WITH_VM=true
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Niveau ZFS : mirror (RAID1), raidz1 (RAID5), raidz2 (RAID6)
|
||||||
|
# Laisser vide pour RAID0
|
||||||
|
export CALCLEVEL=""
|
||||||
|
|
||||||
|
# Liste de lecteurs à utiliser (voir dans /dev/disk/by-id)
|
||||||
|
# Un seul tolléré pour Ext4 et XFS, plusieurs séparés par des espaces pour ZFS
|
||||||
|
export CALCDRV="/dev/disk/by-id/xxxxx"
|
||||||
|
|
||||||
|
# Doit on forcer l'effacement du disque ?
|
||||||
|
export FORCEBLANK="no"
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export MODULE_LIST="upgrade_dist conf_disk"
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
# Domaine LEGOS
|
# Domaine LEGOS
|
||||||
export MAINDOM="legos.obs-mip.fr"
|
export MAINDOM="legos.obs-mip.fr"
|
||||||
|
|
||||||
# Utilisateur de la machine
|
|
||||||
export MAINUSER="levasseu"
|
|
||||||
|
|
||||||
# Proxy LEGOS
|
# Proxy LEGOS
|
||||||
export PROXYSRV="proxy.legos.obs-mip.fr"
|
export PROXYSRV="proxy.legos.obs-mip.fr"
|
||||||
export PROXYPORT="3128"
|
export PROXYPORT="3128"
|
||||||
@@ -23,25 +20,5 @@ export INSTLIST_BASE="bc curl dc debconf-utils deborphan dos2unix dump \
|
|||||||
pbzip2 perl-doc pigz plzip postfix pv qemu-guest-agent resolvconf rsync \
|
pbzip2 perl-doc pigz plzip postfix pv qemu-guest-agent resolvconf rsync \
|
||||||
screen snmpd strace tcpdump tmux traceroute unrar unzip whois xinetd zip"
|
screen snmpd strace tcpdump tmux traceroute unrar unzip whois xinetd zip"
|
||||||
|
|
||||||
# Booléen indiquant une ou plusieurs futures VM
|
|
||||||
export WITH_VM=true
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Configuration du disque de calcul : zfs, ext4 et xfs accepté
|
# Configuration du disque de calcul : zfs, ext4 et xfs accepté
|
||||||
export CALCTYPE="zfs"
|
export CALCTYPE="zfs"
|
||||||
|
|
||||||
|
|
||||||
# Niveau : mirror (RAID1), raidz1 (RAID5), raidz2 (RAID6)
|
|
||||||
# Laisser vide pour RAID0 valable seulement pour ZFS
|
|
||||||
export CALCLEVEL=""
|
|
||||||
|
|
||||||
# Liste de lecteurs à utiliser (voir dans /dev/disk/by-id)
|
|
||||||
# Un seul tolléré pour Ext4 et XFS, plusieurs séparés par des espaces pour ZFS
|
|
||||||
export CALCDRV="/dev/disk/by-id/xxxxx"
|
|
||||||
|
|
||||||
# Doit on forcer l'effacement du disque ?
|
|
||||||
export FORCEBLANK="no"
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export MODULE_LIST="upgrade_dist conf_disk"
|
|
||||||
169
init.sh
169
init.sh
@@ -1,5 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Load libraries
|
||||||
|
. lib/display.sh
|
||||||
|
. lib/filefct.sh
|
||||||
|
|
||||||
# Check gestparc native directory
|
# Check gestparc native directory
|
||||||
#export REPO="/share/services/gestparc"
|
#export REPO="/share/services/gestparc"
|
||||||
|
|
||||||
@@ -8,169 +12,7 @@ export HOSTNAME=$(hostname)
|
|||||||
export DATEFORMAT=${DATEFORMAT:-"+%Y/%m/%d-%H:%M:%S-%N"}
|
export DATEFORMAT=${DATEFORMAT:-"+%Y/%m/%d-%H:%M:%S-%N"}
|
||||||
export LOGFILE=${LOGFILE:-"/var/log/$(uname -n)-$(date +%Y%m%d-%H%M).log"}
|
export LOGFILE=${LOGFILE:-"/var/log/$(uname -n)-$(date +%Y%m%d-%H%M).log"}
|
||||||
|
|
||||||
# Define colors codes used while displaying
|
|
||||||
colorcodes() {
|
|
||||||
DEFAULTFG="\e[0;39m"
|
|
||||||
DEFAULTBG="\e[0;49m"
|
|
||||||
DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
|
||||||
# Regular Colors
|
|
||||||
Black='\e[0;30m'
|
|
||||||
Red='\e[0;31m'
|
|
||||||
Green='\e[0;32m'
|
|
||||||
Yellow='\e[0;33m'
|
|
||||||
Blue='\e[0;34m'
|
|
||||||
Purple='\e[0;35m'
|
|
||||||
Cyan='\e[0;36m'
|
|
||||||
White='\e[0;37m'
|
|
||||||
# Bold
|
|
||||||
BBlack='\e[1;30m'
|
|
||||||
BRed='\e[1;31m'
|
|
||||||
BGreen='\e[1;32m'
|
|
||||||
BYellow='\e[1;33m'
|
|
||||||
BBlue='\e[1;34m'
|
|
||||||
BPurple='\e[1;35m'
|
|
||||||
BCyan='\e[1;36m'
|
|
||||||
BWhite='\e[1;37m'
|
|
||||||
# Underline
|
|
||||||
UBlack='\e[4;30m'
|
|
||||||
URed='\e[4;31m'
|
|
||||||
UGreen='\e[4;32m'
|
|
||||||
UYellow='\e[4;33m'
|
|
||||||
UBlue='\e[4;34m'
|
|
||||||
UPurple='\e[4;35m'
|
|
||||||
UCyan='\e[4;36m'
|
|
||||||
UWhite='\e[4;37m'
|
|
||||||
# Background
|
|
||||||
On_Black='\e[40m'
|
|
||||||
On_Red='\e[41m'
|
|
||||||
On_Green='\e[42m'
|
|
||||||
On_Yellow='\e[43m'
|
|
||||||
On_Blue='\e[44m'
|
|
||||||
On_Purple='\e[45m'
|
|
||||||
On_Cyan='\e[46m'
|
|
||||||
On_White='\e[47m'
|
|
||||||
# High Intensity
|
|
||||||
IBlack='\e[0;90m'
|
|
||||||
IRed='\e[0;91m'
|
|
||||||
IGreen='\e[0;92m'
|
|
||||||
IYellow='\e[0;93m'
|
|
||||||
IBlue='\e[0;94m'
|
|
||||||
IPurple='\e[0;95m'
|
|
||||||
ICyan='\e[0;96m'
|
|
||||||
IWhite='\e[0;97m'
|
|
||||||
# Bold High Intensity
|
|
||||||
BIBlack='\e[1;90m'
|
|
||||||
BIRed='\e[1;91m'
|
|
||||||
BIGreen='\e[1;92m'
|
|
||||||
BIYellow='\e[1;93m'
|
|
||||||
BIBlue='\e[1;94m'
|
|
||||||
BIPurple='\e[1;95m'
|
|
||||||
BICyan='\e[1;96m'
|
|
||||||
BIWhite='\e[1;97m'
|
|
||||||
# High Intensity backgrounds
|
|
||||||
On_IBlack='\e[0;100m'
|
|
||||||
On_IRed='\e[0;101m'
|
|
||||||
On_IGreen='\e[0;102m'
|
|
||||||
On_IYellow='\e[0;103m'
|
|
||||||
On_IBlue='\e[0;104m'
|
|
||||||
On_IPurple='\e[0;105m'
|
|
||||||
On_ICyan='\e[0;106m'
|
|
||||||
On_IWhite='\e[0;107m'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Affiche le status avec en-tête coloré et timestamp
|
|
||||||
# (valeur de $1 : I=info, W=warning, E=error, pas d'entête si différent)
|
|
||||||
prnt() {
|
|
||||||
case $1 in
|
|
||||||
"I")
|
|
||||||
HEADS="[ ${IGreen}info${DEFAULTFG} ]"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
"W")
|
|
||||||
HEADS="[ ${IYellow}Attention${DEFAULTFG} ]"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
"E")
|
|
||||||
HEADS="[ ${IRed}ERREUR${DEFAULTFG} ]"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
echo -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${HEADS} $@"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Backup original installation files (or any old files if runned several time on same file)
|
|
||||||
backupdist()
|
|
||||||
{
|
|
||||||
[[ $# -lt 1 ]] && prnt E "backupdist(): Au moins un argument requis." && return 1
|
|
||||||
|
|
||||||
for file in $@; do
|
|
||||||
if [[ -e ${file} ]]; then
|
|
||||||
prnt I "Création d'une copie de sauvegarde de ${file}..."
|
|
||||||
cp -av $file $file.dist.$(date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g')
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install file to the host (specific first then general)
|
|
||||||
installfile()
|
|
||||||
{
|
|
||||||
local filelist=""
|
|
||||||
local i=0
|
|
||||||
|
|
||||||
[[ $# -lt 2 ]] && (
|
|
||||||
prnt E "installfile(): Au moins deux arguments requis."
|
|
||||||
return 1
|
|
||||||
)
|
|
||||||
[[ $(echo $@ | grep "\*\|\?") ]] && (
|
|
||||||
prnt E "installfile(): Les wildcards sont interdits."
|
|
||||||
return 2
|
|
||||||
)
|
|
||||||
|
|
||||||
for arg in $@; do
|
|
||||||
if [[ -f $BASEGPDIR/profile/$HOSTNAME/$arg ]]; then
|
|
||||||
filelist="$filelist $BASEGPDIR/profile/$HOSTNAME/$arg"
|
|
||||||
elif [[ -f $BASEGPDIR/profile/$arg ]]; then
|
|
||||||
filelist="$filelist $BASEGPDIR/profile/$arg"
|
|
||||||
else
|
|
||||||
filelist="$filelist $arg"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
for i in $filelist; do :; done
|
|
||||||
if [[ ! $i==/* ]]; then
|
|
||||||
prnt E "installfile(): Target must be on the root filesystem."
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
prnt I "Création su répertoire $(dirname $i) si nécessaire..."
|
|
||||||
mkdir -pv $(dirname $i)
|
|
||||||
prnt I "Copie des fichiers ${filelist}..."
|
|
||||||
cp -av $filelist
|
|
||||||
}
|
|
||||||
|
|
||||||
# Configuration du disque de calcul
|
|
||||||
conf_zfs()
|
|
||||||
{
|
|
||||||
# On crée les répertoires d'accueil
|
|
||||||
mkdir -pv /srv/ceph
|
|
||||||
mkdir -pv /share
|
|
||||||
|
|
||||||
# Upgrade of fstab file
|
|
||||||
|
|
||||||
# Mount Ceph volumes if required
|
|
||||||
[[ ! $(mount | grep "on /srv/ceph") ]] && mount -v /srv/ceph
|
|
||||||
[[ ! $(mount | grep "on /share") ]] && mount -v /share
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Blacklist some unwanted packages...
|
|
||||||
apt_blacklist()
|
|
||||||
{
|
|
||||||
[[ ! -d /etc/apt/preferences.d ]] && mkdir -pv /etc/apt/preferences.d
|
|
||||||
installfile avoid-apparmor avoid-chafa avoid-resolvconf /etc/apt/preferences.d
|
|
||||||
}
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
#FUNCLIST="$FUNCLIST authnz"
|
|
||||||
#authnz()
|
#authnz()
|
||||||
#{
|
#{
|
||||||
# apt-get install nscd libpam-krb5 libnss-ldap libpam-ldap
|
# apt-get install nscd libpam-krb5 libnss-ldap libpam-ldap
|
||||||
@@ -185,7 +27,6 @@ apt_blacklist()
|
|||||||
#}
|
#}
|
||||||
|
|
||||||
# Users (from Ldap)
|
# Users (from Ldap)
|
||||||
#FUNCLIST="$FUNCLIST add_user"
|
|
||||||
#add_users()
|
#add_users()
|
||||||
#{
|
#{
|
||||||
# backupdist /etc/passwd /etc/shadow /etc/group
|
# backupdist /etc/passwd /etc/shadow /etc/group
|
||||||
@@ -285,7 +126,7 @@ if [[ $EUID -ne 0 ]];
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Chargement de la configuration
|
# Chargement de la configuration
|
||||||
[[ -s init.sh.conf ]] && . init.sh.conf || (
|
[[ -s conf/init.sh.conf ]] && . conf/init.sh.conf || (
|
||||||
prnt E "Impossible de charger la configuration."
|
prnt E "Impossible de charger la configuration."
|
||||||
exit 1
|
exit 1
|
||||||
)
|
)
|
||||||
|
|||||||
89
lib/display.sh
Normal file
89
lib/display.sh
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
# Defines color codes (standard 16 colors display)
|
||||||
|
|
||||||
|
DEFAULTFG="\e[0;39m"
|
||||||
|
DEFAULTBG="\e[0;49m"
|
||||||
|
DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
||||||
|
# Regular Colors
|
||||||
|
Black='\e[0;30m'
|
||||||
|
Red='\e[0;31m'
|
||||||
|
Green='\e[0;32m'
|
||||||
|
Yellow='\e[0;33m'
|
||||||
|
Blue='\e[0;34m'
|
||||||
|
Purple='\e[0;35m'
|
||||||
|
Cyan='\e[0;36m'
|
||||||
|
White='\e[0;37m'
|
||||||
|
# Bold
|
||||||
|
BBlack='\e[1;30m'
|
||||||
|
BRed='\e[1;31m'
|
||||||
|
BGreen='\e[1;32m'
|
||||||
|
BYellow='\e[1;33m'
|
||||||
|
BBlue='\e[1;34m'
|
||||||
|
BPurple='\e[1;35m'
|
||||||
|
BCyan='\e[1;36m'
|
||||||
|
BWhite='\e[1;37m'
|
||||||
|
# Underline
|
||||||
|
UBlack='\e[4;30m'
|
||||||
|
URed='\e[4;31m'
|
||||||
|
UGreen='\e[4;32m'
|
||||||
|
UYellow='\e[4;33m'
|
||||||
|
UBlue='\e[4;34m'
|
||||||
|
UPurple='\e[4;35m'
|
||||||
|
UCyan='\e[4;36m'
|
||||||
|
UWhite='\e[4;37m'
|
||||||
|
# Background
|
||||||
|
On_Black='\e[40m'
|
||||||
|
On_Red='\e[41m'
|
||||||
|
On_Green='\e[42m'
|
||||||
|
On_Yellow='\e[43m'
|
||||||
|
On_Blue='\e[44m'
|
||||||
|
On_Purple='\e[45m'
|
||||||
|
On_Cyan='\e[46m'
|
||||||
|
On_White='\e[47m'
|
||||||
|
# High Intensity
|
||||||
|
IBlack='\e[0;90m'
|
||||||
|
IRed='\e[0;91m'
|
||||||
|
IGreen='\e[0;92m'
|
||||||
|
IYellow='\e[0;93m'
|
||||||
|
IBlue='\e[0;94m'
|
||||||
|
IPurple='\e[0;95m'
|
||||||
|
ICyan='\e[0;96m'
|
||||||
|
IWhite='\e[0;97m'
|
||||||
|
# Bold High Intensity
|
||||||
|
BIBlack='\e[1;90m'
|
||||||
|
BIRed='\e[1;91m'
|
||||||
|
BIGreen='\e[1;92m'
|
||||||
|
BIYellow='\e[1;93m'
|
||||||
|
BIBlue='\e[1;94m'
|
||||||
|
BIPurple='\e[1;95m'
|
||||||
|
BICyan='\e[1;96m'
|
||||||
|
BIWhite='\e[1;97m'
|
||||||
|
# High Intensity backgrounds
|
||||||
|
On_IBlack='\e[0;100m'
|
||||||
|
On_IRed='\e[0;101m'
|
||||||
|
On_IGreen='\e[0;102m'
|
||||||
|
On_IYellow='\e[0;103m'
|
||||||
|
On_IBlue='\e[0;104m'
|
||||||
|
On_IPurple='\e[0;105m'
|
||||||
|
On_ICyan='\e[0;106m'
|
||||||
|
On_IWhite='\e[0;107m'
|
||||||
|
|
||||||
|
# Affiche le status avec en-tête coloré et timestamp
|
||||||
|
# (valeur de $1 : I=info, W=warning, E=error, pas d'entête si différent)
|
||||||
|
prnt() {
|
||||||
|
case $1 in
|
||||||
|
"I")
|
||||||
|
HEADS="[ ${IGreen}info${DEFAULTFG} ]"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"W")
|
||||||
|
HEADS="[ ${IYellow}Attention${DEFAULTFG} ]"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"E")
|
||||||
|
HEADS="[ ${IRed}ERREUR${DEFAULTFG} ]"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${HEADS} $@"
|
||||||
|
}
|
||||||
|
export -f prnt
|
||||||
50
lib/filefct.sh
Normal file
50
lib/filefct.sh
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
# Backup original installation files (or any old files if runned several time on same file)
|
||||||
|
backupdist()
|
||||||
|
{
|
||||||
|
[[ $# -lt 1 ]] && prnt E "backupdist(): Au moins un argument requis." && return 1
|
||||||
|
|
||||||
|
for file in $@; do
|
||||||
|
if [[ -e ${file} ]]; then
|
||||||
|
prnt I "Création d'une copie de sauvegarde de ${file}..."
|
||||||
|
cp -av $file $file.dist.$(date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g')
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
export -f backupdist
|
||||||
|
|
||||||
|
# Install file to the host (specific first then general)
|
||||||
|
installfile()
|
||||||
|
{
|
||||||
|
local filelist=""
|
||||||
|
local i=0
|
||||||
|
|
||||||
|
[[ $# -lt 2 ]] && (
|
||||||
|
prnt E "installfile(): Au moins deux arguments requis."
|
||||||
|
return 1
|
||||||
|
)
|
||||||
|
[[ $(echo $@ | grep "\*\|\?") ]] && (
|
||||||
|
prnt E "installfile(): Les wildcards sont interdits."
|
||||||
|
return 2
|
||||||
|
)
|
||||||
|
|
||||||
|
for arg in $@; do
|
||||||
|
if [[ -f $BASEGPDIR/profile/$HOSTNAME/$arg ]]; then
|
||||||
|
filelist="$filelist $BASEGPDIR/profile/$HOSTNAME/$arg"
|
||||||
|
elif [[ -f $BASEGPDIR/profile/$arg ]]; then
|
||||||
|
filelist="$filelist $BASEGPDIR/profile/$arg"
|
||||||
|
else
|
||||||
|
filelist="$filelist $arg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
for i in $filelist; do :; done
|
||||||
|
if [[ ! $i==/* ]]; then
|
||||||
|
prnt E "installfile(): Target must be on the root filesystem."
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
prnt I "Création su répertoire $(dirname $i) si nécessaire..."
|
||||||
|
mkdir -pv $(dirname $i)
|
||||||
|
prnt I "Copie des fichiers ${filelist}..."
|
||||||
|
cp -av $filelist
|
||||||
|
}
|
||||||
|
export -f installfile
|
||||||
Reference in New Issue
Block a user