osuboot/osuboot.sh
2024-11-29 14:12:47 +01:00

124 lines
4 KiB
Bash
Executable file

#!/usr/bin/env bash
# OSU!BOOT SOURCE FILE
# Copyright (c) 2024 The osu!boot Authors
# Licensed under the GNU Affero General Public License v3
#
# 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, either version 3 of the
# License, or (at your option) any later version.
#
# 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
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Process environment variables
# COLORLESS
if [ -z "${OSUBOOT_COLORLESS}" ]; then
COLOR_SPECIAL="\e[0;35m"
COLOR_DEFAULT="\e[0;37m"
COLOR_SUCCESS="\e[0;32m"
COLOR_ERROR="\e[0;31m"
COLOR_OTHER="\e[0;33m"
RESET="\e[0m"
fi
# MAX_CACHE_TIME
if [ -z "${OSUBOOT_MAX_CACHE_TIME}" ]; then
OSUBOOT_MAX_CACHE_TIME=1
elif [[ ! ${OSUBOOT_MAX_CACHE_TIME} == ?(-)+([0-9]) ]]; then
echo "Initialization error: \$OSUBOOT_MAX_CACHE_TIME is not a valid integer"
exit 1
elif [ "${OSUBOOT_MAX_CACHE_TIME}" -lt "1" ]; then
echo "Initialization error: \$OSUBOOT_MAX_CACHE_TIME must be at least 1"
exit 1
fi
# DOWNLOAD_URL
[[ -z "${OSUBOOT_DOWNLOAD_URL}" ]] && OSUBOOT_DOWNLOAD_URL="https://github.com/ppy/osu/releases/latest/download/osu.AppImage"
# Display startup messages
echo -en "${COLOR_SPECIAL}"
echo " _ _ _ "
echo " ___ ___ _ _| | |__ ___ ___ | |_"
echo " / _ \/ __| | | | | '_ \ / _ \ / _ \| __|"
echo "| (_) \__ \ |_| |_| |_) | (_) | (_) | |"
echo " \___/|___/\__,_(_)_.__/ \___/ \___/ \__|"
echo ""
echo "osu!boot is licensed under the GNU AGPL v3."
echo "Copyright (c) 2024 The osu!boot Authors"
echo ""
echo "You can find the source at:"
echo "https://git.staropensource.de/JeremyStarTM/osuboot"
echo ""
echo "Thank you for using osu!boot to launch your favorite rythm game!"
echo ""
if [ -n "${OSUBOOT_IS_NICE}" ]; then
echo -e "${COLOR_SUCCESS}Thank you, you too :3"
exit 69
fi
# Check for dependencies
echo -en "${COLOR_DEFAULT}:: Checking for dependencies"
if [ -z "${OSUBOOT_SKIP_CHECKING_DEPS}" ]; then
# wget
if ! which "wget" &> /dev/null; then
echo -e ", ${COLOR_ERROR}wget is not installed${RESET}"
exit 1
fi
# FUSE 2
# It's really embarassing that AppImages still use legacy FUSE 2
if [ ! -f "/usr/lib/libfuse.so.2" ]; then
echo -e ", ${COLOR_ERROR}FUSE 2 is not installed${RESET}"
exit 1
fi
echo -e ", ${COLOR_SUCCESS}installed"
else
echo -e ", ${COLOR_OTHER}skipped"
fi
# Check for internet connectivity
echo -en "${COLOR_DEFAULT}:: Checking internet connectivity"
if [ -z "${OSUBOOT_SKIP_CHECKING_NET}" ]; then
# IPv4
if ! ping 1.1.1.1 -c 1 &> /dev/null; then
echo -e ", ${COLOR_ERROR}offline${RESET}"
exit 1
fi
# DNS
ping one.one.one.one -c 1 &> /dev/null
if ! ping one.one.one.one -c 1 &> /dev/null; then
echo -e ", ${COLOR_ERROR}DNS unreachable${RESET}"
exit 1
fi
echo -e ", ${COLOR_SUCCESS}online"
else
echo -e ", ${COLOR_OTHER}skipped"
fi
# Download osu!lazer
echo -en "${COLOR_DEFAULT}:: Downloading osu!lazer"
if [ -z "${OSUBOOT_DRYRUN}" ]; then
if [ ! -f "$HOME/.cache/osu.AppImage" ] || [ -n "$(find "$HOME/.cache/osu.AppImage" -ctime "+${OSUBOOT_MAX_CACHE_TIME}" 2>/dev/null)" ]; then
echo -e "${RESET}"
wget --quiet --show-progress -O "$HOME/.cache/osu.AppImage.tmp" "${OSUBOOT_DOWNLOAD_URL}"
mv "${HOME}/.cache/osu.AppImage.tmp" "${HOME}/.cache/osu.AppImage"
chmod +x "${HOME}/.cache/osu.AppImage"
else
echo -e ", ${COLOR_OTHER}skipped (cached)"
fi
else
echo -e ", ${COLOR_OTHER}skipped (dry-run)"
fi
# Launch game
echo -en "${COLOR_DEFAULT}:: Launching"
if [ -z "${OSUBOOT_DRYRUN}" ]; then
echo -e "${RESET}"
exec env OSU_EXTERNAL_UPDATE_PROVIDER=1 "${HOME}/.cache/osu.AppImage"
else
echo -e ", ${COLOR_OTHER}skipped (dry-run)"
fi