Linux

You are currently browsing articles tagged Linux.

We got an older laptop to use for one of our 3D printer builds, and so we set out to set it up for 3D printing. The laptop is an IBM ThinkPad T41, and because the processor doesn’t support PAE, we weren’t able to use the latest versions or Ubuntu or Mint. Mint 13 installed okay, but the default window managers gave us some trouble, so we ended up installing Lubuntu 12.04. This version doesn’t require PAE.

After installing and updating the operating system, we set out to install pronterface (Printrun) and slic3r from the git repository. Here’s what we did:

First install python support for printrun, and git.

sudo apt-get install python-serial python-wxgtk2.8 \
 python-pyglet python-tk
sudo apt-get install git

Create a directory for RepRap stuff, and clone Printrun to it from the git repository.

mkdir RepRap
cd RepRap/
git clone https://github.com/kliment/Printrun.git

Next comes build-essential, perl, and cpanminus — all required for slic3r.

sudo apt-get install build-essential libgtk2.0-dev \
 libwxgtk2.8-dev libwx-perl libmodule-build-perl \
 libnet-dbus-perl
sudo apt-get install cpanminus

Go into the Printrun directory, get slic3r, and then dive into that directory where we’ll test it to be sure it all works.

cd Printrun/
git clone http://github.com/alexrj/Slic3r.git
cd Slic3r/

Grab the cpan modules required for slic3r, and test it to be sure it loads up properly.

sudo cpanm Boost::Geometry::Utils Math::Clipper \
 Math::ConvexHull Math::ConvexHull::MonotoneChain \
 Math::Geometry::Voronoi Math::PlanePath Moo Wx
./slic3r.pl

Step up one directory and make sure pronterface works well.

cd ..
python ./pronterface.py
Share

I have everything I need to keep tabs on my home IP address without signing up for a DDNS service like No-IP or DynDNS. My Synology NAS always knows its address when it’s online, and because it’s essentially a little Linux box, there’s no reason it can’t tell my other sites where to find it.

In my case, I want to be able to reach my home IP address by visiting a certain URL on either my remote Linux or Windows host — something like www.mydomain.com/myhomeip. But I don’t really want to hide the IP address like a real DDNS would, and I don’t think my hosting providers would even accommodate that. So I rolled my own.

On the remote web host, I created a few PHP files to receive the notifications. common.php does most of the work:

<?php
$file = 'ip.txt';
$pw = 'some_password_here';
$default = 'www.theFrankes.com';

function redirect() {
  global $file, $default;
  $ip = file_get_contents($file);
  if( isValid( $ip ) ) {
    header( "Location: http://$ip" );
  } else {
    header( "Location: http://$default" );
  }
}

function setIp() {
  global $file, $pw;
  $ip = $_SERVER['REMOTE_ADDR'];
  if( isValid( $ip ) & ( $_GET["pw"] == $pw ) ) {
    $fh = fopen($file, 'w') or die("can't open file");
    fwrite($fh, $ip);
    fclose($fh);
  }
}

function isValid( $ip ) {
  return preg_match( "/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/", $ip );
}
?>

My index page calls redirect(), which reads in the IP address and sends the visitor to it if it’s valid. There’s another page that calls setIp(), and that’s the page that my home computer is going to call, passing in the “password” at the top.

I used putty to log into the Synology server and stopped the cron job.

/usr/syno/etc/rc.d/S04crond.sh stop

Then I edited  /etc/crontab to call a shell script in admin’s home directory every few hours. Don’t copy/paste this into the file using putty, but rather type it in directly and use only one tab to separate each column. Typing it directly prevents special (invisible) characters from getting into the file, which could cause it to be overwritten by the default file upon reboot.

*       */4     *       *       *       root   /volume1/homes/admin/cron/every4hrs.sh

In the shell script, I used wget to make the web request. curl would work just as well. I could have just added this command to the crontab file, but it’s easier to manage a shell script in the home directory. I can also extend it more easily at a later date. The shell script simply contains:

/usr/syno/bin/wget --tries=2 "http://www.mydomain.com/myhomeip/ipsetter.php?pw=some_password_here" -O -

The Synology DiskStation makes a working copy of the crontab when it starts up, and stores it in /var/spool/cron/crontabs/root, so to be safe I just rebooted the device rather than just starting the service up again. When I started the service using “S04crond.sh start”, it would work only until the DiskStation rebooted, and after that it would default back to the original. Rebooting the device right away seems to have fixed that problem.

Share

KeePass is a free and utterly genius password management tool that has allowed me to leave the days of reusing passwords way in the past. Now all of my passwords are different, securely managed, and look something like “út8¥Äbë¬eqö«ûëU^Èm­¯”. (Go ahead — try to guess it!) It was written in Microsoft .Net, and supposedly works just fine under Mono in Linux. Mono is a .Net compatibility layer and it’s already included in Ubuntu installations. Well, most of it is.

The problem is that it didn’t quite work out of the box on our Ubuntu 10.10 machine. In particular, I wasn’t able to connect to my password database via FTP like I usually do, but I solved a couple other common problems along the way as well.

First, download the portable version KeePass from the site’s download page, and move all the files onto your linux box. I put them in my home directory under a new hidden directory called “.KeePass”. The first thing I did was add an application launcher to Ubuntu’s top panel, and lo and behold it would not launch.In console, I saw this error message:

The assembly mscorlib.dll was not found or could not be loaded. It should have been installed in the `/usr/lib/mono/1.0/mscorlib.dll’ directory.

The problem was simple; there was a typo in the path. So be sure to type the path carefully, like this: “mono /home/myname/.KeePass/KeePass.exe”. When Mono can’t find the file, it decides it wants to try to run an older version of itself, and that older version it’s included in Ubuntu by default.

Next there were a couple of errors that I wouldn’t have gotten if I had read the instructions carefully. They were both the standard “assembly not found” errors with the text “The following assembly referenced from /home/myname/.KeePass/KeePass.exe could not be loaded” and “The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly.” The first referred to “System.Windows.Forms” and the next to “System.Runtime.Remoting”.

These assemblies were simply not installed in Ubuntu 10.10 by default, but they’re available in the Ubuntu Software Center. Here’s what they look like when you’re adding them.

Adding Mono System.Windows.Forms Support

Adding Mono System.Windows.Forms Support

Sorry about the overlaid screen shot window in this one, but you can still see how to filter and what to click.

Adding Mono System.Runtime Support

Adding Mono System.Runtime Support

Finally it would run, but I was still unable to from open the database from the URL of the FTP site. When I tried either by opening it directly or tweaking the config file, I got a polite error from KeePass that said, “The requested feature is not implemented.” I recognize this as a System.NotImplementedException that’s trapped (but probably not expected) in the code. What it probably means is that KeePass uses some features of .Net that are not yet implemented in Mono; it’s not KeePass’s fault.

I saw two ways around this error: First I could mount the FTP site to a local path using curlftpfs, but that would mean installing something new. Instead I wrote a short shell script to download the database, launch KeePass, and then upload the database back to the FTP site. Here’s the content of the script:

  Server="ftp://my_ftp_site.com"
  User="my_ftp_username"
  Password="my_password"
  DBFile="database.kdbx"
  LocalPath="$HOME/.KeePass/"

  lftp -u $User,$Password $Server <<EOF
    set ftp:ssl-allow no
    get $DBFile -o $LocalPath$DBFile
  quit
  EOF

  mono ${LocalPath}KeePass.exe

  lftp -u $User,$Password $Server <<EOF
    set ftp:ssl-allow no
    put $LocalPath/$DBFile
  quit
  EOF

Finally, I made the script executable, remapped the launcher to the script, picked a better icon, and I was in business again. I hope someone else out there finds this helpful. I know I will the next time I forget what I did. :)

Share

I have a Synology DiskStation (DS209j) that I use on a primarily Windows network, but in some cases I want to access the DS shares from Ubuntu virtual machine running inside VirtualBox. There’s no sense mounting them as Windows shares with the DS supports NFS, so I went that route in stead. (Besides, some application still have trouble with Samba shares.)

I was scratching my head over a “access denied by server while mounting” error until I realized that VirtualBox was getting in the way. Here are the steps I took to get it up and running properly:

  1. In the VirtualBox menu of the virtual machine , select Devices > Network Adapters… and choose Bridge Adapter instead of the default NAT. This takes your virtual machine out of the private network it has with the host computer and makes it a first-class citizen on the network your host computer is on, with its own IP address.
  2. Check the guest machine’s IP address by opening Applications > Accessories > Terminal and typing “ifconfig”. It will probably start with “192.168″, but you’ll need all four parts if you want to limit access to just that machine.
  3. Log into Synology DiskStation Manager as admin, and click Management.
    1. Under Information, click Status and note the network IP address of your DiskStation. It will probably start with “192.168″, but you’ll need all four parts of the IP address.
    2. Under File Sharing, click NFS, and make sure it’s enabled.
    3. Under Privileges, click Shared Folder. Select the folder one you want to mount using NFS, and click NFS Privileges at the top of the list to add a new privilege. Use the IP address of the guest machine to lock access down to that specific machine, or use wildcards to allow access accross your local network (e.g. “192.168.*.*”).
    4. Before you close the NFS Privileges window, note the “Mount path” at the bottom of the list. It will probably look something like “/volume1/MyShare”
  4. To automatically mount the NFS share when you start up, go back to the Terminal window on the guest machine.
    1. Create a directory to use as a mount location. For example if you want to use “MyDSData” in your home folder, type “sudo mkdir /home/YourUserName/MyDSData”. Enter your password when prompted.
    2. Type “sudo gedit /etc/fstab” in the same Terminal window, and edit then add the line below  line to the end of the file. (It’s all one line.) Instead of “[DS IP Address]” use the IP address of your Synology DS, instead of “[Mount path]” type the mount pah, and instead of [Mount location] type the directory you made above. Don’t leave out the colon or the spaces.

      [DS IP Address]:[Mount path] [Mount location] nfs rw,hard,intr,nolock,nfsvers=3 0 0

      For example: “192.168.1.42:/volume1/MyShare /home/alex/MyDDData nfs rw,hard,intr,nolock,nfsvers=3 0 0″

Share

I had some trouble getting my HP LaserJet P1006 to work with the Synology DS210j (NAS print server), even though HP makes Linux drivers and other Synology DiskStation users have had success. The documents would look like they were sent to the printer just fine, but then nothing would happen — nothing actually printed.

The answer came in a recent Synology forum post by a user named efex. There are just a couple of points I’ll make, then just follow his instructions.

  • Be sure you grab the correct firmware file. For the P1006 it’s called sihpP1006.dl.
  • For the LaserJet P1006 specifically, the “$PRODUCT” value is “3f0/3e17/100″.
  • To save the file back to the share, you may need to clear read-only o archive file attributes. In Windows, right-click on the file name located on the share, choose Properties, and then and uncheck those file attributes.

See the whole tutorial, along with links for other product codes, visit this forum post.

Some Updated, More Detailed Instructions

This typically needs to be done with every Synology firmware update.

  1. Open Putty, and log into the DS as “root” with the administrator user password.
  2. Copy the driver file into the firmware directory. I keep a copy on a share on my Synology box to make it easy. For me, the command is “cp /volume1/docs-joint/PC\ Configurations/Synology\ DS210j/sihpP1006.dl /usr/syno/hotplug/firmware/”
  3. Make a backup of the usb.agent file. “cp /usr/syno/hotplug/usb.agent /usr/syno/hotplug/usb.agent.old”
  4. Copy the original to a share to make it easier to edit. “cp /usr/syno/hotplug/usb.agent /volume1/docs-joint/PC\ Configurations/Synology\ DS210j/”
  5. Open the file in a text editor and add the code below to the end. Save the file as “usb.agent.new” in the same directory (because you probably won’t have permission to overwrite the root file on the share).
  6. Back in Putty, change the permission of the file back to root:root. “chown root:root /volume1/docs-joint/PC\ Configurations/Synology\ DS210j/usb.agent.new”
  7. Overwrite the old “usb.agent” file with the new one. “mv /volume1/docs-joint/PC\ Configurations/Synology\ DS210j/usb.agent.new /volume1/docs-joint/PC\ Configurations/Synology\ DS210j/usb.agent”
  8. Copy the file back to the hotplug directory. “cp /volume1/docs-joint/PC\ Configurations/Synology\ DS210j/usb.agent /usr/syno/hotplug/”
  9. Verify that the newly edit file has permissions “rwxr-xr-x”. If not, use “chmod 755 /usr/syno/hotplug/usb.agent”
  10. Turn the printer off and back on again. You should hear it reset twice instead of once.

# Upload the firmware to the printer
sleep 5
FIRMWARE=/usr/syno/hotplug/firmware/sihpP1006.dl
if [ "$PRODUCT" = "3f0/3e17/100" ]
then
 if [ "$ACTION" = "add" ]
 then
 echo "`date` : Sending firmware to printer..." >> /var/log/hp
 cat $FIRMWARE > /dev/usb/lp0
 echo "`date` : done." >> /var/log/hp
 fi
fi

Share