יום שישי, 29 במרץ 2013

How to package MobaXterm plugins with Cygwin

2015 update:The following post is somewhat redundant, MobaTek's dedicated team of developers already adpated a working port of apt-cyg including all of the steps below (sans the plugin packaging), preventing the need to pack your own plugins. however plugins can still be created to supply different versioning and configuration deployments where needed.

2013 Mar 29th
If you don’t know MobaXterm, here are a couple of words from their Developer’s website
MobaXterm is an enhanced terminal for Windows with an X11 server, a SSH client and several other network tools for remote computing (VNC, RDP, telnet, rlogin). MobaXterm brings all the essential Unix commands to Windows desktop, in a single portable exe file which works out of the box.
MobaXterm provides useful features for developers, sysadmins, webmasters and advanced computer users:
multitab terminal with embedded Unix commands (ls, cd, cat, sed, grep, awk, rsync, wget, …)
embedded X11 server for easily exporting your Unix/Linux display
a session manager with several network utilities: SSH, RDP, VNC, Telnet, Rlogin, FTP, SFTP and XDMCP
passwords management for SSH, RDP, VNC, SFTP (on demand password saving)
easy graphical file transfer using drag and drop during SSH sessions
advanced SSH tunnels creation tool (graphical port forwarding builder)
tasks automation using scripts or macros
I stumbled upon them when I was looking for an X-server solution for a friend which hadn’t the time nor the energy to setup his own cygwin/xterm/virtualbox. as I have dug into the spec and features, my passion grew stronger about this product as it seemed to be tailored for my own desires and needs.
in order to make myself feel at home using it, I had to know I am able to maintain my environment and to have the packages and libraries I need for my tasks, and the ability to control them, as it appears, their plugin system fits like a glove.
The concept is of a sandbox, whenever you start the program you get a clean-slate, vanilla instance of cygwin with some basic needed components, and if you have any plugins in your plugin directory, they are being loaded freshly every time. This does not mean you don’t have a persistent workspace as the program cleverly lets you dedicate a folder from your computer to be the ‘bridge’ or the home folder of your mobaxterm.
Here’s my take on building a mobaxterm plugin, it is very basic and relies heavily on a separate instance of cygwin which you can download from here.
1. install a cygwin instance, keep it minimal but with some tools you’ll probably want for the packaging process (I used tar, gz, wget, apt-cyg…)
2. in your cygwin prompt install apt-cyg. it is helpful for installing packages to your cygwin, and to get list of prerequisites for your op to work.
wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin/
3. install the program you would like to pack ( technically you could build rather then pull ready packages, you may have to use it for some software cygwin/redhat had not patched and optimized to cygwin but my guess is you won’t need it anytime soon )
apt-cyg install package
4. after the package is installed, we know that all of our dependecies are met since apt-cyg is a good package manager. we would like to compile the list of software to pack. I do it by querying the apt-cyg db. i.e.
$ apt-cyg describe perl_vendor
Working directory is /home/dave/plugins/libglib2.0_0
Mirror is ftp://mirror.mcs.anl.gov/pub/cygwin
2013-01-12 01:18:58– ftp://mirror.mcs.anl.gov/pub/cygwin/setup.bz2
=> `.listing’
Resolving mirror.mcs.anl.gov (mirror.mcs.anl.gov)… 146.137.96.7, 2620:0:dc0:1800:214:4fff:fe7d:1b9
Connecting to mirror.mcs.anl.gov (mirror.mcs.anl.gov)|146.137.96.7|:21… connected.
Logging in as anonymous … Logged in!
==> SYST … done. ==> PWD … done.
==> TYPE I … done. ==> CWD (1) /pub/cygwin … done.
==> PASV … done. ==> LIST … done.

[ <=> ] 1,043 –.-K/in 0.003s

2013-01-12 01:19:00 (323 KB/s) – `.listing’ saved [1043]

Removed `.listing’.
2013-01-12 01:19:00– ftp://mirror.mcs.anl.gov/pub/cygwin/setup.bz2
=> `setup.bz2′
==> CWD not required.
==> PASV … done. ==> RETR setup.bz2 … done.
Length: 364917 (356K)

100%[=============================================================>] 364,917 186K/in 1.9s

2013-01-12 01:19:03 (186 KB/s) – `setup.bz2′ saved [364917]

Updated setup.ini

perl_vendor
sdesc: “Additional vendor modules previously packaged in perl-5.10
ldesc: “Common modules to installtest, debug and report CPAN modules:
Pod::Escapes Pod::Simple Test::Pod Devel::Symdump Pod::Coverage
Test::Pod::Coverage Compress::Bzip2 IO::String Archive::Zip
Term::ReadKey Term::ReadLine::Perl Term::ReadLine::Gnu
XML::NamespaceSupport XML::SAX::Base XML::SAX XML::LibXML::Common
XML::LibXML XML::Parser Proc::ProcessTable YAML Config::Tiny
File::Copy::Recursive IPC::Run3 Probe::Perl Tee IO::CaptureOutput
File::pushd File::Which File::HomeDir Digest::SHA IPC::Run
Module::Signature URI HTML::Tagset HTML::Parser HTTP::Date
Encode::Locale LWP::MediaTypes HTTP::Message File::Listing
HTTP::Daemon WWW::RobotRules HTTP::Negotiate HTTP::Cookies Net::HTTP
WWW::RobotRules LWP Net::IP Digest::HMAC_MD5 Net::DNS Test::Reporter
Net::SSL common::sense JSON::XS JSON Metabase::Client::Simple
Sub::Install Data::UUID Sub::Exporter Params::Util Data::OptList
Data::GUID CPAN::DistnameInfo Metabase::Fact Test::Tester
Test::NoWarnings Config::Perl::V CPAN::Testers::Report
Test::Reporter::Transport::Metabase Capture::Tiny Devel::Autoflush
IPC::Cmd CPAN::Reporter Module::ScanDeps PAR::Dist Socket6
IO::Socket::INET6 B::Generate PadWalker Data::Alias”
category: Perl
requires: perl libssp0 libgcc1 libbz2_1 zlib0 libopenssl100 libncurses10 libreadline7 libncursesw10 libxml2 libiconv2 libexpat1 _autorebase cygwin
version: 5.14.2-3
install: release/perl/perl_vendor/perl_vendor-5.14.2-3.tar.bz2 2536307 5b3f36321cff52dc66c8048aa06f905a
source: release/perl/perl-5.14.2-3-src.tar.bz2 17627943 8a1d9eb3fd927b45b8c75fa8f590bcf0
I would then go through with this for every pack then recursively in the bold list. and when I have compiled a list of libraries, and apps I will continue to compiling a list of the needed files.
vi liblist
libglib2.0_0
libncurses10
libssp0
libopenssl100
libfam0
libffi4
libiconv2
libstdc++6
libintl8
libpcre1
zlib0
libssp0
libgcc1
libgdbm4
libdb4.5
crypt
save the liblist file in a clean empty folder, we are getting to the secret sauce now.
for g in `cat liblist`do zcat /etc/setup/$g.lst.gz; done >filelist
for i in `cat filelist` ; do if [[ -d /$i ]]then echo mkdir -p ./$ielse echo cp –parents /$i ./fidone | sort -r> createlist
chmod +X createlist
./createlist
Thats it, (hopefully XD) now just zip the files and folders (leave out liblist filelist and createlist) and rename the zip into .mxt3 and you should be good with your packed software.
This worked for me for building an irssi plugin which you can download here.