MoonWorksTemplate/install.sh

119 lines
3.2 KiB
Bash
Raw Normal View History

2021-04-04 21:01:40 +00:00
#!/bin/bash
# Author: Evan Hemsley
# Usage: ./install.sh
# This file is heavily borrowed from Caleb Cornett's template install script.
# Get the directory of this script
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
readlinkf(){ perl -MCwd -e 'print Cwd::abs_path shift' "$1";}
# Checks if git is installed
function checkGit()
{
2022-08-30 05:11:51 +00:00
git --version > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo >&2 "ERROR: Git is not installed. Please install git to download MoonWorks."
exit 1
fi
2021-04-04 21:01:40 +00:00
}
# Pulls MoonWorks from github
function pullMoonWorks()
{
2022-08-30 05:11:51 +00:00
checkGit
cd lib
git submodule add https://gitea.moonside.games/MoonsideGames/MoonWorks.git
cd ..
echo "Updating to the latest release of MoonWorks..."
2021-04-04 21:01:40 +00:00
git submodule update --init --recursive
if [ $? -eq 0 ]; then
echo "Finished updating!"
else
echo >&2 "ERROR: Unable to update."
exit 1
fi
}
# Downloads and extracts prepackaged archive of native libraries ("moonlibs")
function getLibs()
{
2022-08-30 05:11:51 +00:00
# Downloading
echo "Downloading latest moonlibs..."
curl https://moonside.games/files/moonlibs.tar.bz2 > "$MY_DIR/moonlibs.tar.bz2"
if [ $? -eq 0 ]; then
echo "Finished downloading!"
else
>&2 echo "ERROR: Unable to download successfully."
exit 1
fi
2021-04-04 21:01:40 +00:00
2022-08-30 05:11:51 +00:00
# Decompressing
echo "Decompressing moonlibs..."
mkdir -p "$MY_DIR"
2023-08-08 17:37:53 +00:00
mkdir -p "$MY_DIR"/moonlibs
2022-08-30 05:11:51 +00:00
tar -xvC "$MY_DIR"/moonlibs -f "$MY_DIR"/moonlibs.tar.bz2
if [ $? -eq 0 ]; then
echo "Finished decompressing!"
echo ""
rm "$MY_DIR"/moonlibs.tar.bz2
else
>&2 echo "ERROR: Unable to decompress successfully."
exit 1
fi
}
2021-04-04 21:01:40 +00:00
read -p "Enter your project name or 'exit' to quit: " newProjectName
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
2022-08-30 05:11:51 +00:00
exit 1
2021-04-04 21:01:40 +00:00
fi
NEW_PROJECT_DIR="$MY_DIR/../$newProjectName"
if [ -d "$NEW_PROJECT_DIR" ]; then
2022-08-30 05:11:51 +00:00
>&2 echo "ERROR: Project directory already exists."
2021-04-04 21:01:40 +00:00
exit 1
fi
2022-08-30 05:11:51 +00:00
getLibs
2021-04-04 21:01:40 +00:00
# copy everything into new dir
cp -R "$MY_DIR" "$NEW_PROJECT_DIR"
cd "$NEW_PROJECT_DIR"
2022-03-07 06:07:14 +00:00
files=(ProjectName.sln .gitignore ProjectName.csproj src/ProjectNameGame.cs src/Program.cs .vscode/tasks.json .vscode/launch.json)
2021-04-04 21:01:40 +00:00
for file in "${files[@]}"; do
2022-08-30 05:11:51 +00:00
sed -i -e "s/ProjectName/$newProjectName/g" "./$file"
if [ "$(uname)" == "Darwin" ]; then
rm ./${file}-e
fi
2021-04-04 21:01:40 +00:00
done
mv ./ProjectName.sln "./$newProjectName.sln"
mv ./ProjectName.csproj "./$newProjectName.csproj"
mv ./src/ProjectNameGame.cs ./src/${newProjectName}Game.cs
2021-04-04 21:01:40 +00:00
rm ./install.sh
rm ./LICENSE
rm -rf .git
git init
mkdir lib
pullMoonWorks
2023-08-08 17:37:53 +00:00
dotnet sln ${newProjectName}.sln add ${newProjectName}.csproj --in-root
dotnet sln ${newProjectName}.sln add lib/MoonWorks/MoonWorks.csproj --in-root
dotnet sln ${newProjectName}.sln add lib/MoonWorks/lib/dav1dfile/csharp/dav1dfile-CS.csproj --in-root
dotnet sln ${newProjectName}.sln add lib/MoonWorks/lib/FAudio/csharp/FAudio-CS.Core.csproj --in-root
dotnet sln ${newProjectName}.sln add lib/MoonWorks/lib/RefreshCS/RefreshCS.csproj --in-root
dotnet sln ${newProjectName}.sln add lib/MoonWorks/lib/SDL2-CS/SDL2-CS.Core.csproj --in-root
dotnet sln ${newProjectName}.sln add lib/MoonWorks/lib/WellspringCS/WellspringCS.csproj --in-root
2021-04-04 21:01:40 +00:00
echo "Project $newProjectName created at: "
if [ "$(uname)" == "Darwin" ]; then
2022-08-30 05:11:51 +00:00
echo $(readlinkf $NEW_PROJECT_DIR)
2021-04-04 21:01:40 +00:00
else
2022-08-30 05:11:51 +00:00
echo $(readlink -f $NEW_PROJECT_DIR)
2021-04-04 21:01:40 +00:00
fi