Monday, 2 April 2012

Mac OS X - Package Management with MacPorts


MacPorts
The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.

You can obtain MacPorts from the download page as a package (For Lion, Snow Leopard and Leopard - At time of writing) or you can build from source.
This will typically be installed into /opt/local/bin, so make sure this sits in your PATH.

Update MacPorts
Code Snippet
  1. port selfupdate
End of Code Snippet

View installed ports
Code Snippet
  1. port installed
End of Code Snippet

Search for ports
Code Snippet
  1. port search apache2
End of Code Snippet

Get information about a port
Code Snippet
  1. port info apache2
End of Code Snippet

Find out dependencies for a port
Code Snippet
  1. port deps apache2
End of Code Snippet

See what variations for a port are available (I.e. with/without SSL)
Code Snippet
  1. port variants apache2
End of Code Snippet

Install a port (-f = Force activation)
Code Snippet
  1. sudo port install -f apache2
End of Code Snippet

Clean an installed port
Code Snippet
  1. sudo port clean --all apache2
End of Code Snippet

Uninstall a port
Code Snippet
  1. sudo port uninstall apache2
End of Code Snippet

Display files belonging to an installed port
Code Snippet
  1. port contents apache2
End of Code Snippet

Upgrade a port
Code Snippet
  1. sudo port upgrade apache2
End of Code Snippet


More information can be found on the official MacPorts Guide.

Friday, 30 March 2012

HTTP POST Test site


Use this website if you would like to test your HTTP POST scripts/programs without having to write a server-side test solution.

http://www.posttestserver.com/

Using curl to download files


Example
Code Snippet
  1. curl -C - -O http://www.mirror.com/path/to/NeoOffice-Patch.dmg
End of Code Snippet

Parameters Used
-o/--output Write output to instead of stdout (Outputs the file to the window by default)
-C/--continue-at Resumed transfer offset

Unix - I don't know what kind of terminal you are on - all I have is 'xterm-color'.


If you receive the following error, typically when using text editors like vi, then you need to change your Terminal (Environment variable: TERM)

xterm-color: Unknown terminal type
I don't know what kind of terminal you are on - all I have is 'xterm-color'.


Depending on which shell your using, set the following...

csh shell
Code Snippet
  1. setenv TERM xterm
End of Code Snippet

bash
Code Snippet
  1. export TERM='xterm'
End of Code Snippet

xterm is an example of a terminal emulator. You can use whichever you would like, it's simply a program that emulates a video terminal within some display architecture. Programs gather information from the terminal your currently using (Set in TERM) to aide the display of the content/program.

Here is a good list of various terminals you can try: List of Terminals

Unix Shells


csh (C-Shell)
The C shell is a command processor that's typically run in a text window, allowing the user to type commands which cause actions. The C shell can also read commands from a file, called a script. Like all Unix shells, it supports filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration. What differentiated the C shell, especially in the 1980s, were its interactive features and overall style. Its new features made it easier and faster to use. The overall style of the language looked more like C and was seen as more readable.

tcsh (TENEX C-Shell)
On many systems such as Mac OS X and Red Hat Linux csh is actually tcsh, an improved version of csh. One file containing the tcsh executable has links to it as both "csh" and "tcsh" so that either name refers to the same improved version of the C shell.

On Ubuntu and Solaris machines, there are two different packages: csh and tcsh. The former is a based on the original BSD version of csh and the later is the improved tcsh. To enable the improved version of csh (tcsh), just type 'tcsh'... You will now notice you have access to command history, working arrows etc...

Other shells exist, such as: bash, sh, ksh, zsh, rc etc... Each having their own unique advantages, however, the common shell principles still apply.



Shell startup Scripts (.files)
When you enter a shell (by logging in for example) or switch to another shell (su or executing a different shell), certain shell startup scripts will be executed. It can become confusing as to which shells use which files (I.e. .cshrc, .profile etc etc).

The following as a list of which shells use which files...

csh
Some versions have system-wide .cshrc and .login files. Every
version puts them in different places.

Start-up (in this order):
.cshrc - always; unless the -f option is used.
.login - login shells.

Upon termination:
.logout - login shells.

Others:
.history - saves the history (based on $savehist).

tcsh
Start-up (in this order):
/etc/csh.cshrc - always.
/etc/csh.login - login shells.
.tcshrc - always.
.cshrc - if no .tcshrc was present.
.login - login shells

Upon termination:
.logout - login shells.

Others:
.history - saves the history (based on $savehist).
.cshdirs - saves the directory stack.

sh
Start-up (in this order):
/etc/profile - login shells.
.profile - login shells.

Upon termination:
any command (or script) specified using the command:
trap "command" 0

ksh
Start-up (in this order):
/etc/profile - login shells.
.profile - login shells; unless the -p option is used.
$ENV - always, if it is set; unless the -p option is used.
/etc/suid_profile - when the -p option is used.

Upon termination:
any command (or script) specified using the command:
trap "command" 0

bash
Start-up (in this order):
/etc/profile - login shells.
.bash_profile - login shells.
.profile - login if no .bash_profile is present.
.bashrc - interactive non-login shells.
$ENV - always, if it is set.

Upon termination:
.bash_logout - login shells.

Others:
.inputrc - Readline initialization.

zsh
Start-up (in this order):
.zshenv - always, unless -f is specified.
.zprofile - login shells.
.zshrc - interactive shells, unless -f is specified.
.zlogin - login shells.

Upon termination:
.zlogout - login shells.

rc
Start-up:
.rcrc - login shells

pkg-get and pkgutil package management for Solaris/SunOS


pkg-get
Pkg-get is an open-source, Sun-approved software installation and management tool for Sun Solaris. You can use pkg-get to install a variety of pre-compiled software without having to worry about version compatibility, patch requirements, libraries, or any other prerequisites.

pkgutil
Pkgutil, written in Perl and licensed under GPL, is a tool to make installation of packages in Solaris easier. It handles package dependencies so all required packages are installed before the desired package automatically. This is based on functionality present in apt-get (Debian Linux).

Which tool?
Both tools offer a similar deal... They aide package management on SunOS, they work out dependencies for packages and versioning is controlled by the package manager. I personally use pkgutil, simply because The Open Community Software Project (OpenCSW) has now deprecated support for pkg-get users (This is a large database of free Solaris packages - Note: There are many others you can use with pkg-get)

OpenCSW/Blastwave
The Open Community Software Project (OpenCSW) is an open-source project providing Solaris binary packages of freely available or open-source software. This was previously hosted at Blastwave. The project was originally Blastwave, but this was forked to created The OpenCSW.
OpenCSW provides packages for Solaris 9 and 10, for 32 and 64-bit, x86 and SPARC architectures. Solaris 8 is no longer a 1st-class supported OS[2]: however, there still exists a legacy Solaris 8 archive, which occasionally gets updates.

This isn't the only place to retrieve Solaris packages, but with a nice large database (3500+ packages at time of writing), its quite beneficial to consume.

Getting Started with pkgutil
http://www.blastwave.org/jir/blastwave.fam


Mirrors
OpenCSW/Blastwave do not directly host packages... A number of mirror sites are available to get these, but you must set this in your pkgutil config file. This is typically located here: /etc/opt/csw/pkgutil.conf

To view a list of mirrors, visit The OpenCSW Mirror Page

When selecting a mirror, you must add '/stable' or '/unstable' to the end of the URL. Unstable packages will be more up to date, but may have bugs present. Stable, on the other hand, will have older packages but more robust.

Open your configuration file for editing and alter the "mirror" section. The below example is a stable UK mirror site.
Code Snippet
  1. mirror=http://www.grangefields.co.uk/mirrors/csw/stable/
End of Code Snippet

Save the file and attempt to update the pkgutil catelog (Basically an index of all availalbe packages for a mirror).

Update the pkgutil catelog
Code Snippet
  1. pkgutil -U
End of Code Snippet

Now the catelog is up to date, we can begin to use pkgutil to download and install packages.


Things to note
Ensure wget is in your system PATH (which wget)... pkgutil ships with it's own version, but most distributions of Solaris have a version located here: /usr/sfw/bin

Update pkgutil using the following command
Code Snippet
  1. pkgutil -u pkgutil
End of Code Snippet

Install packages using the following (I.e. bash)
Code Snippet
  1. pkgutil -i bash
End of Code Snippet

Thursday, 22 March 2012

Download older versions of Oracle products


Welcome to the Oracle Software Delivery Cloud

Wednesday, 21 March 2012

Rar Command Line Usage Examples


Rar a single file/directory
Code Snippet
  1. rar a NameOfYourArchive.rar /path/to/file
End of Code Snippet

Rar multiple files
Code Snippet
  1. rar a NameOfYourArchive.rar /path/to/files/*
End of Code Snippet

Unrar a *.rar compressed file
Code Snippet
  1. unrar x NameOfYourArchive.rar
End of Code Snippet

List the contents of a rar file without uncompressing it
Code Snippet
  1. unrar l NameOfYourArchive.rar
End of Code Snippet

Restarting and managing services on Mac OS X


Method 1

Searching running processes to get he PID, then killing it (The service will automatically restart).

Example
Code Snippet
  1. sudo ps -A | grep -i ssh
End of Code Snippet

23450 ?? S 0:00.12 /usr/sbin/sshd -i
23455 ?? S 0:00.03 /usr/sbin/sshd -i
23649 p8 S+ 0:00.00 grep -i ssh


Now use 'kill' on the PID...
Code Snippet
  1. sudo kill 23450
End of Code Snippet



Method 2

launchd is a unified, open-source service management framework for starting, stopping and managing daemons, applications, processes, and scripts. Written and designed by Dave Zarzycki at Apple, it was introduced with Mac OS X Tiger and is licensed under the Apache License.

We will be using launchctl, a subset of this framework to manage services...

List all services
Code Snippet
  1. launchctl list
End of Code Snippet

We can then use this list to identify the names of our services.

Here's an example with SSH...

Stopping a service
Code Snippet
  1. launchctl stop com.openssh.sshd
End of Code Snippet

Starting a service
Code Snippet
  1. launchctl start com.openssh.sshd
End of Code Snippet

How to enable X11 Forwarding with SSH on Mac OS X


The aim of this blog post is to discuss how to display an X window from a target machine on our local system.

A good example here would be the Oracle installer for linux... when the installer is executed, it utilises the windowing system configured to display the installer via. SSH. Lets see how we can set this up...


What is the X windowing system (or X11)
The X window system (commonly X Window System or X11, based on its current major version being 11) is a computer software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers.

Advantages of using SSH for X11 Traffic
- No problems with firewalls, as long as they let SSH pass through (No need to allow access to tcp-port 6000+)
- Communication is encrypted


Note to other OS users [Windows etc]
As long as your software/OS implements the X windowing system, you will be able to display X windows. For windows users, I recommend PuTTY


Mac OS X Configuration

Enable X11 Forwarding in sshd_config
In order to allow X11 forwarding to pass through SSH, we need to enable X11 Forwarding in our config for SSH. This is located in a file called sshd_config and found typically here: /etc/sshd_config or /etc/ssh/sshd_config

Uncomment out the line "# X11Forwarding no" and set it to "yes" (If this hasn't been done already. You will be left with this configuration...

Code Snippet
  1. X11Forwarding yes
End of Code Snippet

Save the file, and restart the sshd service...


Add your target system to the access control list
So our windowing system on our local machine has an access control list (We cant let anybody in as and when we please!)... So we need to allow our target system access to our windowing system.

Code Snippet
  1. xhost fullyqualified.server.name
End of Code Snippet

You will then see this message to confirm...
fullyqualified.server.name being added to access control list


SSH onto our target machine (with the apps using the windowing system. I.e. Oracle Installer)
We can now SSH onto our target machine...

Code Snippet
  1. ssh -X user@fullyqualified.server.name
End of Code Snippet


Ensure the DISPLAY environment variable is configured correctly
On the machine we just SSH'd onto, we need to make sure the DISPLAY environment variable is configured correctly. Our apps will use this to find out where our target machine that supports the X windowing system is located.

Code Snippet
  1. DISPLAY=fullyqualifiedaddressforourhostmachine:0.0
End of Code Snippet

Ensure this has been set correctly...
Code Snippet
  1. echo $DISPLAY
End of Code Snippet

Now lets test to see if our X apps can use our host windowing system via. SSH...
Code Snippet
  1. xclock &
End of Code Snippet

If you do not have xclock, or maybe your trying to execute an installer for Oracle or something, then try and execute the installer.


Gotchas
- Do not set the DISPLAY variable in any login scripts (I.e. bashrc, bash_profile etc...)