From 674dbc247377acec07d86a39f49723ea00a70cb5 Mon Sep 17 00:00:00 2001 From: Valentino Orlandi Date: Sun, 11 Jun 2023 16:40:11 +0200 Subject: [PATCH] Added docker build scripts --- installation_stuff/logdoctor.DOCKER | 5 ++ scripts/DOCKER_build_install.sh | 83 ++++++++++++++++++++++++ scripts/DOCKER_build_update.sh | 97 +++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 installation_stuff/logdoctor.DOCKER create mode 100644 scripts/DOCKER_build_install.sh create mode 100644 scripts/DOCKER_build_update.sh diff --git a/installation_stuff/logdoctor.DOCKER b/installation_stuff/logdoctor.DOCKER new file mode 100644 index 00000000..337ba851 --- /dev/null +++ b/installation_stuff/logdoctor.DOCKER @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +xhost + +docker run -e DISPLAY=$DISPLAY --pid=host +xhost - diff --git a/scripts/DOCKER_build_install.sh b/scripts/DOCKER_build_install.sh new file mode 100644 index 00000000..0b296450 --- /dev/null +++ b/scripts/DOCKER_build_install.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# Store the actual path +current_path=$(pwd) + +# Get the path of LogDoctor-git's folder and move in +docdir="$(dirname $(dirname $(realpath $0)))" +cd "$docdir" + +# Check the existence of a previous image +docker images | grep LogDoctor &> /dev/null +if [[ "$?" == "0" ]] +then + echo "$(tput setaf 11)Warning:$(tput sgr0) an image already exists, please run the $(tput bold)update$(tput sgr0) script instead" + exit 0 +fi + +# Check docker availability +which docker &> /dev/null +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) Docker is not installed" + exit 1 +fi + +# Check debian:latest image +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Checking base image$(tput sgr0)" + +# Check the existence of debian:latest image +docker images | grep debian | grep latest &> /dev/null +if [[ "$?" != "0" ]] +then + # Image not found, pull it + docker pull debian:latest + if [[ "$?" != "0" ]] + then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to pull debian:latest" + exit 1 + fi +fi + +# Done checking +wait +echo "$(tput setaf 10)-->$(tput sgr0) Checked succesfully" + +# Start the build process +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Building LogDoctor image$(tput sgr0)" + +# Build the docker image +docker build -t LogDoctor:latest . +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to build the image" + exit 1 +fi + +# Compilation finished +wait +echo "$(tput setaf 10)-->$(tput sgr0) Built succesfully" + +# Start installing LogDoctor +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Installing$(tput sgr0)" +cd installation_stuff + +chmod 644 ./LogDoctor.desktop +sudo install -DC ./LogDoctor.desktop -t /usr/share/applications +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to create a menu entry" + exit 1 +fi + +chmod 755 ./logdoctor.DOCKER +sudo install -DC ./logdoctor.DOCKER /usr/bin/logdoctor +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to copy the executable" + exit 1 +fi + +# Installation finished +echo "$(tput setaf 10)-->$(tput sgr0) $(tput bold)Installed succesfully$(tput sgr0)" +cd "$current_path" diff --git a/scripts/DOCKER_build_update.sh b/scripts/DOCKER_build_update.sh new file mode 100644 index 00000000..1f412f38 --- /dev/null +++ b/scripts/DOCKER_build_update.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# Store the actual path +current_path=$(pwd) + +# Get the path of LogDoctor-git's folder and move in +docdir="$(dirname $(dirname $(realpath $0)))" +cd "$docdir" + +# Check docker availability +which docker &> /dev/null +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) Docker is not installed" + exit 1 +fi + +# Check the existence of a previous image +docker images | grep LogDoctor &> /dev/null +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 11)Warning:$(tput sgr0) no previous image already found, please run the $(tput bold)install$(tput sgr0) script instead" + exit 0 +fi + +# Check debian:latest image +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Checking base image$(tput sgr0)" + +# Check the existence of debian:latest image +docker images | grep debian | grep latest &> /dev/null +if [[ "$?" != "0" ]] +then + # Image not found, pull it + docker pull debian:latest + if [[ "$?" != "0" ]] + then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to pull debian:latest" + exit 1 + fi +fi + +# Done checking +wait +echo "$(tput setaf 10)-->$(tput sgr0) Checked succesfully" + +# Remove the old image +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Removing old LogDoctor image$(tput sgr0)" + +docker image rm LogDoctor:latest +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to remove LogDoctor:latest" + exit 1 +fi + +# Done removing +wait +echo "$(tput setaf 10)-->$(tput sgr0) Removed succesfully" + +# Start the build process +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Building new LogDoctor image$(tput sgr0)" + +# Build the docker image +docker build -t LogDoctor:latest . +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to build the image" + exit 1 +fi + +# Compilation finished +wait +echo "$(tput setaf 10)-->$(tput sgr0) Built succesfully" + +# Start updating LogDoctor +echo "$(tput setaf 12)==>$(tput sgr0) $(tput bold)Updating$(tput sgr0)" +cd installation_stuff + +chmod 644 ./LogDoctor.desktop +sudo install -DC ./LogDoctor.desktop -t /usr/share/applications +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to create a menu entry" + exit 1 +fi + +chmod 755 ./logdoctor.DOCKER +sudo install -DC ./logdoctor.DOCKER /usr/bin/logdoctor +if [[ "$?" != "0" ]] +then + echo "$(tput setaf 1)Error:$(tput sgr0) failed to copy the executable" + exit 1 +fi + +# Update finished +echo "$(tput setaf 10)-->$(tput sgr0) $(tput bold)Updated succesfully$(tput sgr0)" +cd "$current_path"