Mosh on SalixOS
Posted: 11. Apr 2012, 09:24
Firstly, I hope you don't mind but this is largely a repost of my comments on LQ. I'm repeating it here as I think this application might also interest the Salix crowd. I have tweaked it a little since I know a few things are different on Salix. 
For those unfamiliar with Mosh (MObile SHell), there have recently been some discussions on Hacker News and reddit about it so I thought I would would give it a try. Mosh is a remote terminal, like SSH. It attempts to improve on SSH by being more robust and responsive, especially over Wi-Fi, cellular, and long-distance links and has a few nice features like supporting intermittent connectivity, and providing intelligent local echo and line editing. The authors are pushing it as an better option than SSH particularly over Wi-Fi, mobile, and long-distance links.
Anyway, I thought I would give it try. Since I couldn't find any reference to people using mosh on Slackware/Salix here are some rough notes on how I set it up (including a couple of quick SlackBuilds). Hopefully these are handy should anyone else want to have a play with it.
It has a few dependencies that might not be present on a typical Salix install. I got pysetuptools and protobuf from SlackBuilds.org, [edit] but Salix users can find these in the standard Salix repository and install them from there (thanks to Gapan for confirming this below) [/edit]. In addition you will also need perl-IO-Tty and of course Mosh itself. Below you will find a couple of SlackBuild scripts that I quickly knocked up for these.
All of these packages must be installed on both the client and server to use Mosh.
One 'gotcha' that I noticed after installing Mosh on my machines and trying to connect was that it initially failed with the error "mosh requires a UTF-8 locale" (despite the fact I use a UTF-8 locale). After looking at the mosh FAQ and these two bug reports, I found I was able to connect with:
I decided to make this easier on myself by adding 'SendEnv LANG LC_COLLATE' to /etc/ssh/ssh_config (on the client) and 'AcceptEnv LANG LC_COLLATE' to /etc/ssh/sshd_config (on the server) and then restarting the server's ssh daemon (Note: You can actually connect to the server initially using the --server LANG trick and then use that connection to restart sshd, whilst remained connected via Mosh). Once /etc/ssh/ssh_config and /etc/ssh/sshd_config were configured I was able to avoid having to explicitly set LANG every time with Mosh's --server flag.
So far mosh appears to work as expected. For example, after connecting to my remote server via Mosh I suspended my laptop, chatted with my wife for a while and later when I restored the laptop from its suspended state it restored the connection as soon as wicd got the network back up. Though this is about the sum of my testing so far.
Has anyone else tried it and what do you think?
P.S. Here are my SlackBuilds for perl-IO-Tty and Mosh. They are fully self-contained and will even fetch the source packages if you don't already have them locally. Run them under fakeroot if the source retrieval as root freaks you out.
perl-IO-Tty.SlackBuild:
mosh.SlackBuild:

For those unfamiliar with Mosh (MObile SHell), there have recently been some discussions on Hacker News and reddit about it so I thought I would would give it a try. Mosh is a remote terminal, like SSH. It attempts to improve on SSH by being more robust and responsive, especially over Wi-Fi, cellular, and long-distance links and has a few nice features like supporting intermittent connectivity, and providing intelligent local echo and line editing. The authors are pushing it as an better option than SSH particularly over Wi-Fi, mobile, and long-distance links.
Anyway, I thought I would give it try. Since I couldn't find any reference to people using mosh on Slackware/Salix here are some rough notes on how I set it up (including a couple of quick SlackBuilds). Hopefully these are handy should anyone else want to have a play with it.
It has a few dependencies that might not be present on a typical Salix install. I got pysetuptools and protobuf from SlackBuilds.org, [edit] but Salix users can find these in the standard Salix repository and install them from there (thanks to Gapan for confirming this below) [/edit]. In addition you will also need perl-IO-Tty and of course Mosh itself. Below you will find a couple of SlackBuild scripts that I quickly knocked up for these.
All of these packages must be installed on both the client and server to use Mosh.
One 'gotcha' that I noticed after installing Mosh on my machines and trying to connect was that it initially failed with the error "mosh requires a UTF-8 locale" (despite the fact I use a UTF-8 locale). After looking at the mosh FAQ and these two bug reports, I found I was able to connect with:
Code: Select all
mosh remotehost --server="LANG=$LANG mosh-server"
So far mosh appears to work as expected. For example, after connecting to my remote server via Mosh I suspended my laptop, chatted with my wife for a while and later when I restored the laptop from its suspended state it restored the connection as soon as wicd got the network back up. Though this is about the sum of my testing so far.

Has anyone else tried it and what do you think?
P.S. Here are my SlackBuilds for perl-IO-Tty and Mosh. They are fully self-contained and will even fetch the source packages if you don't already have them locally. Run them under fakeroot if the source retrieval as root freaks you out.

perl-IO-Tty.SlackBuild:
Code: Select all
#!/bin/sh
# Slackware build script for perl-IO-Tty
# Written by ruario
PRGNAM=perl-IO-Tty
VERSION=${VERSION:-1.10}
BUILD=${BUILD:-1}
TAG=${TAG:-ro}
SRCNAM="$(printf $PRGNAM | cut -d- -f2-)"
# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i486 ;;
arm*) ARCH=arm ;;
# Unless $ARCH is already set, use uname -m for all other archs:
*) ARCH=$( uname -m ) ;;
esac
fi
CWD=$(pwd)
TMP=${TMP:-/tmp/SlackBuilds}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
if [ "$ARCH" = "i486" ]; then
SLKCFLAGS="-O2 -march=i486 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
# Exit on most errors
set -e
# Download source package if not present
if [ ! -e $SRCNAM-$VERSION.tar.gz ]; then
wget -c http://search.cpan.org/CPAN/authors/id/T/TO/TODDR/$SRCNAM-$VERSION.tar.gz
fi
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM-$VERSION
tar xvf $CWD/$SRCNAM-$VERSION.tar.gz
cd $SRCNAM-$VERSION
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
-exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
-exec chmod 644 {} \;
# Build with Perl method #1
perl Makefile.PL \
PREFIX=/usr \
INSTALLDIRS=vendor \
INSTALLVENDORMAN3DIR=/usr/man/man3
make
make test
make install DESTDIR=$PKG
# Strip binaries and libraries
find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
# Compress man pages
find $PKG/usr/man -type f -exec gzip -9 {} \;
for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
# Remove perllocal.pod and other special files that don't need to be installed,
# as they will overwrite what's already on the system.
find $PKG -name perllocal.pod -o -name ".packlist" -o -name "*.bs" | xargs rm -f || true
# Remove empty directories
find $PKG -depth -type d -empty -delete || true
# Copy program documentation into the package
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a \
ChangeLog README \
$PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
# Copy the slack-desc into ./install
mkdir -p $PKG/install
# |----------------------------------------------------------------------|
cat << EOS > $PKG/install/slack-desc
$PRGNAM: $PRGNAM (Pseudo TTY object class)
$PRGNAM:
$PRGNAM: Perl extension that provides an interface to allow the creation of a
$PRGNAM: pseudo tty.
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
EOS
# |----------------------------------------------------------------------|
# Make the package
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
Code: Select all
#!/bin/sh
# Slackware build script for mosh
# Written by ruario
PRGNAM=mosh
VERSION=${VERSION:-1.1.3}
BUILD=${BUILD:-1}
TAG=${TAG:-ro}
# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i486 ;;
arm*) ARCH=arm ;;
# Unless $ARCH is already set, use uname -m for all other archs:
*) ARCH=$( uname -m ) ;;
esac
fi
CWD=$(pwd)
TMP=${TMP:-/tmp/SlackBuilds}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
if [ "$ARCH" = "i486" ]; then
SLKCFLAGS="-O2 -march=i486 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
# Exit on most errors
set -e
# Download source package if not present
if [ ! -e $PRGNAM-$VERSION.tar.gz ]; then
wget -c https://github.com/downloads/keithw/$PRGNAM/$PRGNAM-$VERSION.tar.gz
fi
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
-exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
-exec chmod 644 {} \;
# Set Compile flags and configure build
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
--prefix=/usr \
--libdir=/usr/lib${LIBDIRSUFFIX} \
--sysconfdir=/etc \
--localstatedir=/var \
--mandir=/usr/man \
--docdir=/usr/doc/$PRGNAM-$VERSION \
--build=$ARCH-slackware-linux
# Compile the application and install it into the $PKG directory
make
make install DESTDIR=$PKG
# Strip binaries and libraries
find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
# Compress man pages
find $PKG/usr/man -type f -exec gzip -9 {} \;
for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
# Copy program documentation into the package
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a \
AUTHORS COPYING ChangeLog NEWS README.md \
$PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
# Copy the slack-desc into ./install
mkdir -p $PKG/install
# |----------------------------------------------------------------------|
cat << EOS > $PKG/install/slack-desc
$PRGNAM: $PRGNAM (MObile SHell server and client)
$PRGNAM:
$PRGNAM: Remote terminal application that allows roaming, supports intermittent
$PRGNAM: connectivity, and provides intelligent local echo and line editing of
$PRGNAM: user keystrokes.
$PRGNAM:
$PRGNAM: Mosh attempts to improve on SSH by being more robust and responsive,
$PRGNAM: especially over Wi-Fi, cellular, and long-distance links.
$PRGNAM:
$PRGNAM: http://mosh.mit.edu/
$PRGNAM:
EOS
# |----------------------------------------------------------------------|
# Make the package
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}