2021-12-03 09:48:00 +08:00
#!/bin/bash
2021-12-06 07:55:10 +08:00
#
#
# This is the Bash equivalent of ../windows/prepare-install-package.ps1.
# When making changes, both scripts should be updated.
#
#
2021-12-03 09:48:00 +08:00
##########
2022-05-02 05:33:41 +08:00
## Fetch values
2021-12-03 09:48:00 +08:00
##########
2021-12-03 13:26:46 +08:00
# paths
2021-12-03 09:48:00 +08:00
gamePath = "/home/pathoschild/Stardew Valley"
bundleModNames = ( "ConsoleCommands" "ErrorHandler" "SaveBackup" )
2021-12-03 13:26:46 +08:00
# build configuration
2021-12-03 09:48:00 +08:00
buildConfig = "Release"
2021-12-03 13:26:46 +08:00
folders = ( "linux" "macOS" "windows" )
declare -A runtimes = ( [ "linux" ] = "linux-x64" [ "macOS" ] = "osx-x64" [ "windows" ] = "win-x64" )
declare -A msBuildPlatformNames = ( [ "linux" ] = "Unix" [ "macOS" ] = "OSX" [ "windows" ] = "Windows_NT" )
2021-12-03 09:48:00 +08:00
2022-05-02 05:33:41 +08:00
# version number
2022-04-30 10:55:12 +08:00
version = " $1 "
if [ $# -eq 0 ] ; then
echo "SMAPI release version (like '4.0.0'):"
read version
fi
2022-05-02 05:33:41 +08:00
##########
## Move to SMAPI root
##########
cd "`dirname " $0 "`/../.."
2022-04-30 10:55:12 +08:00
2021-12-03 09:48:00 +08:00
##########
## Clear old build files
##########
echo "Clearing old builds..."
2021-12-06 07:55:10 +08:00
echo "-------------------------------------------------"
for path in bin */**/bin */**/obj; do
2021-12-05 04:55:29 +08:00
echo " $path "
2021-12-03 09:48:00 +08:00
rm -rf $path
done
echo ""
##########
## Compile files
##########
2022-05-02 05:33:41 +08:00
. ${ 0 %/* } /set-smapi-version.sh " $version "
2021-12-03 09:48:00 +08:00
for folder in ${ folders [@] } ; do
runtime = ${ runtimes [ $folder ] }
msbuildPlatformName = ${ msBuildPlatformNames [ $folder ] }
echo " Compiling SMAPI for $folder ... "
2021-12-06 07:55:10 +08:00
echo "-------------------------------------------------"
2021-12-05 04:55:29 +08:00
dotnet publish src/SMAPI --configuration $buildConfig -v minimal --runtime " $runtime " -p:OS= " $msbuildPlatformName " -p:GamePath= " $gamePath " -p:CopyToGameFolder= "false" --self-contained true
2021-12-03 09:48:00 +08:00
echo ""
echo ""
echo " Compiling installer for $folder ... "
2021-12-06 07:55:10 +08:00
echo "-------------------------------------------------"
2021-12-03 13:26:46 +08:00
dotnet publish src/SMAPI.Installer --configuration $buildConfig -v minimal --runtime " $runtime " -p:OS= " $msbuildPlatformName " -p:GamePath= " $gamePath " -p:CopyToGameFolder= "false" -p:PublishTrimmed= True -p:TrimMode= Link --self-contained true
2021-12-03 09:48:00 +08:00
echo ""
echo ""
for modName in ${ bundleModNames [@] } ; do
echo " Compiling $modName for $folder ... "
2021-12-06 07:55:10 +08:00
echo "-------------------------------------------------"
2021-12-03 09:48:00 +08:00
dotnet publish src/SMAPI.Mods.$modName --configuration $buildConfig -v minimal --runtime " $runtime " -p:OS= " $msbuildPlatformName " -p:GamePath= " $gamePath " -p:CopyToGameFolder= "false"
echo ""
echo ""
done
done
##########
## Prepare install package
##########
echo "Preparing install package..."
2021-12-06 07:55:10 +08:00
echo "-------------------------------------------------"
2021-12-03 09:48:00 +08:00
# init paths
installAssets = "src/SMAPI.Installer/assets"
packagePath = "bin/SMAPI installer"
packageDevPath = "bin/SMAPI installer for developers"
# init structure
for folder in ${ folders [@] } ; do
mkdir " $packagePath /internal/ $folder /bundle/smapi-internal " --parents
done
# copy base installer files
2021-12-03 13:26:46 +08:00
for name in "install on Linux.sh" "install on macOS.command" "install on Windows.bat" "README.txt" ; do
2021-12-05 04:55:29 +08:00
cp " $installAssets / $name " " $packagePath "
2021-12-03 13:26:46 +08:00
done
2021-12-03 09:48:00 +08:00
# copy per-platform files
for folder in ${ folders [@] } ; do
runtime = ${ runtimes [ $folder ] }
# get paths
2021-12-03 13:26:46 +08:00
smapiBin = " src/SMAPI/bin/ $buildConfig / $runtime /publish "
2021-12-03 09:48:00 +08:00
internalPath = " $packagePath /internal/ $folder "
bundlePath = " $internalPath /bundle "
2021-12-03 13:26:46 +08:00
# installer files
cp -r " src/SMAPI.Installer/bin/ $buildConfig / $runtime /publish " /* " $internalPath "
rm -rf " $internalPath /assets "
2021-12-03 09:48:00 +08:00
# runtime config for SMAPI
2021-12-05 09:25:53 +08:00
# This is identical to the one generated by the build, except that the min runtime version is
# set to 5.0.0 (instead of whatever version it was built with) and rollForward is set to latestMinor instead of
# minor.
cp " $installAssets /runtimeconfig.json " " $bundlePath /StardewModdingAPI.runtimeconfig.json "
2021-12-03 09:48:00 +08:00
2021-12-03 13:26:46 +08:00
# installer DLL config
2021-12-03 09:48:00 +08:00
if [ $folder = = "windows" ] ; then
cp " $installAssets /windows-exe-config.xml " " $packagePath /internal/windows/install.exe.config "
fi
# bundle root files
for name in "StardewModdingAPI" "StardewModdingAPI.dll" "StardewModdingAPI.pdb" "StardewModdingAPI.xml" "steam_appid.txt" ; do
if [ $name = = "StardewModdingAPI" ] && [ $folder = = "windows" ] ; then
name = " $name .exe "
fi
2021-12-05 04:55:29 +08:00
cp " $smapiBin / $name " " $bundlePath "
2021-12-03 09:48:00 +08:00
done
# bundle i18n
cp -r " $smapiBin /i18n " " $bundlePath /smapi-internal "
# bundle smapi-internal
2022-03-05 09:27:17 +08:00
for name in "0Harmony.dll" "0Harmony.xml" "Mono.Cecil.dll" "Mono.Cecil.Mdb.dll" "Mono.Cecil.Pdb.dll" "MonoMod.Common.dll" "Newtonsoft.Json.dll" "Pintail.dll" "TMXTile.dll" "SMAPI.Toolkit.dll" "SMAPI.Toolkit.pdb" "SMAPI.Toolkit.xml" "SMAPI.Toolkit.CoreInterfaces.dll" "SMAPI.Toolkit.CoreInterfaces.pdb" "SMAPI.Toolkit.CoreInterfaces.xml" ; do
2021-12-05 04:55:29 +08:00
cp " $smapiBin / $name " " $bundlePath /smapi-internal "
2021-12-03 09:48:00 +08:00
done
cp " $smapiBin /SMAPI.config.json " " $bundlePath /smapi-internal/config.json "
cp " $smapiBin /SMAPI.metadata.json " " $bundlePath /smapi-internal/metadata.json "
2021-12-03 13:26:46 +08:00
if [ $folder = = "linux" ] || [ $folder = = "macOS" ] ; then
2021-12-05 04:55:29 +08:00
cp " $installAssets /unix-launcher.sh " " $bundlePath "
2021-12-03 09:48:00 +08:00
else
cp " $installAssets /windows-exe-config.xml " " $bundlePath /StardewModdingAPI.exe.config "
fi
# copy .NET dependencies
if [ $folder = = "windows" ] ; then
2021-12-05 04:55:29 +08:00
cp " $smapiBin /System.Management.dll " " $bundlePath /smapi-internal "
2021-12-03 09:48:00 +08:00
fi
2022-06-01 09:23:44 +08:00
# copy legacy .NET dependencies (remove in SMAPI 4.0.0)
cp " $smapiBin /System.Configuration.ConfigurationManager.dll " " $bundlePath /smapi-internal "
cp " $smapiBin /System.Runtime.Caching.dll " " $bundlePath /smapi-internal "
cp " $smapiBin /System.Security.Permissions.dll " " $bundlePath /smapi-internal "
2021-12-03 09:48:00 +08:00
# copy bundled mods
for modName in ${ bundleModNames [@] } ; do
2021-12-03 13:26:46 +08:00
fromPath = " src/SMAPI.Mods. $modName /bin/ $buildConfig / $runtime /publish "
2021-12-03 09:48:00 +08:00
targetPath = " $bundlePath /Mods/ $modName "
mkdir " $targetPath " --parents
2021-12-05 04:55:29 +08:00
cp " $fromPath / $modName .dll " " $targetPath "
cp " $fromPath / $modName .pdb " " $targetPath "
cp " $fromPath /manifest.json " " $targetPath "
2021-12-03 09:48:00 +08:00
if [ -d " $fromPath /i18n " ] ; then
cp -r " $fromPath /i18n " " $targetPath "
fi
done
done
# mark scripts executable
for path in "install on Linux.sh" "install on macOS.command" "bundle/unix-launcher.sh" ; do
if [ -f " $packagePath / $path " ] ; then
chmod 755 " $packagePath / $path "
fi
done
# split into main + for-dev folders
cp -r " $packagePath " " $packageDevPath "
for folder in ${ folders [@] } ; do
# disable developer mode in main package
sed --in-place --expression= "s/\"DeveloperMode\": true/\"DeveloperMode\": false/" " $packagePath /internal/ $folder /bundle/smapi-internal/config.json "
# convert bundle folder into final 'install.dat' files
for path in " $packagePath /internal/ $folder " " $packageDevPath /internal/ $folder " ; do
pushd " $path /bundle " > /dev/null
zip "install.dat" * --recurse-paths --quiet
popd > /dev/null
mv " $path /bundle/install.dat " " $path /install.dat "
rm -rf " $path /bundle "
done
done
##########
## Create release zips
##########
# rename folders
mv " $packagePath " " bin/SMAPI $version installer "
mv " $packageDevPath " " bin/SMAPI $version installer for developers "
# package files
pushd bin > /dev/null
zip -9 " SMAPI $version installer.zip " " SMAPI $version installer " --recurse-paths --quiet
zip -9 " SMAPI $version installer for developers.zip " " SMAPI $version installer for developers " --recurse-paths --quiet
popd > /dev/null
echo ""
echo " Done! Package created in $( pwd ) /bin "