Skip to content

Instantly share code, notes, and snippets.

@dufferzafar
Created February 28, 2023 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dufferzafar/64ddaabebff0d0f7efe734bc1ab3c7bc to your computer and use it in GitHub Desktop.
Save dufferzafar/64ddaabebff0d0f7efe734bc1ab3c7bc to your computer and use it in GitHub Desktop.
Build tmux
#!/usr/bin/bash
# Last modified: 2022/01/26 08:52:11
# Install latest version of Tmux, libevent, ncurse as root.
# local user install
# tmux will be installed in $BUILD/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# Fix so prompted whatever is missing
# From Version Control, not stable, just most rescent repo compile
# git clone https://github.com/tmux/tmux.git
# cd tmux
# sh autogen.sh
# ./configure
# make && sudo make install
# Install in addition? probably not
# install fonts-powerline
# install powerline
# ** need a font that supports symbols installed on windows, nerd tree infuses hundreds of fonts with symbols
########################
# exit on error #
########################
set -e
########################
# Debug MODE #
########################
# echo $? after exit to see the error code it exited for which ever command
# set -x
################################################
# Updated VERSION Defaults 2022.01.24 #
################################################
TMUX_VERSION=3.3a
LIB_VER=2.1.12
NCUR_VER=6.2
BUILD=/spare/local/szafar/apps/tmux/new
################################################
# Root User Detection - Install System Wide? #
################################################
if [ "$EUID" -eq 0 ]
then read -p "Running script as root, install system wide? [yY] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Installing System Wide!"
SysWide="yes"
sleep 5
fi
fi
################################################
# OS Make and Model to make descisions #
################################################
CurOSstr=$(hostnamectl | grep Operating)
echo $CurOS
if [[ "$CurOSstr" == *"Ubuntu"* ]]; then
echo "Ubuntu, verifying environment!"
echo "Verifying libssl-dev"
# dpkg -s libssl-dev
elif [[ "$CurOSstr" == *"Centos"* ]]; then
echo "Verifying Centos environment"
echo "install openssl-devel"
#rpm -qa | grep openssl-devel
elif [[ "$CurOSstr" == *"Red"* ]]; then
echo "Verifying Red Hat environment"
echo "Verifying openssl-devel"
#rpm -qa | grep openssl-devel
elif [[ "$CurOSstr" == *"Arch"* ]]; then
echo "Verifying Arch environment"
echo "Verifying openssl"
#pacman -Qi openssl
elif [[ "$CurOSstr" == *"Buster"* ]]; then
echo "Verifying Raspberry Pi Buster environment"
echo "Verifying libssl-dev"
# dpkg -s libssl-dev
elif [[ "$CurOSstr" == *"Bullseye"* ]]; then
echo "Verifying Raspberry Pi BullsEye environment"
echo "Verifying libssl-dev"
# dpkg -s libssl-dev
else
echo "Unknown OS, continue trying to install?"
echo "Menu? Develope this area!"
fi
########################################################################
# Clean UP in case issue last time #
########################################################################
[[ -f ~/libevent_org.txt ]] && rm -rf ~/libevent_org.txt
[[ -f ~/github_tmux.txt ]] && rm -rf ~/github_tmux.txt
# [ -d "$BUILD/tmux_tmp" ] && rm -rf $BUILD/tmux_tmp
########################################################################
# Find out what the latest version of libevent is to download. #
########################################################################
echo Querying Versions on https://libevent.org... Please be patient.
wget --no-check-certificate -q "https://libevent.org/" -O ~/libevent_org.txt
sleep 1
LIB_VER_B=$(grep -Pom 1 "(?<=>libevent-)[\d\.]+(?=-stable\.tar\.gz)" ~/libevent_org.txt)
echo # (optional) move to a new line
echo "Detected LibEvent $LIB_VER_B"
echo # (optional) move to a new line
rm -rf ~/libevent_org.txt
################################################
# Find out what the newest version of Tmux is #
################################################
echo "Querying Version on https://github.com/tmux/tmux/releases... Please be patient."
wget --no-check-certificate -q "https://github.com/tmux/tmux/releases" -O ~/github_tmux.txt
sleep 1
TMUX_VER_B=$(grep -Pom 1 "(?<=>tmux-)[\d\.]+(?:\w)(?=\.tar\.gz)" ~/github_tmux.txt)
echo # (optional) move to a new line
echo Detected TMUX $TMUX_VER_B on GitHub
echo # (optional) move to a new line
rm -rf ~/github_tmux.txt
################################################
# NCurse today has a static release name #
################################################
# Adding versioning from archives - https://invisible-mirror.net/archives/ncurses/
echo # (optional) move to a new line
echo "Currently the latest version of NCurses will be installed!"
echo # (optional) move to a new line
################################################
# Display Versions found #
################################################
echo "Static vaules"
echo "Tmux : $TMUX_VERSION"
echo "Libevent : $LIB_VER"
echo "NCUR_VER : $NCUR_VER"
echo # (optional) move to a new line
echo # (optional) move to a new line
echo "DETECTED VERSIONS from WEBSITES"
echo "New Tmux Ver : $TMUX_VER_B"
echo "New Libevent Ver: $LIB_VER_B"
echo "NCURSE : Unable to Detect Versions of NCurse by design"
echo # (optional) move to a new line
echo # (optional) move to a new line
################################################
# Prompt to use new version #
################################################
read -p "Use Updated version's from WEBSITE [yY]? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
TMUX_VERSION=$TMUX_VER_B
LIB_VER=$LIB_VER_B
fi
echo # (optional) move to a new line
echo # (optional) move to a new line
echo # (optional) move to a new line
echo "Versions to be installed are the following: "
echo "Tmux: $TMUX_VERSION"
echo "LibEvent: $LIB_VER"
echo "LibEvent: Latest"
echo # (optional) move to a new line
echo # (optional) move to a new line
# sleep 5
################################################################
# Create the directories for the #
# ~/local and #
# ~/tmux_tmp Build directory #
################################################################
mkdir -p $BUILD/local $BUILD/tmux_tmp
cd $BUILD/tmux_tmp
################################################
# Tmux source Download #
################################################
echo # (optional) move to a new line
echo "Downloading tmux"
wget -q https://github.com/tmux/tmux/releases/download/${TMUX_VERSION}/tmux-${TMUX_VERSION}.tar.gz
echo "Downloaded tmux"
echo # (optional) move to a new line
################################################
# libevent Download #
################################################
echo # (optional) move to a new line
echo "Downloading libevent"
wget -q https://github.com/libevent/libevent/releases/download/release-${LIB_VER}-stable/libevent-${LIB_VER}-stable.tar.gz
echo "Downloaded libevent"
echo # (optional) move to a new line
################################################
# NCurses Download #
################################################
echo # (optional) move to a new line
echo "Downloading ncurse"
# wget -q ftp://ftp.invisible-island.net/ncurses/ncurses.tar.gz
wget -q https://ftp.gnu.org/pub/gnu/ncurses/ncurses-${NCUR_VER}.tar.gz
echo "Downloaded ncurse"
echo # (optional) move to a new line
################################################
# # #
################################################ #
# Extract files, Configure, and Compile # #
################################################ #
# # #
################################################
# sleep 5
################################################
# Libevent Extraction #
################################################
tar xvzf libevent-${LIB_VER}-stable.tar.gz
cd libevent-${LIB_VER}-stable
if [[ $SysWide == "yes" ]]; then
./configure --disable-shared
else
./configure --prefix=$BUILD/local --disable-shared
fi
make -j
make install
cd ..
####################################
# Ncurses Extraction #
####################################
tar xvzf ncurses-${NCUR_VER}.tar.gz
# change to cd ncurses*/ ???
# ncursedir=$(find . -maxdepth 1 -type d -name '*ncur*' -print -quit)
cd ncurses-${NCUR_VER} # since I can't get the version number and can't CD into it based on a captured version
if [[ $SysWide == "yes" ]]; then
./configure
else
./configure --prefix=$BUILD/local
fi
make -j
make install
cd ..
###################################
# Tmux Extraction #
###################################
tar xvzf tmux-${TMUX_VERSION}.tar.gz
cd tmux-${TMUX_VERSION}
if [[ $SysWide == "yes" ]]; then
./configure
make -j
make install
else
./configure CFLAGS="-I$BUILD/local/include -I$BUILD/local/include/ncurses" LDFLAGS="-L$BUILD/local/lib -L$BUILD/local/include/ncurses -L$BUILD/local/include"
CPPFLAGS="-I$BUILD/local/include -I$BUILD/local/include/ncurses" LDFLAGS="-static -L$BUILD/local/include -L$BUILD/local/include/ncurses -L$BUILD/local/lib" make -j
cp -f tmux $BUILD/local/bin
fi
cd ..
############################
# cleanup Section #
############################
rm -rf $BUILD/tmux_tmp
echo # (optional) move to a new line
echo # (optional) move to a new line
echo # (optional) move to a new line
echo # (optional) move to a new line
echo # (optional) move to a new line
echo # (optional) move to a new line
printf '\033c' # Clear screen
echo # (optional) move to a new line
if [[ $SysWide == "yes" ]]; then
echo "Installed System Wide."
else
echo "$BUILD/local/bin/tmux is now available. You can optionally add $BUILD/local/bin to your PATH."
fi
exit $?
####################################################################################################################################
# END #
####################################################################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment