New wiki for new addon tmux

Questions to IPFire Addons.
ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

New wiki for new addon tmux

Post by ummeegge » January 2nd, 2015, 1:50 pm

Hi all,
i wanted to introduce a new wiki for the upcoming release of core 87 which contains also a new addon called tmux.

In here --> http://wiki.ipfire.org/en/addons/tmux/start the english wiki can be found.

In here --> http://wiki.ipfire.org/de/addons/tmux/start the german wiki can be found.

It might be great if someone can take a look over it for potential corrections or enhancements.

Greetings,

UE

EDIT(s):
- Changed Core version since security updates needed Core 86
--> Add in here the current state of the development in this thread -->
In- and uninstaller for an example tmux configuration and a pane, window and session arranger script. Installer offers also a Bash prompt modification so a time stamp will be also seen in the prompt and do not need to be integrated into tmux statusbar (more space in it). Installer differs a little to this one --> https://forum.ipfire.org/viewtopic.php? ... =15#p80773 but is in generall the same.

In- and Uninstaller script:

Code: Select all

#!/bin/bash -

#
# Script checks for /root/.tmux.conf file and installs it if not presant.
# Integrates tmux bash script for pane and window structure.
# Special layout of tmux will be executed by the script,
# which will be placed under /usr/bin with the name 'mux'.
# Uninstaller is meanwhile also available.
# Modification of the Bash prompt will also be provided by the script
#
# ummeegge 13.02.2015
#######################################################################
# mtr, iftop, bwm-ng and iptraf-ng and tmux will be used by the script,
# and will be installed if they are not presant.
# 3 windows with different structur and content will be created.
#

# Paths
CONF="${HOME}/.tmux.conf";
SCRIPT="/usr/bin/mux";
BASH="${HOME}/.bashrc";

# Needed Addons
BWM="/usr/bin/bwm-ng";
IFT="/usr/sbin/iftop";
MTR="/usr/sbin/mtr";
IPT="/usr/sbin/iptraf-ng";
TMUX="/usr/bin/tmux";

# Date
date=$(date +"%m-%d-%T");

## Functions
bashrc_funct() {
    # Modify Bash prompt so there is no need to display time in tmux statusbar
    clear;
    echo "Would you like to modify your Bash prompt to display also the current time in it ?";
    echo "The unsinstaller will remove this, but you need to logout and login again that changes takes affect.";
    echo;
    echo "You can also modify or delete the 'export PS1' line in ~/.bashrc which is responsible for that... ";
    echo;
    read -p "To modify your Bash prompt press 'y' and [ENTER]. If you don´t want this, press '"n"' and [ENTER]: " answer
    case $answer in
        y)
            echo;
            clear;
            echo "BackUP existing .bashrc... ";
            cp -v ${BASH} ${BASH}.bckOrig;
            echo;
            echo "Will change the Bash prompt under ${HOME}/.bashrc... ";
            echo;
            sleep 5;
            cat >> ${BASH} << "EOF"

# Tmux installer script entry to enter additional infos into the Bash prompt
export PS1="\e[1;37m[\[\e[0;36m\]\d \t\e[1;37m] \e[1;37m[\[\e[0;36m\]\u@\H\[\e[1;37m] \e[1;32m\] \w\[\e[0;32m\] \n-> "
EOF
        ;;

        n)
            echo;
            echo "Will go for further processing without modifying ${HOME}/.bashrc... ";
            echo;
            sleep 3;
        ;;
    esac
}

# Configuration function
config_funct() {
    # Check for conf and add it if not presant
if [[ -e "${CONF}" ]]; then
    clear;
    echo "Have found a Tmux configuration file... ";
    echo;
    read -p "If you want to backUP the existing tmux.conf press 'y' and [ENTER]. If you want to overwrite it press '"n"' and [ENTER]: " answer
        case $answer in
            y)
                echo;
                echo "Will backUP existing tmux.conf and copy new one to ${HOME}... ";
                echo;
                sleep 5;
                cp -v ${CONF} ${CONF}.bck_${date};
            ;;
                   
            n)
                echo;
                echo "Will overwrite .tmux.conf under ${HOME}... ";
                echo;
                sleep 5;
            ;;
                   
        esac
fi

# Copy tmux.conf into HOME dir
cat > ${CONF} << "EOF"
# tmux configuration file
# should takes place under ~/ as .tmux.conf
###########################################
# ummeegge 04.01.2014
#

# set defaults
set-option -g default-shell "/bin/bash"
set-option -g default-command "bash -l"
set-option -g default-terminal "screen-256color"
#

# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
#

# reload config
bind r source-file ~/.tmux.conf \; display-message "Reload config file..."
#

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
#

# Set scrollback to 10000 lines
set -g history-limit 10000
#

#

# Status bar
# set color for status bar
set-option -g status-bg colour235 #base02
set-option -g status-fg yellow #yellow
set-option -g status-attr dim
# Show host name and IP address on left side of status bar
set -g status-left-length 70
set -g status-left "#[fg=green] #h - #[fg=brightred]#(curl -s https://api.ipify.org; echo) #[fg=green]|"

# Define right statusbar lenght
set -g status-right-length 60
# Show value of logged on users, how much RAM is free and clock currently activated
set -g status-right "#[fg=green]| #[fg=yellow]Users:#[fg=brightred]#(who | wc -l)#[fg=green] - #[fg=yellow]Mem:#[fg=brightred]#(free -m | awk '/Mem:/ {print $4}')#[fg=yellow]MB Free#[fg=green] - #[fg=yellow]Use:#[fg=brightred]#(df -m /var | tail -1 | awk '{print $5}')#[fg=yellow]in /var "
# Center window tabs
set -g status-justify centre
#

# Colorize active pane
set-option -g pane-active-border-fg blue
#

## End tmux.conf

EOF
}

## Start installer
# Installer menu
while true
do

    # Choose installation
    clear;
    echo "+----------------------------------------------------------------------+                 ";
    echo "|               Welcome to Tmux on IPFire installation                 |                 ";
    echo "+----------------------------------------------------------------------+                 ";
    echo;
    echo -e "    If you want to install network template press    \033[1;36m'n'\033[0m and [ENTER] ";
    echo -e "    If you want to install hardware template press   \033[1;36m'h'\033[0m and [ENTER] ";
    echo -e "    If you want to uninstall Tmux installation press \033[1;36m'u'\033[0m and [ENTER] ";
    echo;
    echo    "+----------------------------------------------------------------------+";
    echo -e "      If you want to quit this installation press    \033[1;36m'q'\033[0m and [ENTER] ";
    echo    "+----------------------------------------------------------------------+";
    echo;
    read choice
    clear;

    case ${choice} in
        n*|N*|network*|Network*|NETWORK*)

            ## Start installer
            clear;
            echo "Check for needed Addons... ";
            echo;
            sleep 3;
            if [[ ! -e ${BWM} || ! -e ${IFT} || ! -e ${MTR} || ! -e ${IPT} || ! -e ${TMUX} ]]; then
                pakfire install bwm-ng iftop mtr iptraf-ng tmux;
            fi

            # Check for session, pane and window arranger script
            if [[ -e "${SCRIPT}" ]]; then
                echo;
                read -p "If you want to backUP your existing mux script press 'y' and [ENTER]. If you want to overwrite it press '"n"' and [ENTER]: " answer
                case $answer in
                    y)
                        echo;
                        clear;
                        echo "Will backUP existing mux script under /usr/bin... ";
                        echo;
                        cp -v ${SCRIPT} ${SCRIPT}.bck_${date};
                    ;;
       
                    n)
                        echo;
                        echo "Will overwrite mux script under /usr/bin... ";
                        echo;
                        sleep 5;
                    ;;
                esac
            fi

            # Copy script into file
            cat > ${SCRIPT} << "EOF"
#!/bin/bash -

#
# Example script has been taken from ubuntu wiki
# http://wiki.ubuntuusers.de/tmux
####################################################
# With a litle modification from ummeegge 17.01.2014
#

SESSION=main
tmux="tmux -f /root/.tmux.conf"

# if the session is already running, just attach to it.
$tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
       echo "Session $SESSION already exists. Attaching."
       sleep 1
       $tmux attach -t $SESSION
       exit 0;
fi
                                 
# create a new session, named $SESSION, and detach from it
$tmux new-session   -d -s $SESSION
# Window 0
$tmux new-window    -t $SESSION:0
$tmux rename-window 'TrafficCheck'

# Window 1
$tmux split-window -d -t 0 -v
$tmux split-window -d -t 1 -h

$tmux send-keys -t 0 'iftop' enter C-1
$tmux send-keys -t 1 'mtr 8.8.8.8' enter C-1
$tmux send-keys -t 2 'bwm-ng' enter C-1

# Window 2
$tmux new-window    -t $SESSION:1
$tmux rename-window 'TmuxYourself;-)'

$tmux split-window -d -t 0 -v
$tmux split-window -d -t 1 -h
$tmux split-window -d -t 0 -h

# Window 3
$tmux new-window    -t $SESSION:2
$tmux rename-window 'IPTraf-ng'
$tmux send-keys -t $SESSION:2 'iptraf-ng' enter C-1

# Select entry window
$tmux select-window -t $SESSION:0
$tmux attach -t $SESSION

## End of tmux script

EOF

            # Make mux executable
            chmod +x ${SCRIPT};
            # bashrc entry
            bashrc_funct;
            # add config
            config_funct;
            rm -rf /tmp/tmux-0;
            echo "Installer is finished now... ";
            echo;
            # Start if you´d like
            read -p "To start now mux press [ENTER] . To quit use [CTRL-c] ."
            mux;
            exit 0;
        ;;
       
        h*|H*|hardware*|Hardware*|HARDWARE*)

            # Start hardware monitoring installer
            echo;
            echo "This is currently under development may by you ;-) ?... ";
            echo;
            sleep 3;
        ;;
       
        u*|U*|uninstall*|Uninstall*|UNINSTALL)

            # Start uninstaller
            tmux kill-server;
            rm -rfv \
            "${SCRIPT}" \
            "${CONF}" \
            /tmp/tmux-*;
            mv -v ${BASH}.bckOrig ${BASH};
            read -p "To remove related Addons press 'r' and [ENTER]. To leave them in place press '"l"' and [ENTER]: " answer
                case $answer in
                    r)
                        pakfire remove iptraf-ng bwm-ng iftop mtr tmux;
                    ;;
                   
                    l)
                        echo;
                        echo "Will leave related Addons in place... ";
                        echo;
                    ;;
                   
                esac
            echo;
            echo "Uninstaller has been finished... ";
            echo;
            echo "Goodbye";
            echo;
            exit 0;
           
        ;;
       
        q*|Q*|quit*|Quit*|QUIT*)
            echo;
            echo "Goodbye";
            echo;
            exit 0;
        ;;
       
        *)
            echo;
            echo "This option does not exist... ";
            echo;
            sleep 3;
        ;;
       
    esac
done

## End of Tmux script and config installer

don´t forget to make the script executable with a chmod +x {scriptname}. You can execute it than with a ./{scriptname} .

EDIT: The mouse options seems to do not work with the tmux-2.3 so i deleted it
- Added HTTPS provider to investigate external IP.

bloater99
Posts: 482
Joined: October 13th, 2014, 3:47 pm

Re: New wiki for new addon tmux

Post by bloater99 » January 2nd, 2015, 10:16 pm

The English version is very understandable. I don't see any critical changes that need to be made. Looks like a nice added feature! :)

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » January 5th, 2015, 4:32 pm

Thanks bloater99 for checking this out. I have added now an english manpage for tmux cause there was only an german howto from Ubuntu wiki in the english section which i forgot to changed it appropriatly. Think this should be enough for the wiki, will see ;) .

Greetings,

UE

XerXes
Posts: 157
Joined: February 19th, 2011, 3:11 pm
Location: Germany

Re: New wiki for new addon tmux

Post by XerXes » January 6th, 2015, 5:49 am

Is it may be possible to add the config-file for the example screenshot to the wiki?

I think it makes it allot easier to edit an existing config-file than to start from scratch.

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » January 6th, 2015, 8:09 pm

Hi XerXes,
XerXes wrote:Is it may be possible to add the config-file for the example screenshot to the wiki?

I think it makes it allot easier to edit an existing config-file than to start from scratch.

good idea. I´am currently on the move but if i´am back home i can add one to the wiki as an example, or may if you got one you can add it too !?

UE

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » January 14th, 2015, 3:12 pm

Hi all,
have arranged a smaller config file now for tmux, this could be now a next step to make things a littler more handy for people which needs to start from scratch with tmux and if you find this might be a good idea we could go for further steps with the possibility to bring it may also into the wiki.

Tmux configuration file takes place in ~/.tmux.conf :

Code: Select all

# tmux configuration file
# should takes place under ~/ as .tmux.conf
########################################
# ummeegge 04.01.2014
#

# set defaults
set-option -g default-shell "/bin/bash"
set-option -g default-command "bash -l"
set-option -g default-terminal "screen-256color"
#

# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
#

# reload config
bind r source-file ~/.tmux.conf \; display-message "Reload config file..."
#

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
#

# Set scrollback to 10000 lines
set -g history-limit 10000
#

# Scroll, resize window and switch between the panes with the mouse
# The terminal.app in OS X needs  simbl und MouseTerm
set-option -g mouse-utf8 on
set-option -g mouse-select-pane on
set-option -g mouse-select-window on
set-option -g mouse-resize-pane on
set-window-option -g mode-mouse on
#

# Status bar
# set color for status bar
set-option -g status-bg colour235 #base02
set-option -g status-fg yellow #yellow
set-option -g status-attr dim
# show host name and IP address on left side of status bar
set -g status-left-length 70
set -g status-left "#[fg=green] #h - #[fg=brightred]#(curl icanhazip.com)"

# Show users logged in and date, center window infos
set -g status-right-length 60
set -g status-right "#[fg=brightred]#(who | wc -l) user #[fg=yellow]- %d %b %Y - #(date | awk '{print $4}') "
set -g status-justify centre
#

# Colorize active pane
set-option -g pane-active-border-fg blue
#

## End tmux.conf



Current config state with an example:
Image

Fast explanaition:
- Left the window configuration section for the first empty cause this could also be done over an bash script (nevertheless also possible over the config file), so the configuration is more clear. A potential shell script can call on every execution also the configuration file to check if there are some possible changes and it can attach the session to possible existing ones. Furthermore individual pane settings might be more clear to overview in a separated section ?!
- tmux uses Bash.
- 256 colors are default in the terminal.
- The bind key is now Screen-like and has been changed from [CTRL]-b to [CTRL]-a
- "[CTRL]-a r" can reload the config also while a session.
- UTF-8 will be used.
- Activity alert should be monitored.
- The history are extended to 10000 lines.
- A little more color and design stuff.

Take a look into it and improve it if you find some more/better things.

Will post also may an script, but it might be good to hear from you which addons/software/panes could be a nice idea/concept for IPFire ;) .

Greetings,

UE

EDIT(s):
- Wrote accidently in german have changed it to english ::) .
- Changed config file a little and added a different status bar.
- Added mouse integration for scrolling, pane selection and resizing panes.
- Checks now WAN IP and logged in users (from uptime).
- Actualize statusbar infos every 15 seconds.
- Changed uptime command to who command for investigate logged on users to cause "," delimiter for cut do not work after restart
Last edited by ummeegge on January 21st, 2015, 7:02 am, edited 1 time in total.
Image
Image

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » January 17th, 2015, 12:37 pm

A script example with inspiration from ubuntu Wiki:

Code: Select all

#!/bin/bash -

#
# Example script has been taken from ubuntu wiki
# http://wiki.ubuntuusers.de/tmux
######################################
# With a litle modification from ummeegge 17.01.2014
#

SESSION=main
tmux="tmux -f /root/.tmux.conf"

# if the session is already running, just attach to it.
$tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
       echo "Session $SESSION already exists. Attaching."
       sleep 1
       $tmux attach -t $SESSION
       exit 0;
fi
                                 
# create a new session, named $SESSION, and detach from it
$tmux new-session   -d -s $SESSION
# Window 0
$tmux new-window    -t $SESSION:0 -n 'LogCheck1' 'tail -f /var/log/messages'
$tmux split-window  -v -t $SESSION:0
# Window 1
$tmux new-window    -t $SESSION:1
$tmux split-window  -h -t $SESSION:1
# Window 2
$tmux new-window    -t $SESSION:2
# Window 3
$tmux new-window    -t $SESSION:3
$tmux split-window  -h -t $SESSION:3
$tmux split-window  -v -t $SESSION:3
# Window 4
$tmux new-window    -t $SESSION:4
$tmux split-window  -h -t $SESSION:4
# Select entry window
$tmux select-window -t $SESSION:0
$tmux attach -t $SESSION


The above posted tmux.conf file are included by the script. There are now 4 windows with different Pane structures, feel free to extend the script and the config file.

UE

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » February 4th, 2015, 2:43 pm

Some infos for mouse integration on OS X systems and the usage of terminal.app :

To scroll, resize window and switch between the panes with the mouse (or even the trackpad) there is the need to install MouseTerm and SIMBL --> https://bitheap.org/mouseterm/ to make this work. Have added also

Code: Select all

# Scroll, resize window and switch between the panes with the mouse
# The terminal.app in OS X needs  simbl und MouseTerm
set-option -g mouse-utf8 on
set-option -g mouse-select-pane on
set-option -g mouse-select-window on
set-option -g mouse-resize-pane on
set-window-option -g mode-mouse on
#


into ~/.tmux.conf which is now also integrated in the config above --> viewtopic.php?f=52&p=80334#p79315. To change into scroll mode use [ctrl-a] [alt-5] (for "[") and 'q' to switch it off again.

Some more nice infos about this topic and more can be found in here --> http://floriancrouzat.net/2010/07/compi ... minal-app/ .

UE
Image
Image

User avatar
Roberto Peña
Posts: 761
Joined: July 16th, 2014, 3:56 pm
Location: Bilbao (España)
Contact:

Re: New wiki for new addon tmux

Post by Roberto Peña » February 8th, 2015, 6:27 pm

It would be nice instead of starting the IPFire with ROOT login, default initiate this. So, if we put a KVM monitor, you can see that the device works.

Could you do ?.
Image
Image

╔════════════════════════════════════════════════╗
Donate to improve IPFire: https://www.ipfire.org/donate
╚════════════════════════════════════════════════╝

morlix
Community Developer
Community Developer
Posts: 175
Joined: July 18th, 2011, 10:08 am
Location: Stuttgart

Re: New wiki for new addon tmux

Post by morlix » February 9th, 2015, 12:04 pm

Do i understand you right?

You want us to change the default shell from bash to tmux?
Last edited by morlix on February 10th, 2015, 7:57 am, edited 1 time in total.

User avatar
Roberto Peña
Posts: 761
Joined: July 16th, 2014, 3:56 pm
Location: Bilbao (España)
Contact:

Re: New wiki for new addon tmux

Post by Roberto Peña » February 9th, 2015, 12:35 pm

No, what I would like is not display this static screen (login screen) and put something more dynamic. Iftop eg.
Image
Image

╔════════════════════════════════════════════════╗
Donate to improve IPFire: https://www.ipfire.org/donate
╚════════════════════════════════════════════════╝

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » February 9th, 2015, 4:36 pm

Hi all,
Roberto Peña wrote:It would be nice instead of starting the IPFire with ROOT login, default initiate this. So, if we put a KVM monitor, you can see that the device works.

Could you do ?.

Sorry i don´t get what you mean. You can use therefor a simple ssh command with Pubkey authentication so you don´t need to logon manually and it is also more secure.

Roberto Peña wrote:No, what I would like is not display this static screen (login screen) and put something more dynamic. Iftop eg.

In here the same, with a little shell script like this

Code: Select all

#!/bin/bash -
ssh -p222 -t root@{IP-IPFire} iftop

on your admin machine you will get iftop by doubleklick.

tmux is a terminal multiplexer. In here --> http://en.wikipedia.org/wiki/Tmux you can find a fast explanation of what it is.

If i didn´t get you, try a step by step explanation, thanks.

Greetings,

UE

EDIT: In here --> http://wiki.ipfire.org/en/optimization/ ... info/start you can find also an howto for this and may a little more ;) .
Image
Image

User avatar
Roberto Peña
Posts: 761
Joined: July 16th, 2014, 3:56 pm
Location: Bilbao (España)
Contact:

Re: New wiki for new addon tmux

Post by Roberto Peña » February 9th, 2015, 6:16 pm

The homescreen Login seems very static and IT managers will have swith one screen or KVM and if any more dynamic screen would give them some assurance that everything works fine.

The problem is that every day I put it to restart the IPFire at 03:00 am and if I have to login every day to start the Iftop ... would be nice to default appeared something that shows activity.

He had thought if we could split the screen in half horizontally. The top that showed some activity IPFire and inner display is the login TMux style, but by default.

It may be silly, but give better feel.
Image
Image

╔════════════════════════════════════════════════╗
Donate to improve IPFire: https://www.ipfire.org/donate
╚════════════════════════════════════════════════╝

ummeegge
Community Developer
Community Developer
Posts: 4990
Joined: October 9th, 2010, 10:00 am

Re: New wiki for new addon tmux

Post by ummeegge » February 9th, 2015, 6:44 pm

Hi Roberto Peña,
did you tried the above posted bash script and config file ? If yes, what do you think about the allocation ?
This question,
ummeegge wrote:Will post also may an script, but it might be good to hear from you which addons/software/panes could be a nice idea/concept for IPFire ;) .

might also be a silly question but there is the need to install possibly additional software which is a matter of taste so the question again,

What is a nice idea/concept to visualize an IPFire template for tmux ?

Greetings,

UE
Image
Image

User avatar
Roberto Peña
Posts: 761
Joined: July 16th, 2014, 3:56 pm
Location: Bilbao (España)
Contact:

Re: New wiki for new addon tmux

Post by Roberto Peña » February 10th, 2015, 8:02 am

I mean a thing, more or less, certainly improved. (It should put the ".tmux.conf" of ummeegge)

1. Copy the script to run the program to the /etc/init.d/.
start_tmux.sh
start_tmux.sh.zip
(638 Bytes) Downloaded 121 times

2. To execute permissions to the script.
# chmod 755 /etc/init.d/start_tmux.sh

3. Create symbolic link to the implementation level.
# ln -s /etc/init.d/start_tmux.sh /etc/rc.d/rc3.d/S88tmux

4. Reboot and check operation.
Image
Image

╔════════════════════════════════════════════════╗
Donate to improve IPFire: https://www.ipfire.org/donate
╚════════════════════════════════════════════════╝

Post Reply