Created
May 20, 2017 21:06
-
-
Save DaoWen/d9c54a43a4b5d5a763a4f6c8cc02db3f to your computer and use it in GitHub Desktop.
Script for installing tmux in your home directory (no root)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script for installing tmux on systems where you don't have root access. | |
# tmux will be installed in $INSTALL_PREFIX/bin. | |
# It's assumed that wget and a C/C++ compiler are installed. | |
# exit on error | |
set -e | |
TMUX_VERSION=2.2 | |
BUILD_NCURSES=true | |
LIBEVENT_VERSION=2.0.22-stable | |
echo "Installing tmux to ${INSTALL_PREFIX:=$HOME/local}" | |
# Check if ncurses is already installed | |
if ldconfig -p | fgrep -q libncurses; then | |
BUILD_NCURSES=false | |
fi | |
# create our directories | |
mkdir -p $INSTALL_PREFIX $HOME/tmux_tmp | |
cd $HOME/tmux_tmp | |
WGET="wget --no-check-certificate" | |
function download_file { | |
$WGET -O $2 $1/$2 | |
} | |
# download source files for tmux, libevent, and ncurses | |
download_file https://github.com/tmux/tmux/releases/download/${TMUX_VERSION} tmux-${TMUX_VERSION}.tar.gz | |
download_file https://github.com/libevent/libevent/releases/download/release-${LIBEVENT_VERSION} libevent-${LIBEVENT_VERSION}.tar.gz | |
$BUILD_NCURSES && download_file ftp://ftp.gnu.org/gnu/ncurses ncurses-5.9.tar.gz | |
# extract files, configure, and compile | |
############ | |
# libevent # | |
############ | |
tar xvzf libevent-${LIBEVENT_VERSION}.tar.gz | |
cd libevent-${LIBEVENT_VERSION} | |
./configure --prefix=$INSTALL_PREFIX --disable-shared | |
make | |
make install | |
cd .. | |
############ | |
# ncurses # | |
############ | |
if $BUILD_NCURSES; then | |
tar xvzf ncurses-5.9.tar.gz | |
cd ncurses-5.9 | |
./configure --prefix=$INSTALL_PREFIX | |
make | |
make install | |
cd .. | |
fi | |
############ | |
# tmux # | |
############ | |
tar xvzf tmux-${TMUX_VERSION}.tar.gz | |
cd tmux-${TMUX_VERSION} | |
./configure CFLAGS="-I$INSTALL_PREFIX/include -I$INSTALL_PREFIX/include/ncurses" LDFLAGS="-L$INSTALL_PREFIX/lib -L$INSTALL_PREFIX/include/ncurses -L$INSTALL_PREFIX/include" | |
CPPFLAGS="-I$INSTALL_PREFIX/include -I$INSTALL_PREFIX/include/ncurses" LDFLAGS="-static -L$INSTALL_PREFIX/include -L$INSTALL_PREFIX/include/ncurses -L$INSTALL_PREFIX/lib" make | |
cp tmux $INSTALL_PREFIX/bin | |
cd .. | |
########################### | |
# CREATE TMUX CONFIG FILE # | |
########################### | |
TMUX_CONF=$HOME/.tmux.conf | |
if ! [ -e $TMUX_CONF ]; then | |
echo "unbind C-b" >> $TMUX_CONF | |
echo "set -g prefix C-a" >> $TMUX_CONF | |
echo "bind-key a send-prefix" >> $TMUX_CONF | |
echo "bind-key C-a last-window" >> $TMUX_CONF | |
fi | |
# cleanup | |
rm -rf $HOME/tmux_tmp | |
echo "$INSTALL_PREFIX/bin/tmux is now available. You can optionally add $INSTALL_PREFIX/bin to your PATH." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment