Hacking On Spaceman

From Gnuffy

Jump to: navigation, search

Contents

Package format

Every package built from a PKGBUILD file contains a file ".PKGINFO". This file contains following content written as plain text:

pkgname = name of package
pkgver = version of package, <upstream package version>-<revision of PKGBUILD>
pkgdesc = description of package
url = url to the home of the package
builddate = time when this package was built
buildtime = numerical value, describes what time was needed to build the package specified in seconds
packager = environment in which the package was built
size = numerical value, size of the package content specified in bytes
arch = target architecture of package
license = license of package
depend = on what other packages does this package depend?, all dependencies a seperated by a space
useflags = what useflags were used to build this package

To get an impression how this looks in reality, here is a .PKGINFO file of cppunit:

# Generated by spaceman 0.8.5.beta.2401
# Fri Aug  1 14:26:00 CEST 2008
# CFLAGS="-march=i686 -O2 -pipe"
# CHOST="i686-pc-linux-gnu"
# gcc-version: gcc (GCC) 4.3.1 20080724 (prerelease)
pkgname = cppunit
pkgver = 1.12.1-2
pkgdesc = A C++ unit testing framework
url = http://cppunit.sourceforge.net
builddate = Fri Aug  1 12:26:00 2008
buildtime = 48
packager = Gnuffy Linux (http://www.gnuffy.org)
size = 1202484
arch = i686
license = LGPL
depend = gcc-libs
useflags =

PKGLIST format

This file is a list of packages and is formatted in a parser friendly way. Each line specifies one specific package and contains some values from .PKGINFO:

<pkgname>:<version of upstream package>:<revision of PKGBUILD>:<pkgdesc>:<size>::::<origin repository>:<GPG Key>:<depend>:::TODO:TODO:<url>:

To provide an example:

cppunit:1.12.1:2:A C++ unit testing framework:1202484::::commander:2C64CBD9:gcc-libs klibc:::1217436389:1217444327:http�//cppunit.sourceforge.net:

Notes:

  • GPG Key is 0 if no GPG key is available, currently only used by some archlinux converted repositories
  • The colon in the URL is replaced by a different char: TODO: which one?

Spaceman directory structure

SPACEMAN_FILE_CACHE

  • Default: /var/spaceman/cache/pkg
  • Content: All downloaded packages are stored here

SPACEMAN_HOME

  • Default: /var/db/pkg
  • Content:
    • bzip2 compressed PKGLIST file containing all available packages: pkglist.bz2
    • bzip2 compressed PKGLIST file containing all installed packages: install_pkglist.bz2
    • files: a list of all installed files
<package>:<path of installed file provided by package>

Spaceman files

The power of spaceman relies on a whole bunch of bash scripts organized in the following way: - a lot of bash scripts providing the functions - specific bash scripts for the main file All these files will be concatenated together to one big bash script and a package manager is born.

Function files

Most function files have the name <function>.function.sh. Thus, the following paragraphs describe the inner workings of each function file.

addpkg

  • Description: Extracts the PKGINFO file from a pkg or pkgbuild archive, converts the contained information to PKGLIST format, adds an md5sum and size, and adds everything to a temporary PKGLIST file, which was initialized before (in clean_init)
  • Needed arguments:
    • $1: path to archive
  • Returns: none

add_to_configfile

  • Description: checks if a variable is defined in the config file. If it is not, it will be added with a default value or asks the user for a value. If a variable starts with ":" it contains a compled command sequence to be run to get the default value. This might or might not include the dialog with the user.
  • Needed arguments:
    • $1: name of variable
    • $2: default value
    • $3, $4, $5: explanations to print to config file
  • Returns: nothing

arch2pkgbuild

  • Description: Uses the first argument to split off repository and name of a desired archlinux pkgbuild, which will be fetched from the archlinux rsync server and converted to a gnuffy pkgbuild tarball. The resulting tarball will be stored in the spaceman file cache.
  • Needed arguments:
    • $1: a string with following format: $repos:$name.pkgbuild.tar.bz2
  • Results: nothing

aur2pkgbuild

  • Description: Downloads a compressed archive from AUR and converts it to the gnuffy pkgbuild format. The resulting tarball will be stored in the spaceman file cache.
  • Needed arguments:
    • $1: name of desired package
  • Returns: nothing

backup_pkgdb

  • Description: Creates a new backup of current list of installed packages. Keeps a defined amount of backups be deleting old ones if there are already $PKGDB_BACKUPS backups.
  • Needed arguments: none
  • Optional arguments:
    • PKGDB_BACKUPS: number of available backups, 5 by default.
  • Returns: 0 if PKGDB_BACKUPS is 0, elsewise the return value is the return value of the remove command used for deleting old backups.

build_pkg

check_download

  • Description: Checks if downloaded file matches expected size, md5 and keyid. The checks will be ignored if the expected values are not available. If the values don't match, spaceman forces a clean_exit.
  • Needed arguments:
    • $1: filename
    • $2: expected size of filename
    • $3: expected md5 of filename
    • $4: expected keyid (GPG) of filename
  • Returns: nothing

check_freeze

  • Description: Checks if a package in $INSTALLATION_LIST was frozen some time before and will be removed from $INSTALLATION_LIST
  • Needed arguments:
    • INSTALLTION_LIST: List of pending packages waiting to be installed
  • Returns: Updated $INSTALLATION_LIST without frozen packages

check_key_class

check_signature

  • Description: Checks signature of a given filename.
  • Needed arguments:
    • $1: filename
    • $2: expected keyid (GPG) of filename
  • Returns:
    • 1 if keys don't match
    • $GPG_OUTPUT containing the output of "gpg --keyserver-options auto-key-retrieve $1.sign" if keys match

check_spaceman_dependencies

choose_from_search_results

clean_exit

clean_init

comamain2pkgbuild

configure_spaceman

create_pkgbuild_tar_bz2

ctrl_c

depclean

deps

  • Description: displays direct dependencies of given packages
  • Needed arguments:
    • $CMD_NAME: one or more package to list dependencies for
  • Returns: nothing

deptree

do_build

do_download

do_install

do_remove

extract_DOTINSTALL

extract_pkginfo

  • Description: Extracts a value from a provided pkginfo file, which is stored in the bash variable PKGINFO
  • Needed Arguments:
    • PKGINFO: The stored pkginfo file
    • $1: The variable name to be extracted from the pkginfo file
  • Result: the content of the specified variable

file_exists

filter_results

final_message

  • Description: Adds a message to the final_msg array which will be used by clean_exit and prepare_installation.
  • Needed Arguments:
    • $1 message to be added
  • Returns: nothing

fix_problems

freeze

getdelta

getfile

  • Description: Checks if requested file was already downloaded before. If not, it will be downloaded and stored, if desired to a different filename.
  • Needed arguments:
    • $1 file to download
    • $2 alternative name for downloaded file, if "localonly" the file won't be downloaded
  • Returns:
    • 0 and $fpos containing the path to requested file
    • 1 if file was not found or could not be downloaded

gpg

  • Description: Calls the gnupg binary with the provided arguments. If $FAKEROOTKEY is empty and the root user called spaceman, the gpg binary is called as user spaceman.
  • Needed Arguments:
    • $*
  • Returns: nothing

gpl_check

guess_pkgdesc

install_lock

install_pkg

install_set_tag_by_number

install_set_tag

is_installed

key_class

key_id_out

list_pkg

makepkg

mktemp

msg

  • Description: Displays a specified message colored to the user.
  • Needed Arguments:
    • $1: message to be displayed
  • Returns: nothing

mywget

new_installation

newpkgbuild

new_repos

one_line_output

percent

pkgbuild_change

pkgbuild_qa

pkginfo_dep_change

pkgrating

prepare_chroot

prepare_installation

readkey

recvkeys

  • Description: Extracts the GPG keys from the main PKGLIST file and uses the gnupg binary to receive those keys from the key servers
  • Needed Arguments: none
  • Result: none

remove_chroot

remove

repolist

repos_config

repos_or_key_class

repounlist

result_dependencies

revdep

search_pkg

select_from_list

set_depends

set_pkglist_ptr

shorten_deps

show_downloadsize

show_help

  • Description: Shows the available commandline parameters to the users (spaceman --help)
  • Needed Arguments: none
  • Result: none

show_info

show_installation_date

showmenu

  • Description: Will someday offer an interactive menu to use all features of spaceman more easily.
  • Needed Arguments: none
  • Result: none

show_pkgrating

show_results

sign_all

sign_pkg

splitversion

strwidth

  • Description: Dtermines the real length of a provided string by removing all escape sequences
  • Needed arguments:
    • $1: string to determine length from
  • Returns: length of string without escape sequences

subversion

sync_pkglist

synonym

tag_for_download

tag_for_remove

unfreeze

update_repos

update_system

used_useflags

useflag

  • Description: checks if a provided useflag is contained in $USE, thus set.
  • Needed Arguments:
    • $1: useflag to check
  • Returns: 0 if provided useflag is valid, 1 elsewise.

use

See useflag function

ver2ser

version_compare

  • Description: Compares two versions of the same package
  • Needed Arguments:
    • $1 first version without revision of package
    • $2 second version without revision of package
  • Optional Arguments:
    • $3 revision of first version
    • $4 revision of second version
  • Returns: 0 if equal, 1 if first version is higher than second one, 2 if second version is higher than first one

view_pkgbuild

who_owns

  • Description: searches in spaceman file list (see Spaceman directory structure) for specified files and displays associated package to the user
  • Needed Arguments: files to be searched for
  • Returns: nothing

who_owns_global

  • Description: Downloads "complete_files.lzma" (if it doesn't exist) from the gnuffy mirrors and tries to find owner of the provided files, even if a package is not installed.
  • Needed arguments:
    • $CMD_NAME: filenames to find owners for
  • Optional arguments:
    • $1: if "force" then a current "complete_files.lzma" will be fetched from one of gnuffy mirrors
  • Returns: nothing

word_wrap

yes_no

  • Needed Arguments:
    • DEFAULT_REPLY: specifies the default reply used when --dontask was provided on the command line
  • Description: Parses yes or no answers to spaceman questions. If nothing similiar to yes or no was given, this function will show "What?" to the user.
  • Returns: 0 if yes, 1 if no

Main file

As already mentioned above, there are two specific files for the main bash script:

  • spaceman.head.sh
  • spaceman.tail.sh

spaceman.head.sh

This file contains the specifies the execution path of the shell to be used and contains the copyright. This is also the first file used during the concatenation process.

spaceman.tail.sh

This file defines all available command line parameters, which are mapped to there equivalent bash functions. After reading the configuration file using configure_spaceman, spaceman tries to assure a clean way of initialization and termination by calling clean_init and clean_exit.

Personal tools