#!/usr/bin/env bash # Personal builds only under Aseprite's license. Guide: https://graal.codes/guides/get-aseprite-free # bash -c "$(curl -fsSL https://graal.codes/get/aseprite.sh)" set -eEuo pipefail PINNED="1.3.18.6" CMAKE_VERSION="3.31.6" NINJA_VERSION="1.12.1" WORK="${ASEPRITE_BUILD_DIR:-$HOME/.aseprite-build}" HELP="https://graal.codes/guides/get-aseprite-free" # latest redirect excludes prereleases latest_version() { local u; u="$(curl -fsLI -o /dev/null -w '%{url_effective}' https://github.com/aseprite/aseprite/releases/latest 2>/dev/null)" || return 1; u="${u##*/tag/v}"; [[ "$u" =~ ^[0-9]+(\.[0-9]+)+$ ]] && printf '%s' "$u"; } ASEPRITE_VERSION="${ASEPRITE_VERSION:-$(latest_version || true)}" if [ -z "$ASEPRITE_VERSION" ] && [ -f "$WORK/building" ]; then was="$(tr -cd '0-9.' < "$WORK/building" 2>/dev/null || true)" if [[ "$was" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then ASEPRITE_VERSION="$was"; fi fi ASEPRITE_VERSION="${ASEPRITE_VERSION:-$PINNED}" say() { printf '\n\033[1m%s\033[0m\n' "$*"; } die() { printf '\n\033[31mStopped:\033[0m %s\nHelp: %s\n' "$*" "$HELP" >&2; exit 1; } trap 'die "something went wrong (line $LINENO). Run the same command again to continue where it stopped."' ERR ask() { [ -n "${ASEPRITE_YES:-}" ] && return 0; local a; read -r -p "$1 [Y/n] " a "$WORK/building" [ "$(df -Pk "$WORK" | awk 'NR==2{print $4}')" -gt 2000000 ] || die "this needs about 2 GB of free space. Free some space, then run the same command again." say "Step 1 of 4: Getting the build tools" if [ "$os" = macOS ]; then if ! xcrun --show-sdk-path >/dev/null 2>&1 || ! xcrun -f clang++ >/dev/null 2>&1; then xcode-select --install >/dev/null 2>&1 || true echo "A window will ask to install Apple's tools. Click Install and wait until it says it is done." echo "Then paste the same command again." exit 0 fi mkdir -p tools if ! command -v cmake >/dev/null 2>&1; then fetch "https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-macos-universal.tar.gz" tools/cmake.tar.gz [ -f tools/cmake.ok ] || { rm -rf "tools/cmake-$CMAKE_VERSION-macos-universal"; tar -xzf tools/cmake.tar.gz -C tools || { rm -f tools/cmake.tar.gz; die "could not unpack a download. Run the same command again."; }; touch tools/cmake.ok; } PATH="$WORK/tools/cmake-$CMAKE_VERSION-macos-universal/CMake.app/Contents/bin:$PATH" fi if ! command -v ninja >/dev/null 2>&1; then fetch "https://github.com/ninja-build/ninja/releases/download/v$NINJA_VERSION/ninja-mac.zip" tools/ninja.zip unpack tools/ninja.zip tools/ninja PATH="$WORK/tools/ninja:$PATH" fi else if command -v apt-get >/dev/null 2>&1; then pkgs=(sudo apt-get install -y g++ clang cmake ninja-build unzip curl libx11-dev libxcursor-dev libxi-dev libxrandr-dev libgl1-mesa-dev libfontconfig1-dev) elif command -v dnf >/dev/null 2>&1; then pkgs=(sudo dnf install -y gcc-c++ clang libcxx-devel cmake ninja-build unzip curl libX11-devel libXcursor-devel libXi-devel libXrandr-devel mesa-libGL-devel fontconfig-devel) elif command -v pacman >/dev/null 2>&1; then pkgs=(sudo pacman -S --needed gcc clang cmake ninja unzip curl libx11 libxcursor libxi libxrandr mesa-libgl fontconfig libwebp) elif command -v zypper >/dev/null 2>&1; then pkgs=(sudo zypper install gcc-c++ clang cmake ninja unzip curl libX11-devel libXcursor-devel libXi-devel libXrandr-devel Mesa-libGL-devel fontconfig-devel) else pkgs=() fi if [ ${#pkgs[@]} -gt 0 ]; then if ask "Install the build tools now? It asks for your password."; then [ "${pkgs[1]}" = apt-get ] && { sudo apt-get update || true; } # ignore unrelated apt repository errors "${pkgs[@]}" fi else echo "Install a C++ compiler (clang), CMake, Ninja, unzip and the X11, OpenGL and fontconfig development packages, then run this again." fi for t in clang++ cmake ninja unzip; do command -v "$t" >/dev/null 2>&1 || die "'$t' is not installed."; done fi say "Step 2 of 4: Downloading Aseprite" SRC="$WORK/aseprite-$ASEPRITE_VERSION" fetch "https://github.com/aseprite/aseprite/releases/download/v$ASEPRITE_VERSION/Aseprite-v$ASEPRITE_VERSION-Source.zip" "aseprite-$ASEPRITE_VERSION.zip" unpack "aseprite-$ASEPRITE_VERSION.zip" "$SRC" SKIA_TAG="$(tr -d '[:space:]' < "$SRC/laf/misc/skia-tag.txt")" SKIA="$WORK/skia-$SKIA_TAG-$cpu" fetch "https://github.com/aseprite/skia/releases/download/$SKIA_TAG/Skia-$os-Release-$cpu.zip" "skia-$SKIA_TAG-$cpu.zip" unpack "skia-$SKIA_TAG-$cpu.zip" "$SKIA" say "Step 3 of 4: Building (the long part, 10 to 30 minutes. Lots of text is normal)" args=(-G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DLAF_BACKEND=skia -DSKIA_DIR="$SKIA" -DSKIA_LIBRARY_DIR="$SKIA/out/Release-$cpu" -DSKIA_LIBRARY="$SKIA/out/Release-$cpu/libskia.a") if [ "$os" = macOS ]; then args+=(-DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)") if [ "$cpu" = arm64 ]; then args+=(-DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DPNG_ARM_NEON:STRING=on) else args+=(-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14) fi else # prebuilt Skia needs libstdc++ export CC=clang CXX=clang++ args+=(-DCMAKE_CXX_FLAGS:STRING=-stdlib=libstdc++ -DCMAKE_EXE_LINKER_FLAGS:STRING=-stdlib=libstdc++) fi [ -f "$SRC/build/.configured" ] || rm -f "$SRC/build/CMakeCache.txt" rm -f "$SRC/build/.configured" cmake -S "$SRC" -B "$SRC/build" "${args[@]}" touch "$SRC/build/.configured" cmake --build "$SRC/build" --target aseprite say "Step 4 of 4: Installing" BIN="$SRC/build/bin" if command -v pgrep >/dev/null 2>&1 && pgrep -x aseprite >/dev/null 2>&1; then die "Aseprite is open. Close it, then run the same command again (it finishes much faster this time)." fi if [ "$os" = macOS ]; then BUILT="$BIN/Aseprite.app" [ -x "$BUILT/Contents/MacOS/aseprite" ] || die "the build finished without making Aseprite. Scroll up for the first error." APP="$HOME/Applications/Aseprite.app" mkdir -p "$HOME/Applications" rm -rf "$APP.new" cp -R "$BUILT" "$APP.new" # Info.plist references Aseprite.icns, missing from the source. icon="$WORK/Aseprite.iconset" rm -rf "$icon"; mkdir -p "$icon" for s in 16 32 128 256; do sips -z $s $s "$SRC/data/icons/ase256.png" --out "$icon/icon_${s}x${s}.png" >/dev/null 2>&1 || true; done iconutil -c icns "$icon" -o "$APP.new/Contents/Resources/Aseprite.icns" 2>/dev/null || true rm -rf "$APP.old" if [ -e "$APP" ]; then mv "$APP" "$APP.old"; fi mv "$APP.new" "$APP" rm -rf "$APP.old" touch "$APP" else [ -x "$BIN/aseprite" ] || die "the build finished without making Aseprite. Scroll up for the first error." APP="$HOME/.local/share/aseprite" rm -rf "$APP.new" mkdir -p "$APP.new" "$HOME/.local/bin" "$HOME/.local/share/applications" cp -R "$BIN/aseprite" "$BIN/data" "$APP.new/" if [ -f "$BIN/icudtl.dat" ]; then cp "$BIN/icudtl.dat" "$APP.new/"; fi strip "$APP.new/aseprite" 2>/dev/null || true rm -rf "$APP.old" if [ -e "$APP" ]; then mv "$APP" "$APP.old"; fi mv "$APP.new" "$APP" rm -rf "$APP.old" ln -sf "$APP/aseprite" "$HOME/.local/bin/aseprite" cat > "$HOME/.local/share/applications/aseprite.desktop" </dev/null || true; rm -rf "$old" 2>/dev/null || true ;; esac done if [ "$os" = macOS ]; then say "Done! Aseprite is in your Applications folder." open "$APP" 2>/dev/null || true else say "Done! Aseprite is in your applications menu." [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ] && { (nohup "$APP/aseprite" >/dev/null 2>&1 &) || true; } fi echo "To update later, run the same command again."