Skip to content

Commit

Permalink
Updated installation script. (#6)
Browse files Browse the repository at this point in the history
* Updated installation script.

Refactored and reworked the script to increase efficiency.

I've added some checks that decrease the workload of the script when running an update or if it fails during an installation due to whatever reason.

Added specific region downloading, unsure if this is any use but when checking the various version of the game I did notice some were labelled differently from others so depending on Region, it's probably best to download the correct one.

No longer requires Unity Hub to be installed. Instead it directly downloads the necessary unity files, moves across the ones required and dumps the rest to save space and installation time.

Reworked how updating works, just because a full rm -rf isn't necessary and instead the game works fine after updating without deleting every file, deeming it unnecessary to delete /Bin folder.

* Fixed updating with an installed version

Tested and now seems to work when updating from a previous version.

Also seems to work fine when installing fresh.

* Fixes Unity files issues when updating.

Fixes the issues brought up about duplicate files and previous installations.

Now it minimises the installation / updating process.

* Region expected in lowercase

* Minor simplifications

* shfmt

* fix typo

Co-authored-by: 0xf4b1 <10889432+0xf4b1@users.noreply.github.com>
  • Loading branch information
BarclayXO and 0xf4b1 authored Oct 17, 2021
1 parent 084d6a6 commit cbdb488
Showing 1 changed file with 118 additions and 76 deletions.
194 changes: 118 additions & 76 deletions craft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,152 @@
set -e

NGDP_BIN=$(realpath keg/bin/ngdp)
GREEN='\e[32m'
RED='\e[31m'
WHITE='\e[37m'

setup_keg () {
setup_keg() {
cd keg
./setup.py build
cd ..
}

init_hearthstone () {
set_region() {
if [ -f ".region" ]; then
REGION=$(cat .region)
else
read -p "Which region do you wish to install? [eu/us/kr/cn]: " REGION
echo $REGION >.region
fi
}

init_hearthstone() {
mkdir hearthstone && cd hearthstone
$NGDP_BIN init
$NGDP_BIN remote add hsb
echo "Not installed" > .version
}

check_version () {
echo "Checking versions"
version=$(curl http://us.patch.battle.net:1119/hsb/versions | grep us)
version=${version%|*}
version=${version##*|}
installed=$(cat .version)
echo "Online version: $version"
echo "Installed version: $installed"
}
set_region

download_hearthstone () {
echo "Downloading Hearthstone via keg ..."
$NGDP_BIN --cdn "http://level3.blizzard.com/tpr/hs" fetch hsb --tags OSX --tags enUS --tags Production
$NGDP_BIN install hsb $version --tags OSX --tags enUS --tags Production
echo $version > .version
cd ..
}
if [ "${REGION^^}" = "EU" ] || [ "${REGION^^}" = "US" ] || [ "${REGION^^}" = "KR" ] || [ "${REGION^^}" = "CN" ]; then
$NGDP_BIN remote add http://${REGION}.patch.battle.net:1119/hsb

if [ -z $1 ]; then
if [ ! -d hearthstone ]; then
echo "Hearthstone installation not found"
setup_keg
init_hearthstone
check_version
download_hearthstone
else
cd hearthstone
check_version
if [[ ! "$version" = "$installed" ]]; then
echo "Update required."
rm -rf *
download_hearthstone
fi
echo -e "${RED}Invalid Region. Exiting."
exit 1
fi
TARGET_PATH=$(realpath hearthstone)
else
# User-specified Hearthstone installation
TARGET_PATH=$(realpath $1)
fi

UNITY_ENGINE=/Hub/Editor/2018.4.10f1/Editor/Data/PlaybackEngines/LinuxStandaloneSupport/Variations/linux64_withgfx_nondevelopment_mono

download_unity () {
echo "Downloading Unity Hub"
curl -O https://public-cdn.cloud.unity3d.com/hub/prod/UnityHub.AppImage
chmod +x ./UnityHub.AppImage
./UnityHub.AppImage unityhub://2018.4.10f1/a0470569e97b
[ ! -d ~/Unity$UNITY_ENGINE ] && echo "Required Unity Engine files not installed!" && exit 1
echo "Not installed" >.version
}

if [ -z $2 ]; then
if [ ! -d ~/Unity$UNITY_ENGINE ]; then
echo "Required Unity Engine files not found in default directory!"
download_unity
check_version() {
set_region
VERSION=$(curl http://${REGION}.patch.battle.net:1119/hsb/versions | grep $REGION)
VERSION=${VERSION%|*}
VERSION=${VERSION##*|}

if [ -f ".version" ]; then
INSTALLED=$(cat .version)
else
INSTALLED="Not installed"
fi
UNITY_PATH=~/Unity$UNITY_ENGINE
else
UNITY_PATH=$2$UNITY_ENGINE
fi

echo "Rearrange game files ..."
echo -e "${GREEN}Region: ${WHITE}$REGION"
echo -e "${GREEN}Online version: ${WHITE}$VERSION"
echo -e "${GREEN}Downloaded version: ${WHITE}$INSTALLED"
}

mkdir $TARGET_PATH/Bin
mv $TARGET_PATH/Hearthstone.app/Contents/Resources/Data $TARGET_PATH/Bin/Hearthstone_Data
mv $TARGET_PATH/Hearthstone.app/Contents/Resources/'unity default resources' $TARGET_PATH/Bin/Hearthstone_Data/Resources
mv $TARGET_PATH/Hearthstone.app/Contents/Resources/PlayerIcon.icns $TARGET_PATH/Bin/Hearthstone_Data/Resources
download_hearthstone() {
echo -e "${GREEN}Downloading Hearthstone via keg ...${WHITE}\n"
$NGDP_BIN --cdn "http://level3.blizzard.com/tpr/hs" fetch http://${REGION}.patch.battle.net:1119/hsb --tags OSX --tags enUS --tags Production
$NGDP_BIN install http://${REGION}.patch.battle.net:1119/hsb $VERSION --tags OSX --tags enUS --tags Production
echo $VERSION >.version
}

echo "Copy engine files ..."
download_unity() {
echo -e "${RED}Unity files not found.\n${GREEN}Downloading Unity 2018.4.10f1 (This is version is required for the game to run).${WHITE}\n"
mkdir -p tmp
[ ! -f "tmp/Unity.tar.xz" ] && wget -P tmp https://netstorage.unity3d.com/unity/a0470569e97b/LinuxEditorInstaller/Unity.tar.xz

cp $UNITY_PATH/LinuxPlayer $TARGET_PATH/Bin/Hearthstone.x86_64
cp -r $UNITY_PATH/Data/MonoBleedingEdge $TARGET_PATH/Bin/Hearthstone_Data
echo -e "${GREEN}Extracting Unity files....${WHITE}\n"
tar -xf tmp/Unity.tar.xz -C tmp Editor/Data/PlaybackEngines/LinuxStandaloneSupport/Variations/linux64_withgfx_nondevelopment_mono/LinuxPlayer Editor/Data/PlaybackEngines/LinuxStandaloneSupport/Variations/linux64_withgfx_nondevelopment_mono/Data/MonoBleedingEdge/
UNITY_PATH=tmp/Editor/Data/PlaybackEngines/LinuxStandaloneSupport/Variations/linux64_withgfx_nondevelopment_mono

echo "Creating stubs ..."
mkdir -p $TARGET_PATH/Bin
mv $UNITY_PATH/LinuxPlayer $TARGET_PATH/Bin/Hearthstone.x86_64
mv $UNITY_PATH/Data/MonoBleedingEdge $TARGET_PATH
rm -rf tmp
echo -e "${GREEN}Done!\n${WHITE}"
}

cp client.config $TARGET_PATH
move_files_and_cleaup() {
echo -e "${GREEN}Moving files & running cleanup ...\n${WHITE}"

mkdir -p $TARGET_PATH/Bin/Hearthstone_Data/Plugins/System/Library/Frameworks/CoreFoundation.framework
mv $TARGET_PATH/Hearthstone.app/Contents/Resources/Data $TARGET_PATH/Bin/Hearthstone_Data
mv $TARGET_PATH/Hearthstone.app/Contents/Resources/'unity default resources' $TARGET_PATH/Bin/Hearthstone_Data/Resources
mv $TARGET_PATH/Hearthstone.app/Contents/Resources/PlayerIcon.icns $TARGET_PATH/Bin/Hearthstone_Data/Resources
mv $TARGET_PATH/MonoBleedingEdge $TARGET_PATH/Bin/Hearthstone_Data

make -C stubs
echo -e "${GREEN}Done!\n${WHITE}"

cp stubs/CoreFoundation.so $TARGET_PATH/Bin/Hearthstone_Data/Plugins/System/Library/Frameworks/CoreFoundation.framework
cp stubs/libOSXWindowManagement.so $TARGET_PATH/Bin/Hearthstone_Data/Plugins
echo -e "${GREEN}Cleaning up unecessary files.${WHITE}\n"
rm -rf $TARGET_PATH/Hearthstone.app
rm -rf $TARGET_PATH/'Hearthstone Beta Launcher.app'
}

make -C token
gen_token_login() {
make -C token
cp token/Token.exe $TARGET_PATH
make -C login
cp login/login $TARGET_PATH
}

cp token/Token.exe $TARGET_PATH
create_stubs() {
cp client.config $TARGET_PATH
mkdir -p $TARGET_PATH/Bin/Hearthstone_Data/Plugins/System/Library/Frameworks/CoreFoundation.framework
make -C stubs
cp stubs/CoreFoundation.so $TARGET_PATH/Bin/Hearthstone_Data/Plugins/System/Library/Frameworks/CoreFoundation.framework
cp stubs/libOSXWindowManagement.so $TARGET_PATH/Bin/Hearthstone_Data/Plugins
}

make -C login
check_directory() {
if [ -z $1 ]; then
if [ ! -d hearthstone ]; then
echo -e "${RED}Hearthstone installation not found${WHITE}\n"
setup_keg
init_hearthstone
check_version
download_hearthstone
else
cd hearthstone
check_version
if [[ ! "$VERSION" = "$INSTALLED" ]]; then
echo -e "${RED}Update required.${WHITE}\n"
[ -d "Bin/Hearthstone_Data/MonoBleedingEdge" ] && mv Bin/Hearthstone_Data/MonoBleedingEdge .
rm -rf Bin/Hearthstone_Data
rm -rf Data
rm -rf Hearthstone.app
rm -rf 'Hearthstone Beta Launcher.app'
rm -rf Strings
rm -rf Logs
download_hearthstone
fi
fi
cd ..
TARGET_PATH=$(realpath hearthstone)
else
# User-specified Hearthstone installation
TARGET_PATH=$(realpath $1)
fi
}

cp login/login $TARGET_PATH
check_directory
if [ ! -f "$TARGET_PATH/Bin/Hearthstone.x86_64" ]; then
download_unity
fi
move_files_and_cleaup
gen_token_login
create_stubs

cat << EOF > ~/.local/share/applications/hearthstone.desktop
cat <<EOF >~/.local/share/applications/hearthstone.desktop
[Desktop Entry]
Type=Application
Name=Hearthstone
Expand All @@ -117,4 +157,6 @@ Icon=$TARGET_PATH/Bin/Hearthstone_Data/Resources/PlayerIcon.icns
Categories=Game;
EOF

echo "Done. Now generate your web token, before launching the game!"
chmod +x $TARGET_PATH/login
chmod +x $TARGET_PATH/Bin/Hearthstone.x86_64
echo -e "\n${GREEN}Done. Now generate your web token, before launching the game!${WHITE}"

0 comments on commit cbdb488

Please sign in to comment.