Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Sway (a tiling Wayland compositor) on Ubuntu
#!/bin/bash
set -e
# Based on: https://gist.github.com/concatime/265fa14d260f3aa237ddf991d58dd639
mkdir /tmp/setup_sway
cd /tmp/setup_sway
# === Helpers ===
cmd() { hash "$1" 2>/dev/null; }
install() { sudo apt install -y "$@"; }
dep() { cmd "$1" || install "$1"; }
dep_doc() { [ -d "/usr/share/doc/$1" ] || install "$1"; }
# === Install json-c > 0.12
dep autoconf
dep_doc libtool
if [[ $(apt-cache show libjson-c3 |awk '/Version: / {print $2}') =~ '0.12' ]]; then
if [ ! -d '/usr/local/include/json-c' ]; then
git clone 'https://github.com/json-c/json-c.git'
cd 'json-c'
sh autogen.sh
./configure # --enable-threading
make
sudo make install
fi
fi
# === Install common dependencies
dep gcc
dep pkgconf
dep python3
dep_doc python3-pip
dep_doc ninja-build
dep_doc libwayland-dev
dep_doc libinput-dev
dep_doc libcap-dev
dep_doc libsystemd-dev
dep_doc libavutil-dev
dep_doc libavcodec-dev
dep_doc libavformat-dev
dep_doc libxcb-icccm4-dev
[ -x ~/.local/bin/meson ] || pip3 install --user meson
# === Install wlroots dependencies
dep_doc wayland-protocols
dep_doc libegl1-mesa-dev
dep_doc libgles2-mesa-dev
dep_doc libdrm-dev
dep_doc libgbm-dev
dep_doc libxkbcommon-dev
dep_doc libudev-dev
dep_doc libpixman-1-dev
# === Install xwayland/X11 dependencies
dep_doc libxcb-composite0-dev
dep_doc libxcb-xfixes0-dev
dep_doc libxcb-image0-dev
dep_doc libxcb-render0-dev
dep_doc libx11-xcb-dev
# === Install wlroots
PATH=$PATH:~/.local/bin
if [ ! -d /usr/local/include/wlr ]; then
git clone https://github.com/swaywm/wlroots
cd wlroots
meson build
cd build
ninja
sudo ninja install
fi
# === Install sway dependencies
dep_doc libjson-c-dev
dep_doc libpcre3-dev
dep_doc libcairo2-dev
dep_doc libpango1.0-dev
dep_doc libpangocairo-1.0-0
dep_doc libgdk-pixbuf2.0-dev
dep_doc libpam0g-dev
# === Install sway
if [ ! -x /usr/local/bin/sway ]; then
git clone https://github.com/swaywm/sway
cd sway
meson build
cd build
ninja
sudo ninja install
fi
if [[ -d /usr/share/wayland-sessions && ! -e /usr/share/wayland-sessions/sway.desktop ]]; then
echo -e "[Desktop Entry]\nName=Sway\nComment=The Sway tiling window manager\nExec=/usr/local/bin/sway\nType=Application" |sudo tee /usr/share/wayland-sessions/sway.desktop
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment