LogDoctor/build_install.sh

144 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# Store the actual path
2022-12-01 18:30:55 +01:00
current_path=$(pwd)
# Get the path of LogDoctor-git's folder and move in
docdir="$(dirname $(realpath $0))"
cd "$docdir"
# Check cmake availability
if [[ $(which cmake) =~ ^/ ]]
2022-11-15 21:36:16 +01:00
then
$()
else
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) Cmake is not installed"
2022-11-15 21:36:16 +01:00
exit
fi
# Check the existence of a previous executable file
if [ -e /usr/bin/logdoctor ]
2022-11-15 21:36:16 +01:00
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 11)Warning:$(tput sgr0) a previous installation exists, please run the $(tput bold)update$(tput sgr0) script instead"
exit
2022-11-15 21:36:16 +01:00
fi
# Start the compilation process
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Building$(tput sgr0)"
# Make a build folder
2022-11-16 17:04:11 +01:00
if [ -e build ]
2022-11-15 21:36:16 +01:00
then
rm -r build
2022-12-01 18:30:55 +01:00
if [[ "$?" != "0" ]]
then
echo "$(tput setaf 1)Error:$(tput sgr0) failed to remove existing build directory"
exit
fi
fi
mkdir build
if [[ "$?" != "0" ]]
then
echo "$(tput setaf 1)Error:$(tput sgr0) failed to create build directory"
exit
2022-11-15 21:36:16 +01:00
fi
2022-12-01 18:30:55 +01:00
cd build
# Prepare the cmake files
cmake ../logdoctor -DCMAKE_BUILD_TYPE=MinSizeRel
if [[ "$?" != "0" ]]
2022-11-15 21:36:16 +01:00
then
# an error occured during preparation
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to prepare build files"
2022-11-15 21:36:16 +01:00
exit
fi
# Build the project
cmake --build ./ --target all
if [[ "$?" == "0" ]]
2022-11-15 21:36:16 +01:00
then
# compiled succesfully
mv LogDoctor logdoctor
else
# an error occured during compilation
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to compile"
2022-11-15 21:36:16 +01:00
exit
fi
# Compilation finished
wait
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 10)-->$(tput sgr0) Built succesfully"
# Start installing LogDoctor
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Installing$(tput sgr0)"
cd ../installation_stuff/
2022-12-01 18:30:55 +01:00
if [ ! -d ~/.config/LogDoctor ]
2022-11-15 21:36:16 +01:00
then
mkdir -p ~/.config/LogDoctor
if [[ "$?" != "0" ]]
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to create directory: ~/.config/LogDoctor"
exit
fi
2022-11-15 21:36:16 +01:00
fi
2022-12-01 18:30:55 +01:00
chmod 644 ./logdoctor.conf
install -DC ./logdoctor.conf -t ~/.config/LogDoctor
if [[ "$?" != "0" ]]
then
echo "$(tput setaf 1)Error:$(tput sgr0) failed to copy configuration file"
exit
fi
2022-12-01 18:30:55 +01:00
if [ ! -d /usr/share/LogDoctor ]
2022-11-15 21:36:16 +01:00
then
2022-12-01 18:30:55 +01:00
sudo mkdir -p /usr/share/LogDoctor
2022-11-15 21:36:16 +01:00
if [[ "$?" != "0" ]]
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to create directory: /usr/share/LogDoctor"
exit
fi
2022-11-15 21:36:16 +01:00
fi
2022-12-01 18:30:55 +01:00
chmod 644 ./logdocdata/help/*/*
chmod 444 ./logdocdata/licenses/*
sudo rsync -r --delete ./logdocdata /usr/share/LogDoctor
2022-11-15 21:36:16 +01:00
if [[ "$?" != "0" ]]
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to copy LogDoctor's data"
2022-11-15 21:36:16 +01:00
exit
fi
2022-12-03 17:29:41 +01:00
chmod 644 ./LogDoctor.svg
sudo install -DC ./LogDoctor.svg -t /usr/share/LogDoctor
if [[ "$?" != "0" ]]
2022-11-15 21:36:16 +01:00
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to copy LogDoctor's icon"
2022-11-15 21:36:16 +01:00
exit
fi
2022-12-01 18:30:55 +01:00
chmod 644 ./LogDoctor.desktop
sudo install -DC ./LogDoctor.desktop -t /usr/share/applications
if [[ "$?" != "0" ]]
2022-11-15 21:36:16 +01:00
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to create a menu entry"
2022-11-15 21:36:16 +01:00
exit
fi
cd ../build
chmod 755 ./logdoctor
2022-12-01 18:30:55 +01:00
sudo install -DC ./logdoctor -t /usr/bin
2022-11-15 21:36:16 +01:00
if [[ "$?" != "0" ]]
then
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 1)Error:$(tput sgr0) failed to copy the executable"
2022-11-15 21:36:16 +01:00
exit
fi
# Installation finished
2022-12-01 18:30:55 +01:00
echo "$(tput setaf 10)-->$(tput sgr0) $(tput bold)Installed succesfully$(tput sgr0)"
cd "$current_path"