Skip to content

Instantly share code, notes, and snippets.

@nathanross
Last active February 23, 2017 20:14
Show Gist options
  • Save nathanross/c962de32be11a93d0444 to your computer and use it in GitHub Desktop.
Save nathanross/c962de32be11a93d0444 to your computer and use it in GitHub Desktop.
Install Sway on Debian Jessie
#!/bin/bash
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License can be found at <http://www.gnu.org/licenses/>.
# Proof-of-concept installation script for sway on debian 8.x ("jessie")
# on an amd64 pc. debian jessie is the current "debian stable"
# this can be run as a script, but bash is fragile and this may not
# work depending on the particularities of your setup, so I would suggest
# just treating it as a guide so if at some point something doesn't
# work at one step of a process, it's very clear where and why.
main() {
asRoot
getRecentCmake
getRecentWayland
installWlc
installSway
}
getRecentCmake() {
# cmake from website is statically linked
# whereas installing it from stretch means installing dynamic
# libs as well as upgrading packages that the newer version
# may make use of the newer cmake, but the newer version
# is not necessary to install sway. e.g. libreoffice.
if [[ -e /usr/bin/cmake && ! `cmake --version | grep -i 3.0` ]]; then return 0; fi
log 1 "getting recent Cmake (stable+backports has 3.0.2, 3.1 is expected)"
CMAKE_URL=https://cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz
CMAKE_ARCHIVE=`basename $CMAKE_URL`
mkdtmp dirCmake
log 2 "downloading ... this may take several seconds."
wget -q $CMAKE_URL -O $dirCmake/$CMAKE_ARCHIVE
tar xf $dirCmake/$CMAKE_ARCHIVE -C $dirCmake
log 2 "extracting"
extractedTo=$dirCmake/`basename $CMAKE_ARCHIVE .tar.gz`
cp -R $extractedTo/* /
cp -R $extractedTo/bin/* /usr/bin/
for f in cmake ccmake cpack cpack-gui ctest;
do
rm -f /usr/bin/$f
ln -s /bin/$f /usr/bin/$f
done
cd /tmp
rm -r $dirCmake
}
getRecentWayland() {
# You will need a newer version, or the cmake will pass but the
# make will fail as the code will not compile correctly.
#if we already have a recent enough version, skip.
waylandHeader=/usr/include/wayland-server-protocol.h
if [[ -e $waylandHeader && `grep -Ei "release.*data device" $waylandHeader` ]]; then return 0; fi
log 1 "getting recent Wayland (stable+backports has 1.6, 1.9 is expected) and other Wlc dependencies as needed"
echo "deb http://http.debian.net/debian stretch main contrib" > /etc/apt/sources.list.d/stretch.list
log 2 "adding debian stretch repo and running apt-get update"
apt-get -qq update
# libdrm is not part of wayland, but a more recent version is also
# required by wlc, so it's also fetched here.
log 2 "installing packages"
apt-get -qqy install libgles2-mesa-dev libdrm2 libdrm-dev libegl1-mesa-dev xwayland || exit 1
rm /etc/apt/sources.list.d/stretch.list
log 2 "rm debian stretch repo and running apt-get update"
apt-get -qqy update
}
installWlc() {
#if we already have wlc we can skip this.
if [ -e /usr/include/wlc ]; then return 0; fi
log 1 "getting WLC"
mkdtmp dirWlc
while [ ! -e $dirWlc ]; do
sleep 0.01
done
log 2 "cloning repo"
git clone --quiet https://github.com/Cloudef/wlc.git $dirWlc
cd $dirWlc
git submodule update --quiet --init --recursive || exit 1
log 2 "installing dependencies for which only trusty v. is req'd "
apt-get -qqy install build-essential libinput5 libinput-dev libxkbcommon0 libxkbcommon-dev libudev-dev libxcb-ewmh-dev libxcb-image0 libxcb-image0-dev libxcb-composite0 libxcb-composite0-dev libxcb-xkb1 libxcb-xkb-dev libgbm1 libgbm-dev libdbus-1-dev libsystemd-dev zlib1g-dev libpixman-1-dev || exit 1
mkdir target
cd target
log 2 "configuring"
export errlog=`cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/ .. 2>&1` || dumpErrlog
log 2 "compiling and installing "
export errlog=`make 2>&1 && make install 2>&1` || dumpErrlog
cd /tmp
rm -r $dirWlc
}
installSway() {
# we don't do an idempotency check here because we're assuming
# a user would only run this script if they to install the latest
# version of sway. Making a script that was both idempotent
# and allowed for easy upgrading of sway would require the
# use of args or env. variables; it's a complexity tradeoff.
log 1 "getting Sway"
mkdtmp dirSway
while [ ! -e $dirSway ]; do
sleep 0.01
done
log 2 "cloning repo"
git clone --quiet https://github.com/SirCmpwn/sway.git $dirSway
log 2 "installing dependencies"
apt-get -qqy install libpcre3 libpcre3-dev libcairo2 libcairo2-dev libpango1.0-0 libpango1.0-dev asciidoc libjson-c2 libjson-c-dev || exit $?
log 2 "configuring"
cd ${dirSway}
export errlog=`cmake ${dirSway} . 2>&1` || dumpErrlog
log 2 "compiling and installing "
export errlog=`make 2>&1 && make install 2>&1` || dumpErrlog
log 1 "complete. as your regular username (not root) please create your sway config"
log 1 "if you have never used i3 or sway copy /etc/sway/config to ~/.config/sway/config/ (you may need to make the directory first) "
log 1 "if you have used i3 and have a config, copy ~/.i3/config to ~/.config/sway/config/ (you may need to make the directory first) "
cd /tmp
rm -r $dirSway
}
dumpErrlog() {
echo -e $errlog
exit 1
}
log() {
i=0;
while [ $i -lt $1 ]; do
printf "\t"
i=`expr $i + 1`
done
echo -ne "$2\n"
}
asRoot() {
#in most cases to install systemwide you will need root privileges
if [ `whoami` != "root" ];
then
echo "error: you must run this script as root"; exit 1;
fi
}
mkdtmp() {
# utility function used by other functions to create temporary directories
# in tmp to avoid name conflicts
local -n l=$1;
l=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`;
}
main $@
@varun-magesh
Copy link

This didn't occur to me; I did now though and the expected command is being run with the same fatal error given. This did also reveal that the WLC compile is also failing because of an unknown field ‘release’ specified in initializer .release = wlc_cb_resource_destructor.

@nathanross
Copy link
Author

Thanks for noting the issue @LordPharaoh; the script now moves out of temporary directories after it's done working in them, which should resolve the error you're getting on line 118.

To those reporting an issue: if this script is not working for you, (as I just found out) github Gist does not allow you to watch gist comment threads, so please ping me by typing @nathanross in your comment. (edit: nevermind, that also does not cause a mention on gist. Perhaps I should move this to an actual repo)

In regard to the WLC compile, that's probably actually due to the getRecentWayland function not completing correctly. If you're available to do so and can still reproduce the error, could you give me the results of dpkg -s xwayland? Thanks.

@varun-magesh
Copy link

Thank you for the fix @nathanross.

Package: xwayland
Status: install ok installed
Priority: optional
Section: x11
Installed-Size: 4089
Maintainer: Debian X Strike Force <debian-x@lists.debian.org>
Architecture: amd64
Source: xorg-server
Version: 2:1.17.3-2
Depends: xserver-common (>= 2:1.17.3-2), libaudit1 (>= 1:2.2.1), libc6 (>= 2.17), libdrm2 (>= 2.3.1), libegl1-mesa (>= 7.8.1) | libegl1-x11, libepoxy0 (>= 1.0), libgbm1 (>= 10.2~0), libgcrypt20 (>= 1.6.1), libgl1-mesa-glx | libgl1, libpixman-1-0 (>= 0.30.0), libselinux1 (>= 2.0.82), libwayland-client0 (>= 1.3.92), libxau6, libxdmcp6, libxfont1 (>= 1:1.4.2), libxshmfence1
Description: Xwayland X server
 This package provides an X server running on top of wayland, using wayland
 input devices for input and forwarding either the root window or individual
 top-level windows as wayland surfaces.
Homepage: http://www.x.org/

Edit: There's your problem; /tmp/tmp.EvwdiAQzfP/src/compositor/seat/data.c:109:4: error: unknown field ‘release’ specified in initializer .release = wlc_cb_resource_destructor. If I'm not mistaken, this is an error on the part of the Makefile and/or my system (will investigate); not this script.
Edit 2: Formatting
Edit 3: To clarify, that was the error that stopped WLC from compiling.

@leon-vv
Copy link

leon-vv commented Feb 5, 2016

@nathanross I have written an installation guide in which I have used some commands from your script. I hope this is okay with you. Also I would like to add that CMake refused to generate the Makefiles for Wlc until I installed the lib-xcb-emwh-dev package. You might want to add this package as a dependency.

@nathanross
Copy link
Author

@leon-vv, perfectly fine, and thank you for the heads-up about the library. I've added it to the script.

@Cretezy
Copy link

Cretezy commented Nov 10, 2016

This script doesn't work because libgbm1 is a higher version than libgbm-dev, and both are trying to be installed.

To fix this, simple remove libgbm-dev from the install list in WLC, as I made to my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment