Install Midnight Commander on a shared hosting account

The opportunity – your hosting account offers you shell access! 😀

The problem – they don’t have Midnight Commander installed! 😥

The background (skip to the solution!)

Ok for some of you, none of this is a problem.  You don’t have shell access on your shared hosting account – most don’t.  For others, you have shell access and Midnight Commander is installed already – great!  For other, you live and breathe for the Linux command line and your intimate knowledge of command syntax and Linux “innards” means you can create a symphony with your keyboard.

I, however, am not a Linux “heavy” and my shared hosting account with O2switch (which I think is a REAL deal, given what you get and the price you pay) provides shell access but no Midnight Commander.  I have done some Linux server management in a mixed platform environment and appreciate what Linux brings to the table but I’m a Windows guy and a visual person.  Consequently, when I see that I have shell access, I’m glad to have the ability to do certain things that simple ftp access doesn’t give me.  On the other hand, given ONLY a command line, my productivity plummets.  Don’t get me wrong, I appreciate what can be done with a command line.  I once worked on a mini computer where the only access was the command line for commands, navigating and editing.  I loved it – but I was young and that was my job.  I could afford to learn on the job and really get good and fast.  Now I’ve got too many fish to fry to learn another environment when I’m not in it all the time.  So for those of us who live MOSTLY in a non-Linux environment, a visual environment helps a LOT.

The problem (when the sys admins won’t install Midnight Commander for you) is that Midnight Commander doesn’t have a set of pre-compiled binaries sitting around for you to run.  It depends heavily on system libraries and thus is typically dynamically linked for the distribution where it will run or is compiled from source into the environment where it will run.  By default it installs in directories to which a shared hosting client doesn’t have access.   Even the ONE statically-linked pre-compiled binary which I found on the internet did not work except when running from a directory to which I didn’t have access! 🙄

My issues were mostly in two areas:

  1. Navigation – the basic need for a file manager – the felt need for which things like Norton Commander came into existence!
  2. File Editing – I had access to vim and nano and neither of these are what I’d call “intuitive”.  I’m not calling them “powerless”

I searched high and low and couldn’t find a solution.  I thought I’d try and compile it from source.  The compilers are NOT available to client accounts so I needed to compile elsewhere and then copy the executable binary to my hosting account and see if that would work.  I couldn’t easily figure out what distribution O2switch used for their servers as none of those discovery commands worked.  I finally asked them and they let me know that it was a CentOS derivative. So I installed a CentOS distro in a VM on my Windows machine.  Not that I did everything right but that was one of the hardest distros to work with.  Then I tried to see if I could compile and then static link on a Ubuntu distro in order to have a fully static-linked binary that, theoretically, I could drop in and run. I’d never compiled on a Linux machine so there were things that made sense from days compiling on IBM mainframes but there was a lot that I didn’t get and I was really going around in circles.

I looked for other ncurses-based file managers and/or editors.  I got Ranger to work, but it was WAY different than what I was used to while it helped me navigate a little bit, it still required a knowledge of a set of commands (it has a vi-based interaction) that I simply didn’t have and that were NOT intuitive from my background.  I tried to get the Diakonos editor to work (written in Ruby), but I don’t know Ruby at all and I barely got anything to run and the system-dependencies it had required that I try to make an older version run…blah, blah, blah – just a mess!

So I finally went to the mailing list of the Midnight Commander project to ask the experts.  I found THE resource that I needed in Erdmut Pfeifer on that list.  He gave me the foundation for…

The Solution!

Read the details of my conversation on the mailing list on this thread.  That will give you more background on what I did and especially on the solution that Erdmut was able to give me.  Here is the essence of his answer to me:

You don’t necessarily need to create a statically linked version to get
it to run on a different box. just pack up all required shared libs (use
ldd” to find out which) plus the dynamic loader itself. The dynamic
loader is normally invoked indirectly via the system, but nothing keeps
you from calling it directly, passing it the name of the dynamically
linked binary to run and the directory where the packed-up libs reside –
see “man ld.so” for details (“ld.so” is the generic name of the dynamic
loader, the actual name on today’s 64-bit boxes is typically
ld-linux-x86-64.so.2, which itself is a symlink to ld-<version>.so).
The loader is a statically linked binary, and thus doesn’t need any
libs itself.
 
As I found myself needing something like this rather frequently, I’ve
put together a little Perl script which automates these steps.

So I got his script (which you can find in the thread on the mailing list) and it worked!  I had to keep tweaking some things to get it just right for my environment, but I got it to the point where I could ssh to my shell session and then type “mc” and I was in an environment that I knew and I could be productive.

Here are the steps I took to make it work in the O2switch environment. YMMV in other environments!  Also this was back in September 2016 so I’ve forgotten a bit of what I did and some of my notes are not as helpful to me at the moment, but I think they’ll get the persistant going in the right direction.

  1. Followed Erdmut’s directions in the thread
  2. Used mc from CentOS 6.8 package installation (it’s version 4.7.0.2)
  3. Added /usr and /etc parts (oops – I don’t totally remember what this means!  I think it’s creating a /usr and /etc structure in my local “mc” directory, which I named “mymc”, and copying in the files from the package installation that would normally be in the root “/usr” and root “/etc” directory structures in a typical system-wide installation)
  4. run strace -o ~/ztrace.txt -e trace=file ./mc and review the file not found output to see what needs to be fixed
  5. cp ~/mymc/etc/mc/Syntax ~/mymc/etc
  6. cp ~/mymc/etc/mc/mc.lib ~/mymc/etc
  7. cp ~/mymc/etc/mc/mc.menu ~/mymc/etc
  8. cp ~/mymc/usr/share/mc/skins ~/mymc/etc
  9. cp ~/mymc/etc/mc/filehighlight.ini ~/mymc/etc
  10. cp ~/mymc/etc/mc/mc.keymap ~/mymc/etc
  11. cp ~/mymc/usr/share/mc/mc.hint ~/mymc/etc/mc.hint.  (the “.” at the end is important!) (this brings the prompt)
  12. cp ~/mymc/usr/share/mc/mc.hlp ~/mymc/etc/mc.hlp. (the “.” at the end is important!)
  13. cp ~/mymc/etc/mc/mc.ext ~/mymc/etc
  14. cp ~/mymc/usr/share/mc/syntax ~/mymc/etc
  15. redo mcedit, mcview symbolic links (this still isn’t working yet – i.e. I don’t have the “mcedit” and “mcview” commands.  The editor and viewer work just fine but I can’t access them via “mcedit” and “mcview”)
  16. Below, I’m including a zipped up version of “~/mymc” which may work right out of the box.  I have it unzipped into the root of my home directory.  I would suggest doing the same.
  17. make symbolic link to ~ so that I can run ./mc to start (might not have to do this if you do the following)
  18. placed the following in ~/.bashrc so that I can simply type “mc” to start
    PATH=$PATH:$HOME/mymc
    export PATH
  19. had to change putty’s translation settings to ISO-8859-1:1998 (Latin-1, West Europe) to make the lines correct.  This is dependant on what your server’s settings are.  It’ll likely be either UTF-8 or ISO-8859-1:1998 (Latin-1, West Europe)

Here’s a zipped copy of my directory “mymc” with everything you need (normally) to run Midnight Commander 4.7.0.2 as an O2switch client.  You’ll have to do the path work afterward to make it more easily executable. It may work for other environments. Please let me know if it does!

Download here ==> mymc.zip

RegEx Nirvana?

My technology path has covered a fairly large swath of operating systems and user environments. I’ve gotten quite familiar with different line-command, GUI and full-screen text (3270) environments. I typically customize any environment I work with.

Currently as part of our missionary work, I’m a systems/network administrator in a small private school in France. I’m the only fish in the pond so I get to do everything. It also means I have to do everything. I don’t have the luxury, therefore, to get good at every technology that I work with. If I don’t know it, I have to teach myself, etc. No training budget here.

My background in programming in various environments and database administration in various environments serves me well in many situations. On thing continues to give me fits, however, regular expressions. These beasts are anything but regular! One thing they are, however, is ubiquitous! As a “mostly Windows guy”, I could get by without them, but even there, more and more pieces of software are adding regex capabilities into their find/replace functions. Add to that the fact that I maintain Linux servers (a self-taught area that has caused me no small amount of head-scratching!) and I absolutely cannot escape regular expressions.

As stated earlier, I don’t have the time to learn every good piece of technology that’s out there, nor a training budget…which translates to no tool budget either. So, I need a good piece of freeware/open source that “holds my hand” in the occasional, but deep, regular expression activity. There’s lots of freeware out there, but 90% of it is simply testing regex…not really helping you understand how to write them. I would search, in vain, occasionally for something that could help me.

Well, I finally found something!!!!

Regulazy (and its big brother Regulator) are written by Roy Osherove and can be found here: http://weblogs.asp.net/rosherove/pages/tools-and-frameworks-by-roy-osherove.aspx I highly recommend them as ideal tools to help you build and test regex’s.

I resent the name Regulazy, but I love its facility to write for you the regex by stepping through a complex string and suggesting appropriate matching expressions for each part of it.

Anyway, thanks Roy for those great tools!!!! You’re helping busy sysadmins the world over!

Technorati : , , , , , ,
Del.icio.us : , , , , , ,