#!/usr/bin/env bash
##makedesc: Install flameshot (latest)
source "$( dirname $(readlink -e -- "${BASH_SOURCE}"))/../helpers.sh" || exit 255

title

# https://github.com/flameshot-org/flameshot?tab=readme-ov-file#compilation
# sudo apt install -y --autoremove flameshot && \
#     sudo systemctl restart flameshot

dir="$HOME/install"
clone_dir="$dir/flameshot"
mkdir -p "$dir"

sudo apt install -y \
    g++ \
    cmake \
    build-essential \
    qtbase5-dev \
    qttools5-dev-tools \
    libqt5svg5-dev \
    qttools5-dev \
    libqt5dbus5 \
    libqt5network5 \
    libqt5core5a \
    libqt5widgets5 \
    libqt5gui5 \
    libqt5svg5

if [ ! -d "$clone_dir" ]; then
    git clone --depth=1 --single-branch https://github.com/flameshot-org/flameshot.git "$clone_dir"
fi

# Directory where build files will be placed, may be relative
export BUILD_DIR=build

# Directory prefix where flameshot will be installed. If you are just building and don't want to
# install, comment this environment variable.
# This excludes the bin/flameshot part of the install,
# e.g. in /opt/flameshot/bin/flameshot, the CMAKE_INSTALL_PREFIX is /opt/flameshot
# This must be an absolute path. Requires CMAKE 3.29.
export CMAKE_INSTALL_PREFIX=/opt/flameshot

cd "$clone_dir" && \
    git pull && \
    cmake -S . -B "$BUILD_DIR" && \
    cmake --build "$BUILD_DIR"

[ $? = 0 ] && {
    echo
    success "flameshot installed!"
    # /opt/flameshot/flameshot -v
    echo
}
