#!/bin/bash

set -e  # Exit on error
set -o pipefail  # Catch pipeline failures

# Define the installation directory
INSTALL_DIR="$HOME/gfStory-en"

echo "==> Cloning repository into $INSTALL_DIR..."
if [ -d "$INSTALL_DIR" ]; then
    echo "==> Directory already exists, pulling latest changes..."
    cd "$INSTALL_DIR"
    git pull --recurse-submodules
else
    git clone --recurse-submodules https://github.com/shiropantsu/gfStory-en "$INSTALL_DIR"
    cd "$INSTALL_DIR"
fi

echo "==> Updating package lists..."
sudo apt update

echo "==> Installing dependencies..."
sudo apt install -y ffmpeg pngquant imagemagick libfuse2 wget unzip curl git

echo "==> Installing vgmstream and ImageMagick CLI..."
mkdir -p "$INSTALL_DIR/bin"
cd "$INSTALL_DIR/bin"

wget -q https://github.com/vgmstream/vgmstream-releases/releases/download/nightly/vgmstream-linux-cli.tar.gz
tar -zxf vgmstream-linux-cli.tar.gz && rm vgmstream-linux-cli.tar.gz

wget -q https://imagemagick.org/archive/binaries/magick
chmod +x magick vgmstream-cli
export PATH="$INSTALL_DIR/bin:$PATH"

echo "==> Installing PDM (Python dependency manager)..."
curl -sSL https://pdm.fming.dev/install-pdm.py | python3 -
export PATH="$HOME/.local/bin:$PATH"

echo "==> Setting up Python environment..."
cd "$INSTALL_DIR/unpack"
pdm install
source .venv/bin/activate
pip install -r downloader/requirements.txt

echo "==> Downloading resources..."
mkdir -p downloader/resdata
cp gf-data-us/resdata_no_hash.json downloader/resdata/us_resdata.json
cd downloader
sed -i 's/"ch"/"us"/' config.json5
git apply ../downloader.patch
zip -j resdata.zip resdata/us_resdata.json
python downloader.py --downloadres 0 --abname

echo "==> Unpacking and processing resources..."
cd "$INSTALL_DIR/unpack"
python tests/test_backgrounds.py
python tests/test_characters.py
python tests/test_audio.py
python -m gfunpack downloader/output -o .

echo "==> Moving resources..."
cp audio/audio.json images/backgrounds.json images/characters.json stories/stories.json stories/chapters.json ../src/assets
mv audio ../public
mv images ../public
mv stories ../public

echo "==> Installing FNM (Fast Node Manager)..."
curl -fsSL https://fnm.vercel.app/install | bash
export PATH="$HOME/.fnm:$PATH"
eval "$(fnm env)"

echo "==> Installing latest Node.js version using FNM..."
fnm install --lts
fnm use --lts
export PATH="$(fnm bin):$PATH"

echo "==> Installing PNPM..."
curl -fsSL https://get.pnpm.io/install.sh | sh -
export PATH="$HOME/.local/share/pnpm:$PATH"

echo "==> Installing and building site..."
cd "$INSTALL_DIR"
pnpm install
pnpm build-index
pnpm build

echo "==> Setup complete! You can now run the project locally."
Edit Report
Pub: 18 Feb 2025 17:06 UTC
Views: 77