monithor/generate.sh

90 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
BinNeed="dpkg-deb realpath"
Wai=$(dirname $(realpath $0))
usage () {
echo "$0
permet de générer les versions de monithor server et client en paquet debian"
exit $1
}
GetOut () {
[[ $1 == "pkg" ]] && echo "Le paquet $2 est nécessaire" && usage 1
}
CheckDep() {
for CheckBinNeed in ${BinNeed}
do
TestCheckBinNeed=$(which $CheckBinNeed)
[[ -z $TestCheckBinNeed ]] && GetOut pkg $CheckBinNeed
done
}
GitVersion() {
LastTag=$(git tag | sed "s/^V//g" | cut -d"-" -f1 | sort -n -k2 -t. | tail -n1)
NewTag=${LastTag}-rebuild
}
CpArchName() {
cp -Rf monithor-${1} /tmp/monithor-${1}_${2}_all
}
SedControl() {
sed -i "/^Version/s/:.*/: ${2}/g" /tmp/monithor-${1}_${2}_all/DEBIAN/control
}
BuildDeb(){
echo -n "Gen monithor-${1} [$2] : "
cd /tmp/ &> /dev/null
Dist=$(lsb_release -a 2> /dev/null | grep Distributor |awk '{print $NF}' |tr '[:upper:]' '[:lower:]')
[[ $Dist == "ubuntu" ]] && Compress=' -Z gzip -S fixed '
dpkg-deb ${Compress} --build --root-owner-group monithor-${1}_${2}_all &> /dev/null
[[ "$?" -eq "0" ]] && echo "OK" || echo "FAILED"
}
CleanTemp() {
mkdir $Wai/build &> /dev/null
mv monithor-*deb $Wai/build
rm -Rf monithor-*
}
ManPage() {
if [[ $2 == "create" ]]
then
pandoc -s -t man ${Wai}/doc/monithor-${1}.md -o ${Wai}/doc/monithor-${1}.1
[[ -f ${Wai}/doc/monithor-${1}.1.gz ]] && rm -f ${Wai}/doc/monithor-${1}.1.gz
gzip ${Wai}/doc/monithor-${1}.1
cp ${Wai}/doc/monithor-${1}.1.gz ${Wai}/monithor-${1}/usr/local/man/fr/man1/
fi
if [[ $2 == "delete" ]]
then
rm ${Wai}/monithor-${1}/usr/local/man/fr/man1/*
rm ${Wai}/doc/monithor-${1}.1.gz
fi
}
[[ ! -z $1 ]] && usage
CheckDep
GitVersion
CpArchName server $NewTag
CpArchName client $NewTag
SedControl server $NewTag
SedControl client $NewTag
ManPage client create
ManPage server create
BuildDeb client $NewTag
BuildDeb server $NewTag
#ManPage client delete
#ManPage server delete
CleanTemp