Exercise "Setup"

Objective:

Create the working environment for the course.

Inroduction:

You need to set up two things to get through the course:

  1. A POSIX system to solve the exercises;
  2. A place on the internet to share your solutions to the exercises;

There are several possibilities for that:

  1. Getting a POSIX system:
    1. You can use IFA's server LIFA (lifa.phys.au.dk). I have asked IT-support to create for each of you an account on LIFA. With LIFA you get both a POSIX system and the place on the internet. You only need an internet connection and a terminal emulator with ssh capabilities to log in to LIFA. There is a terminal emulator for Windows—PuTTY—which should do just fine. MacOSX (and other *BSDs) and Linux-based systems all have built-in terminal emulators (well, Android needs an extra app).

      Possible pitfalls: you need an internet connection to work on LIFA; you need VPN connection if you are outside of the university; LIFA has not been updated for about a decade (but is still ok).

    2. Install Ubuntu Desktop (or your other favourite POSIX system) on your own laptop. You can do it either directly or in a virtual box.

    3. MacOSX (Darwin) is mostly POSIX compatible. If you install Homebrew package management system, you should be able to get all the necessary utilities.

    4. There is a POSIX environment for Microsoft-Windows called Cygwin. Some students managed to successfully make it through the course using this enviroment.

  2. Filesharing:
    1. LIFA itself. LIFA runs Apache web-server which serves files from the user's public_html directory.

    2. Your favourite filesharing service (GoogleDrive, DropBox, CloudMe, ownCloud, Github, ...).

Tasks:
  1. Set up your POSIX system and filesharing.

    If you plan to work on your own box:

    1. Install Ubuntu (or your other favourite POSIX system) on your box;
    2. Prepare your file-sharing servce.

    If you plan to work on LIFA, then

    1. You should have received an email from NFIT to your university account with instructions how to get your LIFA account: so, get your LIFA account.

    2. On Linux or Mac: run your terminal emulator and type in the terminal window

      ssh your_username@lifa.phys.au.dk 
      where instead of "your_username" you have to type your actual LIFA username. It might ask you whether you trust lifa – answer "yes" without quotes. Then it will ask you for your password – type in your LOFA password. If everything goes right, you are logged in on lifa.
    3. On windows run PuTTY and specify "lifa.phys.au.dk" without quotes as the destination. Then login with your LIFA username and password. It might ask you whether you trust lifa – answer yes.

    4. When you are done, issue the command

      exit
      
  2. Prepare the directory for the exercises

    • If you are working on your own box, create a directory, say ~/numeric, where you will be doing exercises and find out how you will be uploading your exercises to your filesharing server.

    • If you are working on LIFA, do

      1. Create the directory for the exercises using the mkdir command:

        mkdir -p ~/public_html/numeric
        where ~/ is the abbreviation for you home directory.

        Now the URL http://www.phys.au.dk/~your_username points to your ~/public_html/ directory, while http://www.phys.au.dk/~your_username/numeric points to your ~/public_html/numeric directory which should then be the place for your exercises.

      2. Change the permissions to allow the others see your ~/public_html directory,

        chmod -R go+xr ~/public_html 
        You might need to issue this command again after you have created some new files.

        If you do not wish the others to see a certain file, for example my_secret_file, do

        chmod go-r my_secret_file
    • If you are working on your own box, but use LIFA as fileserver you can copy files and directories between your POSIX box and lifa in several ways:

      1. Using the secure copy command "scp".

        For example (presuming that you are able to ssh onto lifa, since scp uses the same protocol as ssh), if your username on lifa is "pks07", and you want to copy the folder "myFolder" on your box into your "~/public_html/numeric" directory on lifa, you can use the following command:

        scp -r myFolder pks07@lifa.phys.au.dk:/usr/users/pks07/public_html/numeric/
        

        It will ask you for lifa's password (or not if your ssh goes via RSA keys). It may take some seconds to establish ssh connection into lifa, but it works in the end (for me in any case).

        You probably have to delete any lines with "biff" and/or "date" or other talkative commands from you "~/.login" and/or "~/.cshrc" and/or "~/.profile" files because of issuses with talkative shell profiles.

      2. Using the secure shell file system "sshfs" (presuming that you are able to ssh onto lifa, since sshfs uses the same protocol as ssh).

        You first have to install sshfs it with the command

        sudo apt-get install sshfs
        

        Now you can mount your filesystem on lifa as a directory on your own box. You mount sshfs onto an empty directory on your box, for example, "~/lifa" (where "~/" is a short-hand notation for your home-directory). If you don't have such an empty directory, you have to create it with the command mkdir ~/lifa.

        You mount your lifa's filesystem onto the empty "~/lifa" directory with the command (if your username is pks07)

        sshfs pks07@lifa.phys.au.dk:/usr/users/pks07 ~/lifa
        
        Now the "~/lifa" directory is directly connected to your home-directory on lifa. You can copy or move files there or back in the usual way.

        Having done your copying/moving you unmount the filesystem with the command

        fusermount -u ~/lifa
        

        It is of advantage to create the file "~/.ssh/config" with the content

        ServerAliveInterval 10
        
  3. Try it out

    1. Create a "test" sub-directory in your numeric directory:

      • on Lifa:
        mkdir -p ~/public_html/numeric/test
        cd ~/public_html/numeric/test
      • on your own box (if your numeric directory is ~/numeric):
        mkdir -p ~/numeric/test
        cd ~/numeric/test
      Hint: the tabulator-key on the left of the keyboard does completion: it tries to complete—in a smart way—the words you type. You only need to type the (qualified) beginning of the name and then pressing tabulator-key will complete the name for you.
    2. Pick your favourite text editor. If you don't have one, try nano – it is very simple. You only need to remember that, for example, ^X in the menu list at the bottom of the window means pressing the Ctrl-key (usually bottom left) and the x-key (often between z and c) together (Ctrl-key first).

      A very popular GUI text editor is gedit but you need a computer with an X-window system installed to run it (linux-based systems, like Ubuntu, usually have it installed by default). For example, you can boot the computers in the computer room off an Ubuntu Live CD or USB and work from that. In order to use X-window programs you have to login with "-X" option,

      ssh -X user@host

    3. create a file named hello.c with the content

      #include <stdio.h>
      int main(void)
      {
        printf("hello\n");
        return 0;
      } 
    4. compile the program with the command
      cc hello.c -o hello
      or using make utility
      make hello
    5. run the program:
      ./hello
      the word "hello" must appear on the screen if everything goes right.
    6. If you work on Lifa, check whether you can see the file in your browser at http://www.phys.au.dk/~your_username/numeric/test. If you work with your own filesharing service, synchronise the direcory with your fileserver and check that you can see it in a browser.