FOSS-VG/scripts/lib.sh

79 lines
2.1 KiB
Bash
Raw Permalink Normal View History

#!/bin/echo You are not supposed to run this file.
# Copyright 2022, FOSS-VG Developers and Contributers
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# version 3 along with this program.
# If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
if [ "$(tr '[:upper:]' '[:lower:]' <<< $SINGLE)" = "yes" ]; then
echo "Single-threaded mode enabled."
WAIT_ANYWAY="wait"
else
WAIT_ANYWAY=""
fi
if [ -z "$CXX" ]; then
CXX="c++"
fi
if [ -z "$CXXFLAGS" ]; then
CXXFLAGS="-std=c++20 -Wall -Wextra"
fi
CXX_WITH_FLAGS="$CXX $CXXFLAGS"
# automatically find and use an appropriate sha256 sum command
# currently supports sha256sum and NetBSD's sha256
if command -v sha256sum > /dev/null; then
function check_sha256 {
FILE="$1"
CHECKSUM="$2"
sha256sum --check <<< "$CHECKSUM *$FILE" >/dev/null 2>&1
return $?
}
else
if command -v sha256 > /dev/null; then
function check_sha256 {
FILE="$1"
CHECKSUM="$2"
2022-07-30 21:14:23 +02:00
sha256 -c <<< "SHA256 ($FILE) = $CHECKSUM" >/dev/null 2>&1
return $?
}
else
echo "Could not find sha256sum or sha256."
exit 1
fi
fi
# This function exists to make the output more sensible on platforms where
# `rm -v` only prints the names of the removed things instead of a more
# comprehensible message like "removing NAME".
function remove {
echo "Removing $1..."
if [ -d "$1" ]; then
rm -rv "$1"
else
rm -v "$1"
fi
}
# some platforms dont support `mkdir -v`
function create_directory {
echo "Creating directory: $1"
mkdir -p "$1"
}
# `mkfile -v` if you will
function create_file {
echo "Creating file: $1"
touch "$1"
}