From 535b7b6a3101b33b9db3350705b96a650b19b50b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 26 Sep 2008 21:59:07 +0200 Subject: [PATCH] Initial import of pkgfs, aka package from sources. It's a simple wrapper to shell scripts to allow building source distribution files through an easy cli. For now it's only able to fetch/build/install a package into a destination directory. Goal is to be able to have same functionality like GNU's stow. I added three template files to allow building: glib2, gmake and libtool. --HG-- extra : convert_revision : 5e52738f97edc0ff4a9e5de48a75834bf0916651 --- pkgfs.conf | 29 +++ pkgfs.sh | 368 ++++++++++++++++++++++++++++ templates/glib2-2.18.1.pkgfs.tmpl | 51 ++++ templates/gmake-3.81.pkgfs.tmpl | 48 ++++ templates/libtool-2.2.6a.pkgfs.tmpl | 51 ++++ 5 files changed, 547 insertions(+) create mode 100644 pkgfs.conf create mode 100755 pkgfs.sh create mode 100755 templates/glib2-2.18.1.pkgfs.tmpl create mode 100755 templates/gmake-3.81.pkgfs.tmpl create mode 100755 templates/libtool-2.2.6a.pkgfs.tmpl diff --git a/pkgfs.conf b/pkgfs.conf new file mode 100644 index 00000000000..eadaef71e83 --- /dev/null +++ b/pkgfs.conf @@ -0,0 +1,29 @@ +# +# Configuration file for pkgfs. +# + +# +# Global destination dir: this is where all +# packages will be installed. +# +PKGFS_DESTDIR=$HOME/pkgfs/depot + +# +# Global directory where source files will be extracted to. +# +PKGFS_BUILDDIR=$HOME/pkgfs/builddir + +# +# Global directory where the source distfiles are stored. +# +PKGFS_SRC_DISTDIR=$HOME/pkgfs/distdir + +# +# Compilation flags for cc and c++. +# +PKGFS_CFLAGS="-O2 -pipe" +PKGFS_CXXFLAGS="$G_CFLAGS" + +# +# END +# diff --git a/pkgfs.sh b/pkgfs.sh new file mode 100755 index 00000000000..ea524df895d --- /dev/null +++ b/pkgfs.sh @@ -0,0 +1,368 @@ +#!/bin/sh +# +# TODO +# Multiple distfiles in a package. +# Support GNU/BSD-makefile style only packages. +# Actually do the symlink dance (stow/unstow). +# Implement listing packages in PKGFS_DISTDIR. +# +# Default path to configuration file, can be overriden +# via the environment or command line. +# +: ${PKGFS_CONFIG_FILE:=/usr/local/etc/pkgfs.conf} + +# Global private stuff +: ${_progname:=$(basename $0)} +: ${_TOP:=$(/bin/pwd -P 2>/dev/null)} +: ${_FETCH_CMD:=/usr/bin/ftp -a} +: ${_CKSUM_CMD:=/usr/bin/cksum -a rmd160} +: ${_AWK_CMD:=/usr/bin/awk} +: ${_MKDIR_CMD:=/bin/mkdir -p} + +_SFILE= +_EXTRACT_CMD= + +usage() { + cat << _EOF +$_progname: [-cef] + +Targets + build Build package from . + info Show information about . + list List packages installed in PKGFS_DESTDIR. + +Options + -c Path to global configuration file. + If not specified /usr/local/etc/pkgfs.conf is used. + -e Only extract the source distribution file(s). + -f Only fetch the source distribution file(s). + +_EOF + exit 1 +} + +check_path() +{ + eval orig="$1" + + case "$orig" in + /) + ;; + /*) + orig="${orig%/}" + ;; + *) + orig="${_TOP}/${orig%/}" + ;; + esac + + _SFILE="$orig" +} + +show_info_from_buildfile() +{ + echo "Template build file definitions:" + echo + echo " pkgname: $pkgname" + for i in "${distfiles}"; do + [ -n "$i" ] && echo " distfile: $i" + done + echo " URL: $url" + echo " maintainer: $maintainer" + [ -n "${checksum}" ] && echo " checksum: $checksum" + echo " build_style: $build_style" + echo " short_desc: $short_desc" + echo "$long_desc" + echo +} + +check_build_vars() +{ + local dfile= + + if [ -z "$distfiles" ]; then + dfile="$pkgname$extract_sufx" + elif [ -n "${distfiles}" ]; then + dfile="$distfiles$extract_sufx" + else + echo "*** ERROR unsupported fetch state ***" + exit 1 + fi + + dfile="$PKGFS_SRC_DISTDIR/$dfile" + + REQ_VARS="pkgname extract_sufx url build_style checksum" + + # Check if required vars weren't set. + for i in "${REQ_VARS}"; do + eval i=\""$$i\"" + if [ -z "$i" ]; then + echo -n "*** ERROR: $i not set (incomplete build" + echo " file), aborting ***" + exit 1 + fi + done + + case "$extract_sufx" in + .tar.bz2|.tar.gz|.tgz|.tbz) + _EXTRACT_CMD="tar xvfz $dfile -C $PKGFS_BUILDDIR" + ;; + .tar) + _EXTRACT_CMD="tar xvf $dfile -C $PKGFS_BUILDDIR" + ;; + .zip) + _EXTRACT_CMD="unzip -x $dfile -C $PKGFS_BUILDDIR" + ;; + *) + echo -n "*** ERROR: unknown 'extract_sufx' argument in build " + echo "file ***" + exit 1 + ;; + esac +} + +check_rmd160_cksum() +{ + local passed_var="$1" + + if [ -z "${distfiles}" ]; then + dfile="$pkgname$extract_sufx" + elif [ -n "${distfiles}" ]; then + dfile="$distfiles$extract_sufx" + else + dfile="$passed_var$extract_sufx" + fi + + origsum="$checksum" + dfile="$PKGFS_SRC_DISTDIR/$dfile" + filesum="$(${_CKSUM_CMD} $dfile | ${_AWK_CMD} '{print $4}')" + if [ "$origsum" != "$filesum" ]; then + echo "*** WARNING: checksum doesn't match (rmd160) ***" + return 1 + fi + + return 0 +} + +fetch_source_distfiles() +{ + local file= + + if [ -z "$distfiles" ]; then + file="$pkgname" + else + file="$distfiles" + fi + + for f in "$file"; do + if [ -f "$PKGFS_SRC_DISTDIR/$f$extract_sufx" ]; then + check_rmd160_cksum $f + if [ "$?" -eq 0 ]; then + if [ -n "${only_fetch}" ]; then + echo + echo -n "=> checksum ok" + echo " (only_fetch set)" + exit 0 + fi + return 0 + fi + fi + echo "*** Fetching $f ***" + cd "$PKGFS_SRC_DISTDIR" && \ + ${_FETCH_CMD} $url/$f$extract_sufx + if [ "$?" -ne 0 ]; then + echo -n "*** ERROR: there was an error fetching " + echo "'$f', aborting ***" + exit 1 + else + if [ -n "${only_fetch}" ]; then + echo + echo "=> checksum ok (only_fetch set)" + exit 0 + fi + fi + done +} + +check_build_dirs() +{ + if [ ! -d "$PKGFS_DESTDIR" ]; then + ${MKDIR_CMD} "$PKGFS_DESTDIR" + if [ "$?" -ne 0 ]; then + echo -n "*** ERROR: couldn't create PKGFS_DESTDIR " + echo "directory, aborting ***" + exit 1 + fi + fi + + if [ ! -d "$PKGFS_BUILDDIR" ]; then + ${MKDIR_CMD} "$PKGFS_BUILDDIR" + if [ "$?" -ne 0 ]; then + echo -n "*** ERROR: couldn't create PKFS_BUILDDIR " + echo "directory, aborting ***" + exit 1 + fi + fi + + if [ -z "$PKGFS_SRC_DISTDIR" ]; then + echo "*** ERROR: PKGFS_SRC_DISTDIR is not set, aborting ***" + exit 1 + fi + + ${MKDIR_CMD} "$PKGFS_SRC_DISTDIR" + if [ "$?" -ne 0 ]; then + echo "*** ERROR couldn't create PKGFS_SRC_DISTDIR, aborting ***" + exit 1 + fi +} + +build_pkg() +{ + + echo "*** Extracting package: $pkgname ***" + ${_EXTRACT_CMD} + if [ "$?" -ne 0 ]; then + echo -n "*** ERROR: there was an error extracting the " + echo "distfile, aborting *** " + exit 1 + fi + + [ -n "${only_extract}" ] && exit 0 + + echo "*** Building package: $pkgname ***" + if [ -z "$wrksrc" ]; then + if [ -z "$distfiles" ]; then + cd $PKGFS_BUILDDIR/$pkgname + else + cd $PKGFS_BUILDDIR/$distfiles + fi + else + cd $PKGFS_BUILDDIR/$wrksrc + fi + # + # Packages using GNU autoconf + # + if [ "$build_style" = "gnu_configure" ]; then + for i in "${configure_env}"; do + export "$i" + done + + ./configure --prefix="${PKGFS_DESTDIR}" "${configure_args}" + if [ "$?" -ne 0 ]; then + echo -n "*** ERROR building (configure state)" + echo " $pkgname ***" + exit 1 + fi + if [ -z "$make_cmd" ]; then + MAKE_CMD="/usr/bin/make" + else + MAKE_CMD="$make_cmd" + fi + + $MAKE_CMD ${make_build_args} + if [ "$?" -ne 0 ]; then + echo "*** ERROR building (make stage) $pkgname ***" + exit 1 + fi + + ${MAKE_CMD} ${make_install_args} \ + install prefix="$PKGFS_DESTDIR/$pkgname" + if [ "$?" -ne 0 ]; then + echo "*** ERROR instaling $pkgname ***" + exit 1 + fi + + echo "*** SUCCESSFUL build for $pkgname ***" + + for i in "${configure_env}"; do + unset "$i" + done + fi +} + +build_pkg_from_source() +{ + check_build_vars + check_build_dirs + fetch_source_distfiles + build_pkg +} + +args=$(getopt c:ef $*) +[ "$?" -ne 0 ] && usage + +set -- $args +while [ "$#" -gt 0 ]; do + case "$1" in + -c) + PKGFS_CONFIG_FILE="$2" + shift + ;; + -e) + only_extract=yes + ;; + -f) + only_fetch=yes + ;; + --) + shift + break + ;; + esac + shift +done + +[ "$#" -gt 2 ] && usage + +_target="$1" +if [ -z "${_target}" ]; then + echo "*** ERROR missing target ***" + usage +fi + +_buildfile="$2" +if [ -z "${_buildfile}" -o ! -f "${_buildfile}" ]; then + echo "*** ERROR: invalid template file '${_buildfile}', aborting ***" + exit 1 +fi + +check_path "${_buildfile}" +. ${_SFILE} + +if [ ! -f "${PKGFS_CONFIG_FILE}" ]; then + echo -n "*** ERROR: cannot find global config file: " + echo "'${PKGFS_CONFIG_FILE}' ***" + exit 1 +fi + +check_path "${PKGFS_CONFIG_FILE}" +. ${_SFILE} + +if [ -z "${PKGFS_DESTDIR}" ]; then + echo "*** ERROR: PKGFS_DESTDIR not set in configuration file ***" + exit 1 +fi + +if [ -z "${PKGFS_BUILDDIR}" ]; then + echo "*** ERROR PKGFS_BUILDDIR not set in configuration file ***" + exit 1; +fi + +# Main switch +case "${_target}" in +build) + build_pkg_from_source + ;; +info) + show_info_from_buildfile + ;; +list) + list_installed_packages + ;; +*) + echo "*** ERROR invalid target '${_target}' ***" + usage +esac + +# Agur +exit 0 diff --git a/templates/glib2-2.18.1.pkgfs.tmpl b/templates/glib2-2.18.1.pkgfs.tmpl new file mode 100755 index 00000000000..21c1ef7a03e --- /dev/null +++ b/templates/glib2-2.18.1.pkgfs.tmpl @@ -0,0 +1,51 @@ +# ----*---- ----*----- +# Template build file for 'glib-2.18.1' +# ----*---- ----*----- +# +# Name of the package, sometimes you need a different name than +# the one used in the source distribution file. +pkgname=glib-2.18.1 + +# Suffix extraction, only supported: zip and tar/tar+(gz|bzip2). +extract_sufx=".tar.bz2" + +# Use this if pkgname doesn't match or if there are multiple +# source distribution files. +#distfiles="" + +# URL to fetch +url=http://ftp.gnome.org/pub/gnome/sources/glib/2.18 + +# Arguments passed to configure if $build_style = {,gnu_}configure. +#configure_args="" + +# Arguments passed to configure through the environment +configure_env="ac_cv_func_statfs=no" + +# Build style: gnu_configure, bsd-makefile, gnu-makefile, configure. +build_style=gnu_configure + +# Passed flags to the 'make' command before building the package. +#make_build_args="" + +# Passed flags to the 'make' command before installing the package. +#make_install_args="" + +# Short description, max 1 line of 72 chars. +short_desc="The GNU library of C routines" + +# Maintainer of this pkg: name . +maintainer="Juan RP " + +# Checksum of file with rmd160. +checksum=264b37584419d983685910adde8f7b282eccc1ad + +# Long description. Preferibly first line should be left blank +# and use a whitespace while starting lines. +# +# Please also respect 72 chars per line if possible (max 80). +# +long_desc=" + GLib is a library containing many useful C routines for things such + as trees, hashes, lists and strings. It is a useful general purpose + C library used by projects such as GTK+, GIMP and GNOME." diff --git a/templates/gmake-3.81.pkgfs.tmpl b/templates/gmake-3.81.pkgfs.tmpl new file mode 100755 index 00000000000..1988f1d82ef --- /dev/null +++ b/templates/gmake-3.81.pkgfs.tmpl @@ -0,0 +1,48 @@ +# ----*---- ----*----- +# Template build file for 'gmake-3.81' +# ----*---- ----*----- +# +# Name of the package, sometimes you need a different name than +# the one used in the source distribution file. +pkgname=gmake-3.81 + +# Suffix extraction, only supported: zip and tar/tar+(gz|bzip2). +extract_sufx=".tar.bz2" + +# Use this if pkgname doesn't match or if there are multiple +# source distribution files. +distfiles="make-3.81" + +# URL to fetch +url=http://ftp.gnu.org/pub/gnu/make + +# Arguments passed to configure if $build_style = {,gnu_}configure. +configure_args="--program-prefix=g" + +# Build style: gnu_configure, bsd-makefile, gnu-makefile, configure. +build_style=gnu_configure + +# Passed flags to the 'make' command before building the package. +make_build_args="" + +# Passed flags to the 'make' command before installing the package. +#make_install_args="" + +# Short description, max 1 line of 72 chars. +short_desc="The GNU make system" + +# Maintainer of this pkg: name . +maintainer="Juan RP " + +# Checksum of file with rmd160. +checksum=79d418e1258ec0d6ba08b1431a4ade3fec54c2b2 + +# Long description. Preferibly first line should be left blank +# and use a whitespace while starting lines. +# +# Please also respect 72 chars per line if possible (max 80). +# +long_desc=" + GNU Make is a program that determines which pieces of a large + program need to be recompiled and issues the commands to + recompile them, when necessary." diff --git a/templates/libtool-2.2.6a.pkgfs.tmpl b/templates/libtool-2.2.6a.pkgfs.tmpl new file mode 100755 index 00000000000..995cbfff7b4 --- /dev/null +++ b/templates/libtool-2.2.6a.pkgfs.tmpl @@ -0,0 +1,51 @@ +# ----*---- ----*----- +# Template build file for 'libtool-2.2.6a' +# ----*---- ----*----- +# +# Local variable only used in this template. +_mypkgname=libtool-2.2.6 +# Name of the package, sometimes you need a different name than +# the one used in the source distribution file. +pkgname=${_mypkgname}a + +# Suffix extraction, only supported: zip and tar/tar+(gz|bzip2). +extract_sufx=".tar.gz" + +# Use this if extracted directory from source distribution file +# is not the same than pkgname. +wrksrc=${_mypkgname} + +# Use this if pkgname doesn't match or if there are multiple +# source distribution files. +#distfiles="" + +# URL to fetch +url=http://ftp.gnu.org/pub/gnu/libtool + +# Arguments passed to configure if $build_style = {,gnu_}configure. +#configure_args="" + +# Build style: gnu_configure, bsd-makefile, gnu-makefile, configure. +build_style=gnu_configure + +make_build_flags="-j8" +make_install_flags="" + +# Short description, max 1 line of 72 chars. +short_desc="Generic library support" + +# Maintainer of this pkg: name . +maintainer="Juan RP " + +# Checksum of file with rmd160. +checksum=f8862338e2c6ea04332fd5aad4aad5bc35d0e152 + +# Long description. Preferibly first line should be left blank +# and use a whitespace while starting lines. +# +# Please also respect 72 chars per line if possible (max 80). +# +long_desc=" + This is GNU libtool, a generic library support script. Libtool hides + the complexity of generating special library types (such as shared + libraries) befind a consistent interface."