#!/bin/sh
# $Id: init,v 1.3 2004/03/16 01:43:45 zal Exp $
#
# Script to remove stale tmux named pipes on bootup.
#

### BEGIN INIT INFO
# Provides:          tmux-cleanup
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     S
# Default-Stop:
# Short-Description: tmux sessions cleaning
### END INIT INFO

set -e

TMUXDIR=/var/run/tmux

case "$1" in
start)
    if test -L $TMUXDIR || ! test -d $TMUXDIR; then
        rm -f $TMUXDIR
        mkdir $TMUXDIR
        chown root:utmp $TMUXDIR
    fi
    find $TMUXDIR -type p -print0 | xargs -0r rm -f --
# If the local admin has used dpkg-statoverride to install the tmux
# binary with different set[ug]id bits, change the permissions of
# $TMUXDIR accordingly
    BINARYPERM=`stat -c%a /usr/bin/tmux`
    if [ "$BINARYPERM" -ge 4000 ]; then
        chmod 0755 $TMUXDIR
    elif [ "$BINARYPERM" -ge 2000 ]; then
        chmod 0775 $TMUXDIR
    else
        chmod 0777 $TMUXDIR
    fi
    ;;
stop|restart|reload|force-reload)
    ;;
esac

exit 0
