Last active
August 26, 2024 23:23
-
-
Save tyrone-sudeium/489afacf20ed7ebbf37ad035ab935fee to your computer and use it in GitHub Desktop.
FFXIV Teamcraft Installer/Updater for Linux / WINE. Requires the @rankynbass fork of XLCore (only tested when installed via AUR or built from source)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
DESKTOP_INTEGRATION=1 | |
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 | |
;; | |
--no-integrate) | |
DESKTOP_INTEGRATION=0 | |
shift | |
;; | |
*) # unknown option | |
echo "Unknown option: $1" | |
shift | |
;; | |
esac | |
done | |
TC_ROOT="$WINEPREFIX/drive_c/users/$WINEUSER/AppData/Local/ffxiv-teamcraft" | |
# Desktop integration stuff | |
TC_ICON_URL="https://github.com/ffxiv-teamcraft/ffxiv-teamcraft/blob/96555f4b540aa40ed002bdbbc62c6df44005d0df/apps/client/src/assets/app-icon.png?raw=true" | |
TC_ICON_PATH="$TC_ROOT/ffxiv-teamcraft.png" | |
DESKTOP_FILE_STR=$(cat <<EOF | |
[Desktop Entry] | |
Comment=FFXIV Teamcraft | |
Exec=/home/$USER/sbin/xlcore-wine 'C:\\\\\\\\users\\\\\\\\$WINEUSER\\\\\\\\AppData\\\\\\\\Local\\\\\\\\ffxiv-teamcraft\\\\\\\\FFXIV Teamcraft.exe' | |
GenericName=An FFXIV tool to handle collaborative crafts easily\s | |
Icon=$TC_ICON_PATH | |
Name=FFXIV Teamcraft | |
NoDisplay=false | |
StartupNotify=true | |
Terminal=false | |
TerminalOptions= | |
Type=Application | |
EOF | |
) | |
XLCORE_WINE_URL="https://gist.githubusercontent.com/tyrone-sudeium/d08029ee3f581594476be661600309f0/raw" | |
XLCORE_WINE_PATH="$HOME/sbin/xlcore-wine" | |
DESKTOP_FILE_PATH="$HOME/.local/share/applications/ffxiv-teamcraft.desktop" | |
desktop_integrations() { | |
if [ $DESKTOP_INTEGRATION -ne 0 ] && [ ! -e "$DESKTOP_FILE_PATH" ]; then | |
echo "Installing desktop integrations..." | |
mkdir -p "$HOME/sbin" | |
printf "$DESKTOP_FILE_STR" > "$DESKTOP_FILE_PATH" | |
if [ ! -e "$XLCORE_WINE_PATH" ]; then | |
curl -L -o "$XLCORE_WINE_PATH" "$XLCORE_WINE_URL" | |
chmod +x "$XLCORE_WINE_PATH" | |
fi | |
if [ ! -e "$TC_ICON_PATH" ]; then | |
curl -L -o "$TC_ICON_PATH" "$TC_ICON_URL" | |
fi | |
fi | |
} | |
# 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." | |
desktop_integrations | |
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" | |
desktop_integrations | |
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 | |
desktop_integrations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment