Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

2.2 KB
Raw Blame
#!/bin/bash
APPIMAGETOOL="./.cache/build-tools/appimagetool"
RELEASE_CHANNEL=${RELEASE_CHANNEL:-"stable"}

# appimagetool is itself an AppImage, so it mounts itself through FUSE, which
# the hosted runners no longer provide. This runs outside shim-linuxdeploy.sh,
# so it needs its own copy of the fallback.
export APPIMAGE_EXTRACT_AND_RUN=1

mkdir -p ./.cache/build-tools
wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage -O "${APPIMAGETOOL}" || { echo "Failed to download appimagetool."; exit 1; }
chmod +x "${APPIMAGETOOL}"

if [ "${RELEASE_CHANNEL}" != "stable" ]; then
    APP_DIR=./src-tauri/target/release/bundle/appimage/Jan-${RELEASE_CHANNEL}.AppDir
else
    APP_DIR=./src-tauri/target/release/bundle/appimage/Jan.AppDir
fi

# bundle additional resources in the AppDir without pulling in their dependencies
cp ./src-tauri/resources/bin/bun $APP_DIR/usr/bin/bun

# tauri-cli before 2.11.4 (tauri-apps/tauri#15596) links .DirIcon to the icon's
# absolute build-host path, which dangles inside the mounted AppImage. appimagetool
# keeps it because it resolves here, so re-point it relative to the AppDir root.
DIR_ICON="$APP_DIR/.DirIcon"
if [[ "$(readlink "$DIR_ICON")" == /* ]]; then
    ln -sfn "$(basename "$(readlink "$DIR_ICON")")" "$DIR_ICON"
fi
if [ ! -f "$DIR_ICON" ] || [[ "$(readlink "$DIR_ICON")" == /* ]]; then
    echo ".DirIcon in $APP_DIR is missing or not relative to the AppDir."
    exit 1
fi

# The host's Vulkan loader and NVIDIA driver have to be the ones that run; a copy
# from the build host crashed every model load on Arch (#9173). shim-linuxdeploy.sh
# excludes them, so finding one here means that exclusion stopped applying.
HOST_LIBS=$(find "$APP_DIR" \( -name 'libvulkan.so*' -o -name 'libcuda.so*' \) 2>/dev/null)
if [ -n "$HOST_LIBS" ]; then
    echo "$APP_DIR bundles libraries that must come from the user's system:"
    echo "$HOST_LIBS"
    exit 1
fi

# remove appimage generated by tauri build
APP_IMAGE=./src-tauri/target/release/bundle/appimage/$(ls ./src-tauri/target/release/bundle/appimage/ | grep AppImage | head -1)
echo $APP_IMAGE
rm -f $APP_IMAGE

# repackage appimage with additional resources
"${APPIMAGETOOL}" $APP_DIR $APP_IMAGE