application installation guntis barzdins girts folkmanis

61
Application Installation Guntis Barzdins Girts Folkmanis

Upload: brittany-walker

Post on 03-Jan-2016

230 views

Category:

Documents


2 download

TRANSCRIPT

Application Installation

Guntis BarzdinsGirts Folkmanis

“Hello World” palaišana

unix% cat > hello.c

#include <stdio.h>int main() { printf("Hello World!\n"); return 0;}

Ctrl/Dunix%gcc hello.cunix%./a.outHello World!unix%

gccthe Gnu Compiler Collection

Frontend for: C: gcc C++: g++ More (ada, java, objective-c, fortran, …)

Backend for: x86, ia-64, ppc, m68k, alpha, hppa, mips, sparc,

mmix, pdp-11, vax, …

gcc: Usage

gcc foo.cpp Outputs ./a.out binary

gcc -g -Wall –pedantic foo.cpp bar.cpp baz.o –o foo -g: produce debugging information -Wall –pedantic: many types of warnings -o foo: output to file “foo”

Linking libraries: eg math library: –lm

The library foo is named libfoo.a under unix

Linking

o Combines the program object code with other object code to produce the executable file.

o The other object code can come from the Run-Time Library, other libraries, or object files that you have created.

o Saves the executable code to a disk file. On the Linux system, that file is called a.out.

o If any linker errors are received, no executable file will be generated.

Normal Linking and Loading

Printf.c

Printf.o

StaticLibrary

gcc

ar

a.out

Linker

Memory

Main.c

gcc

Main.o

Loader

X Window code:- 500K minimum- 450K libraries

Load Time Dynamic Linking

Printf.c

Printf.o

DynamicLibrary

gcc

ar

a.out

Linker

Memory

Main.c

gcc

Main.o

Loader

• Save disk space.• Libraries move?• Moving code?• Library versions?• Load time still the same.

Run-Time Dynamic Linking

Printf.c

Printf.o

DynamicLibrary

gcc

ar

a.out

Linker

Memory

Main.c

gcc

Main.o

Loader

Save disk space.Startup fast.Might not need all.

Run-timeLoader

Creating a static library

static library for linking: libsomething.a create .o files: gcc –c helper.c ar rlv libsomething.a *.o ranlib libsomething.a use library as gcc –L/your/dir –lsomething

Creating a dynamic library

Details differ for each platform gcc –shared –fPIC –o libhelper.so *.o

use same as for static (-llibrary) also LD_LIBRARY_PATH

Program Development Using gcc

Source File pgm.c

Program Object Code File pgm.o

Executable File a.out

Preprocessor

Modified Source Code in RAM

Compiler

Linker

Other Object Code Files (if any)

Editor

Unix sw development environments

Emacs Kdevelop Xcode

Other Programming Tools

There are tools to ease single programmer development of multiple file projects (make)

There are version control tools for multi programmer projects: CVS (Concurrent Version Control)

There are “packaging” tools to ease installing programs: Tarball, RPM, DEB,...

The make program

If in a directory full of C files there is a text file with the default name of makefile then running $make will cause it to be used by the make program

The power of make is that it examines timestamps. If a change is made to part2.c and make run again, only part2.c is compiled. The linker links the old part1.o, old main.o and the new part2.o to make the final program.

Makefiles• When programming large applications

– Better to modularise.– Keep individual source files small.– Instead of one large file.

• Difficult to edit.

• Slow to compile.

– Not easy to do manually.– Use a “makefile.”

Makefile example

• Consider, program contained in two separate source files.– “main.c”– “sum.c”– Both contain header “sum.h”

• Require executable file to be named “sum”• Next slide shows a simple makefile that

could be used.

Makefile example

# Make file for sum executablesum: main.o sum.o

gcc –o sum main.o sum.omain.o: main.c sum.h

gcc –c main.csum.o: sum.c sum.h

gcc –c sum.c

Comment line preceded with “#”

“Dependency line”

“Action line”

Dependency line must start in column 1

Action line must begin with a tab character

Dependency line + Actionline = “Rule”

make

make maintains dependency graphs based on modification times Makefile as default name make [–f makefile] [target]

if node newer than child, remake childtarget ...: dependencycommandcommandtab!

make environment

Environment variables (PATH, HOME, USER, etc.) are available as $(PATH), etc.

Also passed to commands invoked Can create new variables (gmake):

export FOOBAR = foobar

make variables

implicit rules, e.g., a .c file into .o.c.o:$(CC) $(CFLAGS) $<

$@ name of current target

$? list of dependencies newer than target$< name of dependency file$* base name of current target$% for libraries, the name of member

make

all: hello cleanclean:rm –f *.o

helper.o: helper.cOBJ = helper.o \ hello.ohello: $(OBJ)$(CC) $(CFLAGS) $(LDFLAGS) –o $@ $(OBJ)

make depend

depend: $(CFILES) $(HFILES)$(CC) $(CFLAGS) –M $(CFILES) > .state

# works for GNU make and BSD make#if 0include .state#endif#include “.state”

Revision Management

diffutils: Find differences among files (diff and diff3) Update a set of files from generated differences

(patch) cvs

Maintains a history of changes for groups of files Including: who, when, what, and optionally why

Analogue of Visual SourceSafe New alternatives: subversion and bitkeeper

Revision ManagementWhat CVS lets you do

Modify source code locally until it’s ready to be merged with what everyone sees Multiple people can modify the same file and be ok

Develop multiple versions of software simultaneously And merge these branches later on

Recall past versions of code base Based on time ago or version

See committer's comments on their changes

In more widespread linux distributions, programs are distributed in binary RPM, DEB or modified TGZ formats

RPM (RedHat Package Management) packages are used on RedHat, Mandrake, Suse, Conectiva

DEB are used on the open source distribution Debian and its forks

Modified TGZ are used on SlackWare

Packages

Packaging Approaches:Source vs. Binary

There are two fundamentally different approaches for packaging-based software distributions:

providing source packages containing the vendor sources plus instructions for automated build and installation.

providing binary packages containing the final installation files only.

Most packaging facilities support both approaches, although often not equally well.

Both approaches have each their pros and cons, nevertheless all software distributions focus on one of them.

source package

binary package

distribution size package size package dependencies

installation reproducability

installationrun-time stability

installation system alignment

installation time

Dependencies management is a very useful feature of package management software

They keep systems in a consistent state and guarantee the applications to run in the expected way

rpm or dpkg commands have limited dependencies management features

They can report which library a package relies on, but the library can itself rely on other packages…

Dependencies

Main Package Distribution Formats in Linux

There is no standard package manager in Linux Packages Distributed in Binaries or Source Code form Main Package Management Standards

Tarball files (.tar.gz/.tar.bz2) The old-fashioned way of distributing software in Linux/Unix Compatible with all distros Main package manager in Slackware, Gentoo

RPM (RedHat Package Manager) (.rpm) Introduced by RedHat and has been adopted by many other distributions

(Fedora, Mandrake, SuSe) . The most popular Linux package format

DEB (Debian Package Manager) (.deb) Introduced by Debian distribution

Installing from Tarball files

Software Packages coming in source code archives have to be compiled before installed

Usually come in .tar.gz or .tar.bz2 archives Typical compilation/installation steps

Unpack the archive: tar xzvf <package_name>.tar.gz tar xvjf <package_name>.tar.bz2

Change to the extracted directory cd <extracted_dir_name>

Run source configuration script as follows: ./configure

Build the source code using the GNU Make utility as follows: make

Install the package as follows: make install

“INSTALL” or “README” files also exist in this directory giving application-specific usage information

Backup Tools tar

tar jxvf mytarball.tar.bz2 - Extract files from mytarball.tar.bz2 tar zxvf mytarball.tar.gz - Extract files from mytarball.tar.gz -z : Use gzip compression -j : Use bzip2 compression -x : Extract -c: Create -v : Verbose -f : Use file Gzip compression is used for tarballs with the extensions .tar.gz, .tgz, and .tar.Z. Bzip2 compression which is slightly better but requires more CPU is used in tarballs with the

extensions .tar.bz2 and .tbz2. tar jcvf mytarball.tar.bz2 my_files - Creates a tarball mytarball.tar.bz2 with the specified files.

gzip file - Will compress file using gzip compression and will rename "file" to "file.gz“ gunzip file.gz - Will uncompress file compressed using gzip compression and will rename

"file.gz" to "file“ bzip2 file - Will compress file using bzip2 compression and will rename "file" to "file.bz2“ bunzip2 file.bz2 - Will uncompress file compressed using bzip2 compression and will

rename "file.bz2" to "file“

Apache Example1. gunzip apache_xxx.tar.gz2. tar -xvf apache_xxx.tar3. gunzip php-xxx.tar.gz4. tar -xvf php-xxx.tar5. cd apache_xxx6. ./configure --prefix=/www --enable-module=so7. make8. make install9. cd ../php-xxx

10. Now, configure your PHP. This is where you customize your PHP with various options, like which extensions will be enabled. Do a ./configure --help for a list of available options. In our example we'll do a simple configure with Apache 1 and MySQL support. Your path to apxs may differ from our example.

./configure --with-mysql --with-apxs=/www/bin/apxs

11. make12. make install

If you decide to change your configure options after installation, you only need to repeat the last three steps. You only need to restart apache for the new module to take effect. A recompile of Apache is not needed. Note that unless told otherwise, 'make install' will also install PEAR, various PHP tools such as phpize, install the PHP CLI, and more.

Managing Software in RedHat-based distributions

Using the command line, packages are installed using rpm utility program Install a package

rpm -i <package_name>.rpm Update an existing package

rpm –U <package_name>.rpm Remove a package

rpm –e <package_name>

Three ways to manage software packages in Debian

dpkg: Used on .deb files like rpm Install: dpkg -i <package_name>.deb

If an older version of the package is installed it updates it automatically by replacing it with the new

Remove: dpkg -r <package_name> dselect: dpkg console front-end apt-get: The most frequently used way of managing

software packages in Debian. Install: apt-get install <package_name>

e.g. apt-get install kde to install KDE Window Manager Remove: apt-get remove <package_name>

Package Management Using RPM

To install or upgrade a package: rpm -Uvh package-1.0.i386.rpm To remove a package: rpm -e package-1.0 To determine what version of a package you have installed: rpm -qa | grep

package_name To determine what package a file "belongs" to: rpm -qf filePackage

Management Cont. Using Apt

To update your package lists: apt-get update To install all updated packages: apt-get dist-upgrade To install a package: apt-get install package To upgrade a package: apt-get upgrade package To then remove that package (and all packages that depend on it): apt-get

remove package To search for a package: apt-cache search search_string

Other Packaging Methods The Debian case (APT - Advanced Packaging Tool)

The first distribution used organised on-line package repositories APT utilities set (apt-get, apt-cache etc.) is provided for managing

packages on these repositories Can manage packages in binaries and source format Provides packages inter-dependency auto-resolve Contacts repositories listed in /etc/apt/sources.list file E.g. apt-get remove gnome # Remove GNOME

apt-cache search mozilla #Search for package names # containing mozilla”

The Gentoo Linux case (emerge) Deals mostly with source files

Fetches packages and compiles them according to compilation parameters given in /etc/make.conf

E.g. emerge kde #Fetches, compiles and installs packages for KDE

Gentoo Portage features Provides ebuild scripts which download, patch, compile, and install

packages. Modeled on the ports-based BSD distributions. Dependency checking, extreme customization. Original source tarballs are downloaded.

No need to wait for someone to make a binary package for your distribution. The user specifies what they want, and the system is built to their

specifications. Compiles are optimized for your specific hardware.

E.g. Altivec on G4 PPC chips, Pentium versus Athlon.

Portage tree

The Portage tree is a collection of ebuilds, files that contain all information Portage needs to maintain software (install, search, query, ...). These ebuilds reside in /usr/portage by default.

The Portage tree is usually updated with rsync: # emerge --sync # emerge-webrsync

To search for all packages who have "pdf" in their name: $ emerge search pdf

Evaluation of application

Edit RPM Specification

(.spec)

Commit RPM Specification

to CVS

Checkout RPM Specification

from CVS

Fetch Vendor Sources

Roll Source RPM Package

Store Source RPM into

Repository

Fetch Source RPM from Repository

UnpackSource RPM

Unpack Vendor Sources

Configure & Build Application

Install Application

Store BinaryRPM into

Repository

Roll Binary RPM Package

Fetch Binary RPM from Repository

Install Application

into Instance

RemoveApplication

from Instance

upgrade

END

BEGIN

Track Vendor Sources

Package Lifecycle

My hack: This universe.Just one little problem:core keeps dumping.

developer

administrator

On-line Package Repositories

Large package bases on the Web Accessible via FTP or HTTP

http://rpm.pbone.net/ http://www.apt-get.org/text/?site=4

Using rpm

rpm –i install package, check for dependencies

rpm –e erase package rpm –U upgrade package rpm –q query packages (e.g., -a = all)

rpm -qrpm -q -i telnetName : telnet Relocations: (not relocateable)Version : 0.17 Vendor: Red Hat, Inc.Release : 18.1 Build Date: Wed Aug 15 15:08:03 2001Install date: Fri Feb 8 16:50:03 2002 Build Host: stripples.devel.redhat.comGroup : Applications/Internet Source RPM: telnet-0.17-18.1.src.rpmSize : 88104 License: BSDPackager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>Summary : The client program for the telnet remote login protocol.Description :Telnet is a popular protocol for logging into remote systems over theInternet. The telnet package provides a command line telnet client.

Install the telnet package if you want to telnet to remote machines.

This version has support for IPv6.

Building your own rpm: spec

# # spec file for hello world app# Summary: hello worldName: helloVersion: 1.0 Release: 1Copyright: GPL Group: Applications/TestSource: http://www.cs.columbia.edu/IRT/software/URL: http://www.cs.columbia.edu/IRT/software/Distribution: Columbia UniversityVendor: IRTPackager: Henning Schulzrinne <[email protected]>BuildRoot: /home/hgs/src/rpm

%description The world's most famous C program.

Building your own rpm: spec

%preprm -rf $RPM_BUILD_DIR/hello-1.0zcat $RPM_SOURCE_DIR/hello-1.0.tgz | tar -xvf -

%buildmake

%installmake ROOT="$RPM_BUILD_ROOT" install

%files%doc README/usr/local/bin/hello/usr/local/man/man1/hello.1

%clean

Building your own rpm

create ~/.rpmmacros

%_topdir /home/hgs/src/test/rpm cd /home/hgs/src/test/rpm/SPECS rpm -ba --buildroot /home/hgs/tmp hello-1.0.spec

creates binary and source RPM

APT is a system created in the Debian community to automatically manage the packages dependencies

APT can install, remove and upgrade packages, managing dependencies and downloading the packages

It’s a frontend to other tools, and it uses the underlying package management system, like the rpm or dpkg commands

It’s able to fetch packages from several media (cdrom, ftp, http, nfs), and it can be used to create ad-hoc software repositories

APT

APT – Using (1/3)

[root]@[/] # apt-get install nautilusReading Package Lists... DoneBuilding Dependency Tree... DoneThe following extra packages will be installed: bonobo libmedusa0 libnautilus0The following NEW packages will be installed: bonobo libmedusa0 libnautilus0 nautilus0 packages upgraded, 4 newly installed, 0 to remove and 1

not upgraded.Need to get 8329kB of archives. After unpacking 17.2MB

will be used.Do you want to continue? [Y/n]

APT – Using (2/3)

[root]@[/] # apt-get remove gnome-panelReading Package Lists... DoneBuilding Dependency Tree... DoneThe following packages will be REMOVED: gnome-applets gnome-panel gnome-panel-data gnome-

session0 packages upgraded, 0 newly installed, 4 to remove and 1

not upgraded.Need to get 0B of archives. After unpacking 14.6MB will be

freed.Do you want to continue? [Y/n]

APT – Using (3/3)

[root]@[/] # apt-cache search pdfkghostview - PostScript viewer for KDEtetex - The TeX text formatting system.xpdf - A PDF file viewer for the X Window System…

[root]@[/] # apt-cache show xpdf…Filename: xpdf-1.00-3.i386.rpmDescription: A PDF file viewer for the X Window System.Xpdf is an X Window System based viewer for Portable

Document Format (PDF) files. Xpdf is a small and efficient program which uses standard X fonts.

Brazilian distribution Conectiva ported the apt system on its linux distribution, which uses rpm packages

Apt is now available for all distributions using rpm, also thanks to the SourceForge project apt4rpm (http://apt4rpm.sourceforge.net)

Some features of Debian apt are not yet available, like package priority or requests to change configuration files, because of some differences in deb and rpm format

APT for RPM

Create the directory tree <arch>/RPMS.os, <arch>/RPMS.updates,

<arch>/base (for apt specific files)Ex: /linux/apt/redhat/7.3/i386/RPMS.os

In RPMS.os: copy the distribution rpms In RPMS.updates: copy the updates rpms

Give the command genbasedir --topdir=/linux/apt --bloat --bz2only

redhat/7.3/i386 os (for “os” section) genbasedir --topdir=/linux/apt --bloat --bz2only

redhat/7.3/i386 updates (for “updates” section)

APT – repository creation

Create an apache virtual host<VirtualHost *>

ServerName apt.na.infn.it

DocumentRoot /linux/apt

<Directory /linux/apt>

Options +Indexes

</Directory>

</VirtualHost>

The source.list file to access this repository is

rpm http://apt.na.infn.it redhat/7.3/i386 os updates

APT – repository source.list

We have an apt repository in our campus in Naples, accessible at

http://apt.na.infn.it

apt packages for RedHat 7.2, 7.3, 8 e 9 and corresponding sources.list files for os and updates are available on this site

Updates rpms and apt lists are updated every night

APT – Naples repository

Apt simplifies package management on rpm based distributions, even on RedHat

Systems update is possible with only two commands:# apt-get update; apt-get -y upgrade

Using a local repository is possible to upgrade machines using no external links

It is possible to include non standard packages in local repositories...

APT - Benefits

Advanced Package Tool for RPM

High level package management tool from Debian ported to RPM based systems (Conectiva Linux, RedHat, Fedora, SUSE, Scientific Linux ...)

Installs the whole software with one command: “apt-get install lcg-ui” and APT will do the rest for you

Automatically resolves dependencies for specified packages and downloads required rpms

Central configuration file with repositories' URLs (/etc/apt/sources.list or /etc/apt/sources.list.d)

Automated or half-automated software upgrades Note! APT requires that there are no broken dependencies in the

OS