Mosh on SalixOS

Here you can post links to your contributed packages.
ruario
Posts: 88
Joined: 23. Dec 2010, 08:41

Mosh on SalixOS

Post by ruario » 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:

Code: Select all

mosh remotehost --server="LANG=$LANG mosh-server"
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:

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}
mosh.SlackBuild:

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}
Last edited by ruario on 15. Apr 2012, 15:02, edited 3 times in total.

User avatar
gapan
Salix Wizard
Posts: 5521
Joined: 6. Jun 2009, 17:40

Re: Mosh on SalixOS

Post by gapan » 11. Apr 2012, 12:15

Does mosh use any kind of encryption? It seems interesting, but if it doesn't, it wouldn't be much use I guess.

You can find both setuptools and protobuf in the salix repos btw.
Image
Image

ruario
Posts: 88
Joined: 23. Dec 2010, 08:41

Re: Mosh on SalixOS

Post by ruario » 11. Apr 2012, 12:23

gapan wrote:Does mosh use any kind of encryption? It seems interesting, but if it doesn't, it wouldn't be much use I guess.
Yes, from the Mosh homepage, technical info section:
Mosh homepage wrote:Datagrams are encrypted and authenticated using AES-128 in OCB mode.
Wikipedia has an article on OCB mode.
Wikipedia OCB mode page wrote:OCB mode is listed as an optional method in the IEEE 802.11 wireless security standard as an alternative to CCM.
As part of the IEEE 802.11 wireless security standard, this type of encryption should be fairly well tested.
gapan wrote:You can find both setuptools and protobuf in the salix repos btw.
Great, that makes it even easier for Salix users to install. I have updated the original post to mention this.

User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: Mosh on SalixOS

Post by thenktor » 11. Apr 2012, 14:30

Mosh... I like the name, so I have to try it Image :mrgreen:
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)

User avatar
mimosa
Salix Warrior
Posts: 3094
Joined: 25. May 2010, 17:02
Contact:

Re: Mosh on SalixOS

Post by mimosa » 11. Apr 2012, 15:00

I have a vague memory of thinking something of the kind about the name "Salix" some time back ;)

ruario
Posts: 88
Joined: 23. Dec 2010, 08:41

Re: Mosh on SalixOS

Post by ruario » 11. Apr 2012, 19:14

As a side note, there is draft version of a research paper about Mosh that will be presented at USENIX later this year, which is quite interesting if anyone is interested in the finer details or how it works.

User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: Mosh on SalixOS

Post by thenktor » 17. Apr 2012, 09:13

Q: Does mosh work with Amazon EC2?
Yes, it works great, but please remember to open up UDP ports 60000–61000 on the EC2 firewall.
Well, this is an important info not only for Amazon EC2. I could not connect until I've found this in the FAQ and I've opened these ports in the firewall.
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)

ruario
Posts: 88
Joined: 23. Dec 2010, 08:41

Re: Mosh on SalixOS

Post by ruario » 17. Apr 2012, 12:43

Ah, yes I can see how that might catch you out.

P.S. You can also specify a particular server-side UDP port with "-p".

ruario
Posts: 88
Joined: 23. Dec 2010, 08:41

Re: Mosh on SalixOS

Post by ruario » 17. Apr 2012, 12:53

By the way, I really like mosh thus far and am tempted to submit it as a binary package for Salix. Three questions:

1. Is this the type of thing Salix might accept
2. If yes, can I submit Slackbuild scripts like the ones above or should I rewrite them as SLKBUILDs.
3. I think the mosh guys plan to have an updated release very soon with a bunch of bug fixes. Again assuming you would accept a binary package should I wait before I submit because if I understand the policy correctly, once submitted only critical updates (e.g. security fixes) will be accepted within a given release cycle. So I could not submit an updated mosh package to SalixOS 13.37 again unless it was critical.

P.S. In case it has any bearing on your thoughts about me submitting binary packages I should also mention that I have submitted cleaned up SlackBuilds to SBo. So (assuming they are accepted) Salix users would be able to get mosh from slapt-src/Sourcery anyway.

User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: Mosh on SalixOS

Post by thenktor » 18. Apr 2012, 11:13

ruario wrote:P.S. In case it has any bearing on your thoughts about me submitting binary packages I should also mention that I have submitted cleaned up SlackBuilds to SBo. So (assuming they are accepted) Salix users would be able to get mosh from slapt-src/Sourcery anyway.
I would have suggested to add it to our SLKBUILD repository (http://salix.enialis.net/slkbuild/13.37/) but actually adding it to SlackBuilds is fine, too.
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)

Post Reply