diff --git a/README.md b/README.md index d8d36e8..d858514 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ Please consider giving this repo a star if you found it helpful. If you encounter any errors, please report it in the issues tab. ## Where is the executable? -The executable is stored in ~/Applications/aseprite. Have fun! +The executable is stored in $XDG_DATA_HOME/aseprite. Have fun! -## Integrating with your desktop environment -Download the aseprite.desktop file from this GitHub repository and move it to ~/.local/share/applications. -Then, it should appear in your application menu! +## How do I run Aseprite? +This script should automatically add aseprite to your application menu and to your path. +You should be able to launch it as you would any other software. ## Credits I condensed https://github.com/aseprite/aseprite/blob/main/INSTALL.md into this script. diff --git a/aseprite.desktop b/aseprite.desktop deleted file mode 100644 index 09eef2a..0000000 --- a/aseprite.desktop +++ /dev/null @@ -1,9 +0,0 @@ -[Desktop Entry] -Name=Aseprite -GenericName=Pixel Art Editor -Exec=~/Applications/aseprite/aseprite -Terminal=false -Icon=~/Applications/aseprite/data/icons/ase256.png -Type=Application -Categories=Graphics -StartupWMClass=aseprite diff --git a/compile.sh b/compile.sh old mode 100644 new mode 100755 index ad34502..b08ed52 --- a/compile.sh +++ b/compile.sh @@ -1,22 +1,48 @@ #!/bin/bash -# Check distro -os_name=$(grep 'NAME=' /etc/os-release | head -n 1 | sed 's/NAME=//' | tr -d '"') +[[ -z "${XDG_DATA_HOME}" ]] && XDG_DATA_HOME="${HOME}/.local/share" +INSTALL_DIR="${XDG_DATA_HOME}/aseprite" +BINARY_DIR="${HOME}/.local/bin" +LAUNCHER_DIR="${XDG_DATA_HOME}/applications" +ICON_DIR="${XDG_DATA_HOME}/icons" -# Return to home directory -cd +SIGNATURE_FILE="${INSTALL_DIR}/compile-aseprite-linux" +BINARY_FILE="${BINARY_DIR}/aseprite" +LAUNCHER_FILE="${LAUNCHER_DIR}/aseprite.desktop" +ICON_FILE="${ICON_DIR}/aseprite.png" -# Download skia -wget https://github.com/aseprite/skia/releases/download/m102-861e4743af/Skia-Linux-Release-x64-libc++.zip -mkdir -p ~/deps/skia -unzip Skia-Linux-Release-x64-libc++.zip -d ~/deps/skia -# Clean up zip file -rm Skia-Linux-Release-x64-libc++.zip +if [[ -f "${SIGNATURE_FILE}" ]] ; then + read -e -p "aseprite already installed. update? (y/n): " choice + [[ "${choice}" == [Yy]* ]] \ + || exit 0 +else + [[ -d "${INSTALL_DIR}" ]] \ + && { echo "aseprite already installed to '${INSTALL_DIR}'. aborting" >&2 ; exit 1 ; } + { [[ -f "${LAUNCHER_FILE}" ]] || [[ -f "${BINARY_FILE}" ]] || [[ -f "${ICON_FILE}" ]] ; } \ + && { echo "other aseprite data already installed to home directory. aborting" >&2 ; exit 1 ; } +fi +WORK_DIR=$(mktemp -d -t 'compile-aseprite-linux-XXXXX') \ + || { echo "unable to create temp folder" >&2 ; exit 1 ; } -echo "Enter sudo password to install dependencies. This is also a good time to plug in your computer, since compiling will take a long time." +cleanup() { + code=$? + echo "cleaning up" + pushd -0 >/dev/null + dirs -c + rm -rf "${WORK_DIR}" + exit "${code}" +} +trap "cleanup" EXIT + +pushd "${WORK_DIR}" + +# Check distro +os_name=$(grep 'NAME=' /etc/os-release | head -n 1 | sed 's/NAME=//' | tr -d '"') + +echo "Enter sudo password to install dependencies. This is also a good time to plug in your computer, since compiling will take a long time." # Assign package manager to a variable if [[ "$os_name" == *"Fedora"* ]]; then @@ -31,41 +57,60 @@ fi # Install dependencies if [[ $package_man == "dnf" ]]; then - sudo dnf install -y gcc-c++ clang libcxx-devel cmake ninja-build libX11-devel libXcursor-devel libXi-devel mesa-libGL-devel fontconfig-devel git + sudo dnf install -y gcc-c++ clang libcxx-devel cmake ninja-build libX11-devel libXcursor-devel libXi-devel mesa-libGL-devel fontconfig-devel git elif [[ $package_man == "apt" ]]; then - sudo apt-get install -y g++ clang libc++-dev libc++abi-dev cmake ninja-build libx11-dev libxcursor-dev libxi-dev libgl1-mesa-dev libfontconfig1-dev git + sudo apt-get install -y g++ clang libc++-dev libc++abi-dev cmake ninja-build libx11-dev libxcursor-dev libxi-dev libgl1-mesa-dev libfontconfig1-dev git fi +[[ $? == 0 ]] \ + || { echo "failed to install dependencies" >&2 ; exit 1 ; } + # Clone aseprite -git clone --recursive https://github.com/aseprite/aseprite.git --depth=1 +git clone --recursive https://github.com/aseprite/aseprite.git --depth=1 \ + || { echo "unable to clone code base" >&2 ; exit 1 ; } + +# Download skia +wget https://github.com/aseprite/skia/releases/download/m102-861e4743af/Skia-Linux-Release-x64-libc++.zip \ + || { echo "failed to download skia" >&2 ; exit 1 ; } +mkdir ./skia && unzip Skia-Linux-Release-x64-libc++.zip -d ./skia \ + || { echo "failed to extract skia" >&2 ; exit 1 ; } echo "Finished downloading! Time to compile." -cd aseprite -mkdir build -cd build +mkdir aseprite/build \ + || { echo "failed create build folder" >&2 ; exit 1 ; } +pushd aseprite/build + export CC=clang export CXX=clang++ cmake \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DCMAKE_CXX_FLAGS:STRING=-stdlib=libc++ \ - -DCMAKE_EXE_LINKER_FLAGS:STRING=-stdlib=libc++ \ - -DLAF_BACKEND=skia \ - -DSKIA_DIR=$HOME/deps/skia \ - -DSKIA_LIBRARY_DIR=$HOME/deps/skia/out/Release-x64 \ - -DSKIA_LIBRARY=$HOME/deps/skia/out/Release-x64/libskia.a \ - -G Ninja \ - .. -ninja aseprite - -# Cleanup -cd -rm -rf deps - -mkdir -p Applications/aseprite - -mv aseprite/build/bin aseprite/build/aseprite -mv aseprite/build/aseprite ~/Applications/aseprite + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_CXX_FLAGS:STRING=-stdlib=libc++ \ + -DCMAKE_EXE_LINKER_FLAGS:STRING=-stdlib=libc++ \ + -DLAF_BACKEND=skia \ + -DSKIA_DIR="${WORK_DIR}/skia" \ + -DSKIA_LIBRARY_DIR="${WORK_DIR}/skia/out/Release-x64" \ + -DSKIA_LIBRARY="${WORK_DIR}/skia/out/Release-x64/libskia.a" \ + -G Ninja \ + .. \ + || { echo "configuration failed" >&2 ; exit 1 ; } + +ninja aseprite \ + || { echo "compilation failed" >&2 ; exit 1 ; } + +popd + +rm -rf "${INSTALL_DIR}" \ + || { echo "unable to clean up old install" >&2 ; exit 1 ; } +mkdir -p "${INSTALL_DIR}" "${BINARY_DIR}" "${LAUNCHER_DIR}" "${ICON_DIR}" \ + || { echo "unable to create install folder" >&2 ; exit 1 ; } + +{ mv aseprite/build/bin/* "${INSTALL_DIR}" \ + && touch "${SIGNATURE_FILE}" \ + && ln -sf "${INSTALL_DIR}/aseprite" "${BINARY_FILE}" \ + && ln -sf "${INSTALL_DIR}/data/icons/ase256.png" "${ICON_FILE}" \ + && cp -f "${WORK_DIR}/aseprite/src/desktop/linux/aseprite.desktop" "${LAUNCHER_FILE}" \ +; } || { echo "failed to complete install" >&2 ; exit 1 ; } + echo "Done compiling!" -echo "The executable is stored in ~/Applications/aseprite. Have fun!" -echo "You can move this folder anywhere." +echo "The executable is stored in '${INSTALL_DIR}'. Have fun!"