Skip to content

Instantly share code, notes, and snippets.

@tyrone-sudeium
Created December 16, 2023 07:50
Show Gist options
  • Save tyrone-sudeium/489afacf20ed7ebbf37ad035ab935fee to your computer and use it in GitHub Desktop.
Save tyrone-sudeium/489afacf20ed7ebbf37ad035ab935fee to your computer and use it in GitHub Desktop.
FFXIV Teamcraft Installer/Updater for Linux / WINE
#!/bin/bash
command -v jq >/dev/null 2>&1 || { echo >&2 "jq required. Install it and try again."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "curl required. Install it and try again."; exit 1; }
command -v 7z >/dev/null 2>&1 || { echo >&2 "7z required. Install it and try again."; exit 1; }
verlte() {
printf '%s\n' "$1" "$2" | sort -C -V
}
WINEPREFIX="$HOME/.xlcore/wineprefix"
WINEUSER=$USER
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-p|--prefix)
WINEPREFIX="$2"
shift # past argument
shift # past value
;;
-u|--user)
WINEUSER="$2"
shift
shift
;;
*) # unknown option
echo "Unknown option: $1"
shift
;;
esac
done
TC_ROOT="$WINEPREFIX/drive_c/users/$WINEUSER/AppData/Local/ffxiv-teamcraft"
# Get the latest release information using the GitHub API
RELEASE_INFO=$(curl -s "https://api.github.com/repos/ffxiv-teamcraft/ffxiv-teamcraft/releases/latest")
# Extract release assets using jq
ASSET_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name | endswith(".nupkg")) | .browser_download_url')
INSTALLER_ASSSET_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name | endswith(".exe")) | .browser_download_url')
LATEST_VERSION=$(echo "$RELEASE_INFO" | jq -r '.name')
VERSION_FILE="$TC_ROOT/.version"
CURRENT_VERSION=$(cat "$VERSION_FILE")
if verlte "$LATEST_VERSION" "$CURRENT_VERSION"; then
echo "Nothing to do: already on latest."
exit 0
fi
if [ -e "$TC_ROOT/app-$LATEST_VERSION" ]; then
echo "Nothing to do: $LATEST_VERSION unexpectedly already installed."
printf '%s' "$LATEST_VERSION" > "$VERSION_FILE"
exit 0
fi
rm -r /tmp/tc
mkdir -p /tmp/tc
if [ ! -e "$TC_ROOT" ]; then
echo "Teamcraft not found: installing from scratch..."
# Grab the installer asset
ASSET_FILENAME=$(basename "$INSTALLER_ASSSET_URL")
echo "Downloading asset: $ASSET_FILENAME"
# Download the asset
curl -L -o "/tmp/tc/installer.exe" "$INSTALLER_ASSSET_URL"
pushd /tmp/tc
# Extract the Squirrel installer
7z x installer.exe -o/tmp/tc
# Extract the embedded nupkg
mkdir -p /tmp/tc/package
7z x *.nupkg -o/tmp/tc/package
# Move the execution stub
mkdir -p "$TC_ROOT"
mv "package/lib/net45/FFXIV Teamcraft_ExecutionStub.exe" "$TC_ROOT/FFXIV Teamcraft.exe"
# Copy the updater
mv "package/lib/net45/Update.exe" "$TC_ROOT/Update.exe"
# Move the initial app version
mv /tmp/tc/package/lib/net45 "$TC_ROOT/app-$LATEST_VERSION"
printf '%s' "$LATEST_VERSION" > "$VERSION_FILE"
else
if [ ! -n "$ASSET_URL" ]; then
echo "No asset with '.nupkg' extension found in the latest release."
exit 1
fi
# Install update to $TC_ROOT/app-$LATEST-VERSION
# Get the filename from the URL
ASSET_FILENAME=$(basename "$ASSET_URL")
echo "Downloading asset: $ASSET_FILENAME"
# Download the asset
curl -L -o "/tmp/tc/latest.nupkg" "$ASSET_URL"
pushd /tmp/tc
7z x latest.nupkg -o/tmp/tc
mkdir -p "$TC_ROOT"
mv /tmp/tc/lib/net45 "$TC_ROOT/app-$LATEST_VERSION"
printf '%s' "$LATEST_VERSION" > "$VERSION_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment