FOSS-VG/scripts/setup_project.sh

103 lines
3.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2022-06-27 11:46:13 +02:00
# 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
source scripts/lib.sh
echo -n "Wget or curl? "
if command -v wget >/dev/null 2>&1; then
USE_WGET=yes
echo "wget"
else
if command -v curl >/dev/null 2>&1; then
USE_WGET=no
echo "curl"
else
2022-06-27 13:06:09 +02:00
echo "Found neither wget nor curl. Aborting."
exit 1
fi
fi
function download {
URL="$1"
DESTINATION="$2"
2022-07-20 15:52:04 +02:00
SHA256SUM="$3"
if [ ! -d .download_cache ]; then
echo "Cache directory missing."
create_directory .download_cache
fi
2022-07-20 15:52:04 +02:00
if [ -f ".download_cache/$SHA256SUM" ]; then
if check_sha256 ".download_cache/$SHA256SUM" "$SHA256SUM"; then
2022-07-20 15:52:04 +02:00
echo "Using locally cached file for $DESTINATION"
cp ".download_cache/$SHA256SUM" "$DESTINATION"
return 0
else
echo "Locally cached file for $DESTINATION is corrupted."
rm ".download_cache/$SHA256SUM"
download "$URL" "$DESTINATION" "$SHA256SUM"
return $?
fi
2022-07-06 14:15:40 +02:00
else
2022-07-20 15:52:04 +02:00
echo -n "Downloading $URL to $DESTINATION... "
if [ $USE_WGET = yes ]; then
wget -O ".download_cache/$SHA256SUM" "$URL" >/dev/null 2>&1
else
curl -L "$URL" --output ".download_cache/$SHA256SUM" >/dev/null 2>&1
fi
if check_sha256 ".download_cache/$SHA256SUM" "$SHA256SUM"; then
2022-07-20 15:52:04 +02:00
cp ".download_cache/$SHA256SUM" "$DESTINATION"
echo "done."
return 0
else
echo "error."
echo "Checksum verification failed. Your download is either corrupted or the file has been altered. Removing file."
rm ".download_cache/$SHA256SUM"
return 1
fi
2022-07-06 14:15:40 +02:00
fi
}
scripts/clean.sh
scripts/clean_dependencies.sh
2022-07-12 01:51:23 +02:00
set -e # failures are not acceptable here
create_directory dependencies/tmp
2022-07-06 14:15:40 +02:00
download https://github.com/DuffsDevice/tiny-utf8/archive/refs/tags/v4.4.3.tar.gz dependencies/tmp/tiny-utf8.tar.gz 8e3f61651909c9f3105d3501932a96aa65733127fb6e7cf94cb1b0a2dff42c8f
2022-07-12 01:51:23 +02:00
download https://github.com/fpagliughi/sockpp/archive/refs/tags/v0.7.1.tar.gz dependencies/tmp/sockpp.tar.gz 2e023528bebbd2ac083fc91fbe6d5c4158c3336bedbcff48f594f3b28f53b940
echo -n ">>> Extracting tiny-utf8... "
gzip -d dependencies/tmp/tiny-utf8.tar.gz
tar -xf dependencies/tmp/tiny-utf8.tar -C dependencies
echo "done"
echo -n ">>> Extracting sockpp... "
2022-07-12 01:51:23 +02:00
gzip -d dependencies/tmp/sockpp.tar.gz
tar -xf dependencies/tmp/sockpp.tar -C dependencies
echo "done"
echo ">>> Building sockpp... "
2022-07-12 01:51:23 +02:00
pushd dependencies/sockpp-0.7.1/ >/dev/null 2>&1
cmake -G "MinGW Makefiles" -Bbuild .
cmake --build build
2022-07-12 01:51:23 +02:00
popd >/dev/null 2>&1
echo ">>> Cleaning up..."
remove dependencies/tmp