Setting Up Your Computer’s Environment under Linux

This document shows you how to set up your computer’s environment under Linux to be as similar as possible to the one in the Digital Systems Laboratory. In fact, these instructions are the ones used to set up that Laboratory in the first place…

The term computer environment, as used in this context, simply means the “look and feel” of the software. In other words, it involves things like the settings you should change in the editor, the icons on your desktop and configuration files for the shell. Some of these things tend to be very subjective and personal (everyone has their own preference regarding colours, for example); these instructions take this into account.

In this document, “$” will indicate the ordinary user’s shell prompt and “#” will indicate the root superuser’s shell prompt. Anything in a bold monospaced font is what you are expected to type in; an ordinary monospaced font is used for the computer’s response. Please note that this document doesn’t show every response from the computer! Something like “K » System Tools » Terminal” means that you click on the K menu button, select the System Tools sub-menu and finally click on Terminal.

These instructions assume that you have already mounted this CD-ROM on your computer, and that the mount point (where the CD-ROM can be found within the file system) is /mnt/cdrom. See the instructions for mounting the CD-ROM for more details.

Structure of This Document

This document is broken down into a number of sections, all of which you should read. Some sections may have a “For Advanced Users” sub-section; you may safely skip these if you don’t feel like finding out exactly how things are set up in the Laboratory. The sections are:

1.Minimum System Requirements
2.Selecting the KDE Desktop
3.Home Directory Configuration Files
4.KDE Desktop Files
5.Syntax Files for the Kate Editor
6.Utility Programs (for advanced users)

Minimum System Requirements

These instructions assume that you have already installed the GNU Tools for Linux, which you will be using to compile, debug and run your programs as part of your laboratory experiments. Part of installing these tools involves checking that your computer meets the minimum computer specification. You may need the root superuser’s password for parts of this setup.

Selecting the KDE Desktop

Part of the appeal of the Linux operating system is the power to choose: you can choose exactly which applications you want to use. One of the more significant choices is which desktop environment to run. Unlike Microsoft Windows, which provides only one desktop per operating system version, Linux allows you to run many desktop environments. The two most popular are the KDE Desktop and the Gnome Desktop. Each of these desktop environments is almost infinitely customisable.

This document uses the KDE Desktop environment, along with the applications bundled with that environment. You can, of course, use the Gnome Desktop instead; in that case, however, you would need to figure out how to configure and use it yourself. Treat it as a learning experience!

You select the KDE Desktop environment before you log in to your computer. In most cases, the graphical login screen will have a Session Type menu somewhere where you can choose “KDE” (or something very similar). In the case of Red Hat Linux 7.3, for example, the Session Type appears in the actual login dialog box. On the other hand, Red Hat Linux 8.0 places the Session menu at the bottom of the entire login screen.

For Advanced Users

If you wish to ensure that KDE is the default choice when you create a new user (and this would be the case within the Laboratory itself), you will need to figure out which file stores the user’s choice of desktop environments. You then need to make sure that that file contains the correct information, and that it gets copied to the newly-created user’s home directory.

The canonical file to modify under most systems is .xsession. This shell script (in the user’s home directory) is executed every time the user logs in at the graphical login prompt. It should contain something like:

#!/bin/sh
exec startkde

This shell script appears on this CD-ROM as dot.xsession. Once you have verified that the file, in fact, works, you can make it a default by copying it to the /etc/skel directory (when a new user is created, everything in /etc/skel is copied to his or her home directory):

cp /mnt/cdrom/unsw/common/labsetup-linux/other/dot.xsession /etc/skel/.xsession
chmod u+w /etc/skel/.xsession

If this method does not work, other files to check are .gnome/gdm, .gnome2/gdm and/or .wmrc, all relative to the user’s home directory. You can find copies of these files in the [List] unsw/common/labsetup-linux/other directory.

By the way, this CD-ROM contains a script, cplabsetup, that copies all of the files mentioned in this entire document to their proper places. Please be aware, however, that you might need to edit this script to suit your local environment. Assuming you have mounted the CD-ROM on /mnt/cdrom, you can run this script by typing (all on one line):

/mnt/cdrom/unsw/common/labsetup-linux/scripts/cplabsetup /mnt/cdrom /etc/skel

You should still read through the rest of this document, of course, just to see if there is something else to be done…

Home Directory Configuration Files

The [List] unsw/common/labsetup-linux/home-config directory contains a number of files that you should copy to your home directory. The procedure to do so is:

1. Log in as an ordinary user (not as the root superuser), making sure that you select KDE as your desktop environment.
You should never do your ordinary work as root! To do so invites the whole world to crack into your computer, destroy your data and use your system to attack others. Besides, it is very easy to make a single typing mistake that wipes out your entire system in one hit. For example, can you figure out the difference between running “rm -fr .” and “rm -fr /”?
2. Open a shell command line window. Under Red Hat Linux 8.0, you can do so by selecting “The Red Hat” » System Tools » Terminal. Under other Linux distributions, try K » System » Shell. If worst comes to worst, try running konsole or xterm from the K » Run Command dialog box.
3. Assuming your CD-ROM is mounted on /mnt/cdrom, type in the following lines:
cd /mnt/cdrom/unsw/common/labsetup-linux/home-config
cp dot.bashrc ~/.bashrc
cp dot.bash_profile ~/.bash_profile
cp dot.bash_logout ~/.bash_logout
cp dot.gdbtkinit ~/.gdbtkinit
cp dot.komodo ~/.komodo
cd ~
chmod u+w .bashrc .bash_profile .bash_logout .gdbtkinit .komodo
source .bash_profile
Remember that the “$” indicates the shell prompt (which might be something quite different from “$”): you don’t type it in. In addition, your browser might split up commands over a number of lines (depending on the width of your browser window); that does not mean you do the same!
4. Leave the shell command line window open, as you will need it later.

Three of the files you have just copied (.bashrc, .bash_profile and .bash_logout) are initialisation files for the shell command line. These files include useful aliases (pseudo-commands), various settings and a nice shell prompt.

For Advanced Users

You should make sure all users on your system use the Bourne Again Shell as their login shell. This is the default on almost all Linux distributions. However, if you want to make sure, you can do so by inspecting the file /etc/passwd. The seventh field of each user should read /bin/bash. More details are available in passwd(5) in the Linux Reference Manual. (By the way, the rather cryptic notation “passwd(5)” is a shortcut for saying “type man 5 passwd at the shell command line”).

If you want to ensure that the files listed above are used by all new users, all you need to do is copy them to the /etc/skel directory. Remember to remove the “dot” prefix from each of the filenames. See the script cplabsetup in the [List] unsw/common/labsetup-linux/scripts directory for more details.

Instead of copying the files, you might want to merge their contents into the files already present in /etc/skel. How to do so is beyond the scope of this document.

KDE Desktop Files

The computers in the Digital Systems Laboratory are set up, by default, to have a number of shortcut icons on the desktop that will make your life a little easier. The [List] unsw/common/labsetup-linux/kde-desktop directory contains the files that make up these shortcut icons. You can have the same icons on your desktop at home by following these steps:

1. You need to find out where your desktop directory is located. In almost all cases, this will be Desktop in your home directory. To check, use the previously-opened shell command line window to type the following commands:
cd ~
ls Desktop
If you do not see the error message “ls: Desktop: No such file or directory”, everything is OK: your desktop directory is Desktop. You can now skip to step 2.
If you do see this error message, you need to figure out where your desktop directory is stored. To do so, open the Control Centre from the K menu (or “The Red Hat” menu on Red Hat Linux — and note that Control Centre is not the same as Red Hat’s Control Panel!). Next, select Look & Feel from the left-hand side, then Desktop. Look through the different tabs to find a field named “Desktop path”. The value there is your desktop directory: write it down somewhere. Now you can close the Control Centre and proceed to step 2.
2. Having discovered your desktop directory, type in the following commands. If your desktop directory is not Desktop, you need to replace every occurrence of ~/Desktop in these commands with the actual desktop directory location:
cd /mnt/cdrom/unsw/common/labsetup-linux/kde-desktop
cp Shell.desktop ~/Desktop
cp Editor.desktop ~/Desktop
cp DSL-Readme.desktop ~/Desktop
cp ARM-ARM.desktop ~/Desktop
chmod u+w ~/Desktop/*.desktop
3. The new shortcut icons should automatically appear on your KDE desktop within a few seconds (although they might be hidden under a window somewhere). You can now move them around to suit your own tastes by dragging them with the left mouse button.
4. You will need to modify the shortcut icons to point to the right locations for your system (by default, the icons are set up so that they can be used in the Laboratory itself). Find the “DSL Companion CD-ROM README” icon and right-click on it. Select Properties from the pop-up menu. Now, go to the URL tab and edit the location of the CD-ROM Root directory README.html file. This will be file:///mnt/cdrom/README.html, assuming your CD-ROM is mounted on /mnt/cdrom. Click OK to close the dialog box. Test this icon by either single-clicking or double-clicking on it (depending on how your KDE Desktop environment is set up): a browser window should successfully open.
5. Finally, find the “ARM Architecture Reference Manual” icon and right-click on it. Select Properties from the pop-up menu. Now, go to the Execute tab and modify the Command field to read:
acroread /mnt/cdrom/reference/arm-architecture-reference.pdf
Click OK to close the dialog box. Now, test this icon: the ARM Architecture Reference Manual should appear. If you get an error complaining about the fact that acroread could not be executed, you need to install the Adobe Acrobat Reader program. Alternatively, you could use a program like kghostview, gv or xpdf instead of acroread.

For Advanced Users

The cplabsetup script automatically copies the four files mentioned above. It also copies two additional files: Home.desktop, which provides the Home desktop icon, and .directory, which contains the positions of all of these icons on a 1024 × 768 desktop. Make sure you read through this script before running it!

Once the desktop files have been copied using the script (most likely to /etc/skel), you may need to edit the files to make the icons point to the right locations. The two files you may need to modify are DSL-Readme.desktop and ARM-ARM.desktop. In the case of DSL-Readme.desktop, modify the line starting with URL=. In the case of ARM-ARM.desktop, modify the line starting with Exec=.

Syntax Files for the Kate Editor

In the Digital Systems Laboratory, the editor you are encouraged to use is Kate, the KDE Advanced Text Editor. Of course, you can choose to use any editor you like, including the venerable Emacs and VI editors. It’s your editor, after all!

Kate, however, is quite a simple-to-use text editor that boasts a number of useful features. One of these is syntax highlighting, where your file is displayed in pretty colours to reflect its syntax structure. Unfortunately, it does not come by default with syntax highlighting for assembly language programs (such as you will be writing in the Laboratory) or for Makefiles. This can be rectified by following these steps:

1. Using the previously-opened shell command line window, type:
cd /mnt/cdrom/unsw/common/labsetup-linux
mkdir -p ~/.kde/share/apps/kate/syntax
cp kate-syntax/* ~/.kde/share/apps/kate/syntax
chmod u+w ~/.kde/share/apps/kate/syntax/*
mkdir -p ~/.kde/share/config
cp kde-config/katerc ~/.kde/share/config
cp kde-config/katesyntaxhighlightingrc ~/.kde/share/config
chmod u+w ~/.kde/share/config/katerc
chmod u+w ~/.kde/share/config/katesyntaxhighlightingrc
2. You can test Kate by clicking (or by double-clicking) on the Editor shortcut icon that you previously placed on the desktop. You might want to open some sample files (such as found in examples/intro on this CD-ROM) to test whether the syntax highlighting works. If you like, you can configure Kate by selecting Settings » Configure Kate. In particular, you might want to change the colour scheme to suit your tastes…

For Advanced Users

Once again, the cplabsetup does all of the hard work of copying the files into the correct places. This script can even be used by a non-root user by specifying ~ as the destination directory. In fact, you are encouraged to do so with a test user account before copying the files to /etc/skel. Always test, test, and retest!

If you prefer a different set of default settings for Kate, simply copy the appropriate files (katerc and katesyntaxhighlightingrc for KDE 3) to your own .kde/share/config directory, then use Kate to change the settings. You now need to edit these files to remove any references to files in your own directories (see the “Cache_…” settings in katesyntaxhighlightingrc, in particular). Once you have done so, you can use these files as a default for all other users. The exact instructions to do all this is beyond the scope of this document.

Utility Programs (For Advanced Users)

The utils/unsw directory contains a number of scripts that are useful for maintaining the Digital Systems Laboratory. In particular, the insync script allows you to synchronise two directories, possibly over a network connection; this allows you, for example, to copy this CD-ROM to the hard drive for local student access.

To copy these scripts, perform the following steps:

1. Create the user account “labstaff” for laboratory maintenance. You will probably use adduser(8) to do this.
2. Log in as labstaff, open a shell command line window and run the cplabsetup script for testing. This assumes you have the CD-ROM mounted on /mnt/cdrom:
/mnt/cdrom/unsw/common/labsetup-linux/scripts/cplabsetup /mnt/cdrom ~
source ~/.bash_profile
3. Copy the actual scripts:
mkdir ~/bin
cp /mnt/cdrom/utils/unsw/src/* ~/bin
chmod 755 ~/bin/*
4. Copy the Companion CD-ROM and make it accessible to everyone:
umask 022
mkdir ~/cdrom
insync -d /mnt/cdrom ~/cdrom
chmod 755 ~
chmod -R u+w ~/cdrom
5. Now you can log in under the various course accounts (elec2041, etc.) and create a symbolic link to this CD-ROM copy. Remember to make sure that such links (and directories leading to them) are world-readable!

Conclusion

Having gotten this far, you have successfully set up your computer’s environment under Linux! Now you can proceed to setting up your environment under Windows, if applicable, or to the examples directory on this CD-ROM, or to something else…