diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/.gitignore | 9 | ||||
-rw-r--r-- | scripts/Makefile.am | 62 | ||||
-rw-r--r-- | scripts/abs | 77 | ||||
-rw-r--r-- | scripts/abs.sh.in | 173 | ||||
-rwxr-xr-x | scripts/gensync | 128 | ||||
-rw-r--r-- | scripts/gensync.sh.in | 158 | ||||
-rwxr-xr-x | scripts/makepkg | 1088 | ||||
-rw-r--r-- | scripts/makepkg.sh.in | 1470 | ||||
-rwxr-xr-x | scripts/makeworld | 172 | ||||
-rw-r--r-- | scripts/makeworld.sh.in | 194 | ||||
-rwxr-xr-x | scripts/pacman-optimize | 145 | ||||
-rw-r--r-- | scripts/pacman-optimize.sh.in | 164 | ||||
-rw-r--r-- | scripts/rankmirrors.py.in (renamed from scripts/rankmirrors) | 34 | ||||
-rwxr-xr-x | scripts/repo-add | 288 | ||||
-rw-r--r-- | scripts/repo-add.sh.in | 346 | ||||
-rwxr-xr-x | scripts/repo-remove | 136 | ||||
-rw-r--r-- | scripts/repo-remove.sh.in | 184 | ||||
-rwxr-xr-x | scripts/updatesync | 131 | ||||
-rw-r--r-- | scripts/updatesync.sh.in | 157 |
19 files changed, 2936 insertions, 2180 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 00000000..17a2a41e --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,9 @@ +abs +gensync +makepkg +makeworld +pacman-optimize +rankmirrors +repo-add +repo-remove +updatesync diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 57baee49..01250f5b 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,9 +1,7 @@ -# TODO: this would be nice to enable, but we need --help and --version -# flags on all of our scripts first (this is what it checks) -#AUTOMAKE_OPTIONS = std-options +# enforce that all scripts have a --help and --version option +AUTOMAKE_OPTIONS = std-options bin_SCRIPTS = \ - abs \ gensync \ makepkg \ makeworld \ @@ -13,6 +11,58 @@ bin_SCRIPTS = \ repo-remove \ updatesync -EXTRA_DIST = $(bin_SCRIPTS) +if INCLUDE_ABS +bin_SCRIPTS += abs +endif -abs gensync makepkg makeworld pacman-optimize rankmirrors repo-add repo-remove re-pacman updatesync: +EXTRA_DIST = \ + abs.sh.in \ + gensync.sh.in \ + makepkg.sh.in \ + makeworld.sh.in \ + pacman-optimize.sh.in \ + rankmirrors.py.in \ + repo-add.sh.in \ + repo-remove.sh.in \ + updatesync.sh.in + +# Files that should be removed, but which Automake does not know. +MOSTLYCLEANFILES = $(bin_SCRIPTS) *.tmp + +#### Taken from the autoconf scripts Makefile.am #### +edit = sed \ + -e 's|@localedir[@]|$(localedir)|g' \ + -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ + -e 's|@localstatedir[@]|$(localstatedir)|g' \ + -e 's|@prefix[@]|$(prefix)|g' \ + -e 's|@PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \ + -e 's|@PACKAGE_BUGREPORT[@]|$(PACKAGE_BUGREPORT)|g' \ + -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \ + -e 's|@configure_input[@]|Generated from $@.in; do not edit by hand.|g' + +## All the scripts depend on Makefile so that they are rebuilt when the +## prefix etc. changes. Use chmod -w to prevent people from editing the +## wrong file by accident. +# two 'test' lines- make sure we can handle both sh and py type scripts +# third 'test' line- make sure one of the two checks succeeded +$(bin_SCRIPTS): Makefile + rm -f $@ $@.tmp + test -f $(srcdir)/$@.sh.in && $(edit) $(srcdir)/$@.sh.in >$@.tmp || true + test -f $(srcdir)/$@.py.in && $(edit) $(srcdir)/$@.py.in >$@.tmp || true + test -f $@.tmp || false + chmod +x $@.tmp + chmod a-w $@.tmp + mv $@.tmp $@ + +abs: $(srcdir)/abs.sh.in +gensync: $(srcdir)/gensync.sh.in +makepkg: $(srcdir)/makepkg.sh.in +makeworld: $(srcdir)/makeworld.sh.in +pacman-optimize: $(srcdir)/pacman-optimize.sh.in +rankmirrors: $(srcdir)/rankmirrors.py.in +repo-add: $(srcdir)/repo-add.sh.in +repo-remove: $(srcdir)/repo-remove.sh.in +re-pacman: $(srcdir)/re-pacman.sh.in +updatesync: $(srcdir)/updatesync.sh.in + +# vim:set ts=2 sw=2 noet: diff --git a/scripts/abs b/scripts/abs deleted file mode 100644 index 2ec4322c..00000000 --- a/scripts/abs +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -CONFDIR="/etc/abs" -CONNMODE="m" - -[ -f "$CONFDIR/abs.conf" ] && source "$CONFDIR/abs.conf" - -#user based overrides -[ -f ~/.abs.conf ] && source ~/.abs.conf - -usage() { - echo "Arch Build System -- synchronization utility" - echo "usage: $0 [-p] [repository1 [repository2 ...]]" - echo - echo "abs will synchronize PKGBUILD scripts from the CVS repository" - echo "into $ABSROOT. You can follow different package trees by" - echo "editing /etc/abs/supfile.* files. If no argument is given, abs " - echo "will synchronize from supfiles specified in /etc/abs/abs.conf." - echo "If -p is specified, the connection is opened in passive mode." -} - -update() { - cd "$ABSROOT" - for sup in "${SUPFILES[@]}"; do - if [ "$sup" != "testing" ]; then - if [ "$sup" = "${sup#!}" ]; then - $CVSUP -L 1 -r 0 -g -b "$ABSROOT" -P $CONNMODE -c .sup "$CONFDIR/supfile.$sup" - fi - elif [ "$sup" = "testing" ]; then - if [ ! -d "$ABSROOT/testing" ]; then - mkdir "$ABSROOT/testing" - fi - cd "$ABSROOT/testing" - $CVSUP -L 1 -r 0 -g -b "$ABSROOT/testing" -P $CONNMODE -c .sup "$CONFDIR/supfile.testing" - cd "$ABSROOT" - fi - done -} - -if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then - usage - exit 0 -fi - -if [ ! -d "$ABSROOT" ]; then - echo "abs: $ABSROOT does not exist (or is not a directory)" - exit 1 -fi -if [ ! -w "$ABSROOT" ]; then - echo "abs: no write permissions in $ABSROOT" - exit 1 -fi - -if [ "$(type -p cvsup)" ]; then - CVSUP="cvsup" -elif [ "$(type -p csup)" ]; then - CVSUP="csup" -else - echo "abs: missing CVS synchronization utility. Install cvsup or csup." - exit 1 -fi - -if [ "$1" = "-p" ] || [ "$1" = "--passive" ]; then - CONNMODE="-" - shift -else - CONNMODE="m" -fi - -if [ "$#" -ne "0" ]; then - SUPFILES=("$@") -fi - -update - -exit 0 -# vim: set ts=2 sw=2 noet: diff --git a/scripts/abs.sh.in b/scripts/abs.sh.in new file mode 100644 index 00000000..ae825259 --- /dev/null +++ b/scripts/abs.sh.in @@ -0,0 +1,173 @@ +#!/bin/bash -e +# +# abs - download a PKGBUILD tree from a CVS repository +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +## +# Script Exit Reasons +# ------------------- +# E_OK : Everything worked :) +# E_MISSING_PROGRAM : A program the script depends on is not installed. +# E_CONFIG_ERROR : Missing/incorrect configuration. +# E_INVALID_OPTION : User has passed unknown/invalid option to script. +## + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' +BUG_REPORT_EMAIL='@PACKAGE_BUGREPORT@' +CONFDIR="@sysconfdir@/abs" +PASSIVE='m' + +# Source config files +if [ -r "$CONFDIR/abs.conf" ]; then + source "$CONFDIR/abs.conf" +fi + +# User based overrides +if [ -r ~/.abs.conf ]; then + source ~/.abs.conf +fi + + +msg() { + local mesg=$1; shift + printf "==> ${mesg}\n" "$@" >&2 +} + +error() { + local mesg=$1; shift + printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 +} + + +usage() { + printf "$(gettext "abs (pacman) %s - download a PKGBUILD tree from a CVS repository")\n\n" "$myver" + printf "$(gettext "Usage %s [options] [repository...]")\n\n" "$0" + printf "$(gettext "Options:")\n" + printf "$(gettext " -p, --passive The connection is opened in passive mode.")\n" + echo + printf "$(gettext " -h, --help Display this help message then exit.")\n" + printf "$(gettext " -V, --version Display version information then exit.")\n" + echo + printf "$(gettext "\ +abs will synchronize build scripts from the CVS repository\n\ +into %s. You can follow different package trees by\n\ +editing %s files. If no argument is given, abs\n\ +will synchronize from supfiles specified in %s.\n\n")" \ + "$ABSROOT" "$CONFDIR/supfile.*" "$CONFDIR/abs.conf" + printf "$(gettext "Report bugs to <%s>.")\n" "$BUG_REPORT_EMAIL" +} + +version() { + printf "abs (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + + +## +# Signal Traps +## +trap 'error "$(gettext "TERM signal caught. Exiting...")"; exit 1' TERM HUP QUIT +trap 'error "$(gettext "Aborted by user! Exiting...")"; exit 1' INT +trap 'error "$(gettext "An unknown error has occured. Exiting...")"; exit 1' ERR + + +# Parse Command Line Options. +OPT_SHORT="hpV" +OPT_LONG="help,passive,version" +OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')" +if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then + # This is a small hack to stop the script bailing with 'set -e' + echo; usage; exit 1 # E_INVALID_OPTION; +fi +eval set -- "$OPT_TEMP" +unset OPT_SHORT OPT_LONG OPT_TEMP + +while true; do + case "$1" in + -p|--passive) PASSIVE='-';; + + -h|--help) usage; exit 0;; # E_OK + -V|--version) version; exit 0;; # E_OK + + --) OPT_IND=0; shift; break;; + *) usage; exit 1;; # E_INVALID_OPTION + esac + shift +done + +if [ $# -gt 0 ]; then + SUPFILES=("$@") +fi + + +# Check permissions and programs. +if [ ! -d "$ABSROOT" ]; then + error "$(gettext "%s does not exist or is not a directory.")" "$ABSROOT" + exit 1 # E_CONFIG_ERROR +elif [ ! -w "$ABSROOT" ]; then + error "$(gettext "You do not have write permissions in %s.")" "$ABSROOT" + exit 1 # E_CONFIG_ERROR +fi + + +if [ "$(type -p csup)" ]; then + CVSUP="csup" +elif [ "$(type -p cvsup)" ]; then + CVSUP="cvsup" +else + error "$(gettext "Missing CVS synchronization utility. Install csup or cvsup.")" + exit 1 # E_MISSING_PROGRAM +fi + + +# Begin script. +for sup in ${SUPFILES[@]}; do + case "$sup" in + testing) + if [ ! -d "$ABSROOT/$sup" ]; then + mkdir "$ABSROOT/$sup" + fi + workdir="$ABSROOT/$sup" + ;; + + *) + if [ "$sup" != "${sup#!}" ]; then + continue + fi + workdir="$ABSROOT" + ;; + esac + + msg "$(gettext "Updating %s...")" "$sup" + cd "$workdir" + $CVSUP -L 1 -r 0 -g -b "$workdir" -P "$PASSIVE" -c .sup "$CONFDIR/supfile.$sup" +done + +exit 0 # E_OK + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/gensync b/scripts/gensync deleted file mode 100755 index 5a3dab88..00000000 --- a/scripts/gensync +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash -# -# gensync -# -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. -# - -myver='3.0.0' - -usage() { - echo "gensync $myver" - echo "usage: $0 <root> <destfile> [package_directory]" - echo - echo "gensync will generate a sync database by reading all PKGBUILD files" - echo "from <root>. gensync builds the database in a temporary directory" - echo "and then compresses it to <destfile>." - echo - echo "gensync will calculate md5sums of packages in the same directory as" - echo "<destfile>, unless an alternate [package_directory] is specified." - echo - echo "note: The <destfile> name is important. It must be of the form" - echo " {treename}.db.tar.gz where {treename} is the name of the custom" - echo " package repository you configured in /etc/pacman.conf. The" - echo " generated database must reside in the same directory as your" - echo " custom packages (also configured in /etc/pacman.conf)" - echo - echo "example: gensync /var/abs/local /home/mypkgs/custom.db.tar.gz" - echo - echo - exit 0 -} - -BUILDSCRIPT="PKGBUILD" -PKGEXT="pkg.tar.gz" - -source /etc/makepkg.conf - -error () { - echo "==> ERROR: $*" >&2 -} - -die () { - error $* - exit 1 -} - -check_force () { - local i - for i in ${options[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "force" ]; then - true - fi - done - false -} - -if [ $# -lt 2 ]; then - usage - exit 1 -fi - -if [ "$1" = "-h" -o "$1" = "--help" ]; then - usage - exit 0 -fi - -d=$(dirname $1) -rootdir="$(cd $d && pwd)/$(basename $1)" -d="$(dirname $2)" -destdir="$(cd $d && pwd)" -destfile="$destdir/$(basename $2)" -pkgdir="" -if [ "$3" != "" ]; then - pkgdir="$3" -fi - -[ ! -d "$rootdir" ] && die "invalid root dir: $rootdir" - -echo "gensync: building database entries, generating md5sums..." >&2 -cd "$destdir" - -pkgs="" -forcepkgs="" - -for file in $(find "$rootdir"/* -name "$BUILDSCRIPT"); do - unset pkgname pkgver pkgrel options - - source $file || die "failed to parse parse $file" - if [ "$pkgdir" != "" ]; then - pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT" - else - pkgfile="$destdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT" - fi - - if [ ! -f "$pkgfile" ]; then - error "could not find $pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT - skipping" - else - if check_force; then - forcepkgs="$forcepkgs $pkgfile" - else - pkgs="$pkgs $pkgfile" - fi - fi -done - -echo "creating repo DB..." - -# we'll trim the output just a tad, as gensync may be used on large repos -repo-add $destfile $pkgs --force $force_pkgs \ - | grep -e "package" -e "database" - -# vim: set ts=2 sw=2 noet: diff --git a/scripts/gensync.sh.in b/scripts/gensync.sh.in new file mode 100644 index 00000000..8109fe22 --- /dev/null +++ b/scripts/gensync.sh.in @@ -0,0 +1,158 @@ +#!/bin/bash +# +# gensync +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' + +# functions + +usage() { + printf "gensync (pacman) %s\n\n" "$myver" + printf "$(gettext "Usage: %s <root> <destfile> [package_directory]")\n\n" "$0" + printf "$(gettext "\ +gensync will generate a sync database by reading all PKGBUILD files\n\ +from <root>. gensync builds the database in a temporary directory\n\ +and then compresses it to <destfile>.\n\n")" + printf "$(gettext "\ +gensync will calculate md5sums of packages in the same directory as\n\ +<destfile>, unless an alternate [package_directory] is specified.\n\n")" + printf "$(gettext "\ +note: The <destfile> name is important. It must be of the form\n\ + {treename}.db.tar.gz where {treename} is the name of the custom\n\ + package repository you configured in /etc/pacman.conf. The\n\ + generated database must reside in the same directory as your\n\ + custom packages (also configured in /etc/pacman.conf)\n\n")" + echo "$(gettext "Example: gensync /var/abs/local /home/mypkgs/custom.db.tar.gz")" + exit 0 +} + +version() { + printf "gensync (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +error () { + local mesg=$1; shift + printf "==> ERROR: ${mesg}\n" "$@" >&2 +} + +die () { + error $* + exit 1 +} + +check_force () { + local i + for i in ${options[@]}; do + local lc=$(echo $i | tr [:upper:] [:lower:]) + if [ "$lc" = "force" ]; then + true + fi + done + false +} + +# PROGRAM START + +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage + exit 0 +fi + +if [ "$1" = "-V" -o "$1" = "--version" ]; then + version + exit 0 +fi + +if [ $# -lt 2 ]; then + usage + exit 1 +fi + +# source system and user makepkg.conf +if [ -r @sysconfdir@/makepkg.conf ]; then + source @sysconfdir@/makepkg.conf +else + die "$(gettext "%s not found. Can not continue.")" "@sysconfdir@/makepkg.conf" +fi + +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + + +d=$(dirname $1) +rootdir="$(cd $d && pwd)/$(basename $1)" +d="$(dirname $2)" +destdir="$(cd $d && pwd)" +destfile="$destdir/$(basename $2)" +pkgdir="" +if [ "$3" != "" ]; then + pkgdir="$3" +fi + +[ ! -d "$rootdir" ] && die "$(gettext "invalid root dir: %s")" $rootdir + +echo "$(gettext "gensync: building database entries, generating md5sums...")" >&2 +cd "$destdir" + +pkgs="" +forcepkgs="" + +for file in $(find "$rootdir"/* -name "$BUILDSCRIPT"); do + unset pkgname pkgver pkgrel options + + source $file || die "$(gettext "failed to parse parse %s")" $file + if [ "$arch" = 'any' ]; then + CARCH='any' + fi + if [ "$pkgdir" != "" ]; then + pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT" + else + pkgfile="$destdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT" + fi + + if [ ! -f "$pkgfile" ]; then + error "$(gettext "could not find %s-%s-%s-%s.%s - skipping")" $pkgname $pkgver $pkgrel $CARCH $PKGEXT + else + if check_force; then + forcepkgs="$forcepkgs $pkgfile" + else + pkgs="$pkgs $pkgfile" + fi + fi +done + +echo "$(gettext "creating repo DB...")" + +# we'll trim the output just a tad, as gensync may be used on large repos +repo-add $destfile $pkgs --force $force_pkgs \ + | grep -e "package" -e "database" + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/makepkg b/scripts/makepkg deleted file mode 100755 index c192855f..00000000 --- a/scripts/makepkg +++ /dev/null @@ -1,1088 +0,0 @@ -#!/bin/bash -# -# makepkg - make packages compatable for use with pacman -# -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> -# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> -# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> -# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk> -# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. -# - -myver='3.0.3' -startdir=$(pwd) - -BUILDSCRIPT="PKGBUILD" -PKGEXT="pkg.tar.gz" - -source "/etc/abs/abs.conf" -SRCROOT="$ABSROOT" - -# Options -CLEANUP=0 -CLEANCACHE=0 -DEP_BIN=0 -DEP_SRC=0 -SUDO=0 -FORCE=0 -GENINTEG=0 -INSTALL=0 -NOBUILD=0 -NODEPS=0 -NOEXTRACT=0 -RMDEPS=0 -REPKG=0 -LOGGING=0 - -PACMAN_OPTS= - -#determine if we are running with fakeroot -if [ "$1" = "-F" ]; then - INFAKEROOT=1 - shift -else - INFAKEROOT=0 -fi - -### SUBROUTINES ### - -plain() { - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - echo -e " \033[1;1m$1\033[1;0m" >&2 - else - echo " $1" >&2 - fi -} - -msg() { - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - echo -e "\033[1;32m==>\033[1;0m \033[1;1m$1\033[1;0m" >&2 - else - echo "==> $1" >&2 - fi -} - -msg2() { - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - echo -e " \033[1;34m->\033[1;0m \033[1;1m$1\033[1;0m" >&2 - else - echo " -> $1" >&2 - fi -} - -warning() { - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - echo -e "\033[1;33m==> WARNING:\033[1;0m \033[1;1m$1\033[1;0m" >&2 - else - echo "==> WARNING: $1" >&2 - fi -} - -error() { - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2 - else - echo "==> ERROR: $1" >&2 - fi -} - -strip_url() { - echo "$1" | sed 's|^.*://.*/||g' -} - -# checks to see if options are present in makepkg.conf or PKGBUILD; -# PKGBUILD options always take precedence -check_option() { - local needle=$(echo $1 | tr [:upper:] [:lower:]) - local i - # loop PKGBUILD opts first so it overrides makepkg.conf - for i in ${options[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "$needle" ]; then - echo "y" - return - elif [ "$lc" = "!$needle" ]; then - echo "n" - return - # START DEPRECATED - # TODO This code should be removed in the next release of makepkg - elif [ "$lc" = "no$needle" ]; then - warning "Options beginning with 'no' will be depricated in the next version of makepkg!" - plain "Please replace 'no' with '!': no$needle -> !$needle." - echo "n" - return - elif [ "$lc" = "keepdocs" -a "$needle" = "docs" ]; then - warning "Option 'keepdocs' may not work as intended. Please replace with 'docs'." - # END DEPRECATED - fi - done - # fall back to makepkg.conf options - for i in ${OPTIONS[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "$needle" ]; then - echo "y" - return - elif [ "$lc" = "!$needle" ]; then - echo "n" - return - fi - done - echo "unknown" - return -} - -# check if option is present in BUILDENV -check_buildenv() { - local needle=$(echo $1 | tr [:upper:] [:lower:]) - local i - # use options from makepkg.conf - for i in ${BUILDENV[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "$needle" ]; then - echo "y" - return - elif [ "$lc" = "!$needle" ]; then - echo "n" - return - fi - done - echo "unknown" - return -} - -in_array() { - local needle=$1 - shift 1 - [ -z "$1" ] && return 1 - for i in $*; do - [ "$i" = "$needle" ] && return 0 - done - return 1 -} - -checkdeps() { - [ $# -gt 0 ] || return - - pmout=$(pacman $PACMAN_OPTS -T $*) - ret=$? - if [ $ret -eq 1 ]; then #unresolved deps - echo $pmout - elif [ $ret -ne 0 ]; then - error "pacman returned a fatal error ($ret): $pmout" - exit 1 - fi -} - -handledeps() { - local missingdeps=0 - local deplist="$*" - local depstrip="" - local striplist="" - local haveperm=0 - if [ \( "$EUID" = "0" -a "$INFAKEROOT" != "1" \) -o "$SUDO" = 1 ]; then - haveperm=1 - fi - - for dep in $deplist; do - depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||') - striplist="$striplist $depstrip" - done - - if [ "$deplist" != "" -a $haveperm -eq 1 ]; then - if [ "$DEP_BIN" = "1" -a "$SUDO" = "1" ]; then - # install missing deps from binary packages (using pacman -S and sudo) - msg "Installing missing dependencies..." - if [ "$INFAKEROOT" = "1" ]; then - # kinda hacky, but we need to make pacman think that we're NOT - # in fakeroot so it will go ahead and install the dependencies. - FAKEROOTKEY2=$FAKEROOTKEY - unset FAKEROOTKEY - fi - sudo pacman $PACMAN_OPTS -S $striplist - if [ $? -eq 1 ]; then - error "Pacman failed to install missing dependencies." - exit 1 - fi - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY=$FAKEROOTKEY2 - unset FAKEROOTKEY2 - fi - elif [ "$DEP_BIN" = "1" ]; then - # install missing deps from binary packages (using pacman -S) - msg "Installing missing dependencies..." - pacman $PACMAN_OPTS -S $striplist - if [ $? -eq 1 ]; then - error "Pacman failed to install missing dependencies." - exit 1 - fi - elif [ "$DEP_SRC" = "1" ]; then - # install missing deps by building them from source. - # we look for each package name in $SRCROOT and build it. - if [ "$SRCROOT" = "" ]; then - error "Source root cannot be found - please make sure it is specified in /etc/makepkg.conf" - exit 1 - fi - # TODO: handle version comparators (eg, glibc>=2.2.5) - msg "Building missing dependencies..." - for dep in $striplist; do - candidates=$(find $SRCROOT -type d -name "$dep") - if [ "$candidates" = "" ]; then - error "Could not find \"$dep\" under $SRCROOT" - exit 1 - fi - success=0 - for pkgdir in $candidates; do - if [ -f "$pkgdir/$BUILDSCRIPT" ]; then - cd "$pkgdir" - if [ "$RMDEPS" = "1" ]; then - PKGDEST="$PKGDEST" makepkg -i -c -b -r - else - PKGDEST="$PKGDEST" makepkg -i -c -b - fi - if [ $? -eq 0 ]; then - success=1 - break - fi - fi - done - if [ "$success" = "0" ]; then - error "Failed to build \"$dep\"" - exit 1 - fi - done - else - missingdeps=1 - fi - elif [ "$deplist" != "" -a $haveperm -eq 0 ]; then - if [ "$DEP_SRC" = "1" -o "$DEP_BIN" = "1" ]; then - warning "Cannot auto-install missing dependencies as a normal user without sudo!" - plain "Run makepkg as root or with -S to resolve dependencies automatically." - fi - missingdeps=1 - fi - - # rerun any additional sh scripts found in /etc/profile.d/ - for i in /etc/profile.d/*.sh - do - if [ -x $i ]; then - . $i &>/dev/null - fi - done - - return $missingdeps -} - -resolvedeps() { - deplist="" - newdeplist="" - - deplist=$(checkdeps $*) - if [ -n "${deplist}" ]; then - handledeps $deplist - if [ $? -eq 0 ]; then - # check deps again to make sure they were resolved - newdeplist=$(checkdeps $*) - if [ -n "${newdeplist}" ]; then - error "Failed to install all missing dependencies." - fi - else - newdeplist="$deplist" - fi - fi - - # if new dep list is not empty, print the list - if [ -n "${newdeplist}" ]; then - msg "Missing Dependencies:" - for dep in ${newdeplist}; do - msg2 "${dep}" - done - return 1 - else - return 0 - fi -} - -# fix flyspray bug #5923 -removedeps() { - # runtimedeps and buildtimedeps are set when resolving deps - local deplist="$runtimedeps $buildtimedeps" - local depstrip="" - local striplist="" - - for dep in $deplist; do - depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||') - striplist="$striplist $depstrip" - done - - if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a -n "$deplist" ]; then - msg "Removing installed dependencies..." - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY2=$FAKEROOTKEY - unset FAKEROOTKEY - fi - sudo pacman $PACMAN_OPTS -Rs $striplist - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY=$FAKEROOTKEY2 - unset FAKEROOTKEY2 - fi - elif [ "$RMDEPS" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" -a -n "$deplist" ]; then - msg "Removing installed dependencies..." - pacman $PACMAN_OPTS -Rs $striplist - fi -} - -installpackage() { - if [ "$INSTALL" = "1" -a "$SUDO" = "1" ]; then - msg "Installing package with pacman -U..." - if [ "$INFAKEROOT" = "1" ]; then - FAKEROOTKEY2=$FAKEROOTKEY - unset FAKEROOTKEY - fi - sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT} - local exitcode=$? - if [ "$INFAKEROOT" = "1" ]; then - export FAKEROOTKEY=$FAKEROOTKEY2 - unset FAKEROOTKEY2 - fi - exit $exitcode - elif [ "$INSTALL" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" ]; then - msg "Installing package with pacman -U..." - pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT} - exit $? - fi -} - -usage() { - echo "makepkg version $myver" - echo - echo "Usage: $0 [options]" - echo - echo "Options:" - echo " -b, --builddeps Build missing dependencies from source" - echo " -c, --clean Clean up work files after build" - echo " -C, --cleancache Clean up source files from the cache" - echo " -d, --nodeps Skip all dependency checks" - echo " -e, --noextract Do not extract source files (use existing src/ dir)" - echo " -f, --force Overwrite existing package" - echo " -g, --geninteg Generate integrity checks for source files" - echo " -h, --help This help" - echo " -i, --install Install package after successful build" - echo " -L, --log Log package build process" - echo " -m, --nocolor Disable colorized output messages" - echo " -o, --nobuild Download and extract files only" - echo " -p <buildscript> Use an alternate build script (instead of '$BUILDSCRIPT')" - echo " -r, --rmdeps Remove installed dependencies after a successful build" - # fix flyspray feature request #2978 - echo " -R, --repackage Repackage contents of pkg/ without building" - echo " -s, --syncdeps Install missing dependencies with pacman" - echo " -S, --usesudo When calling pacman, use sudo" - echo - echo "These options can be passed to pacman:" - echo - echo " --noconfirm Do not ask for confirmation when resolving dependencies" - echo " --noprogressbar Do not show a progress bar when downloading files" - echo - echo "If -p is not specified, makepkg will look for '$BUILDSCRIPT'" - echo -} - -ARGLIST=$@ - -#preserve environment variables -_PKGDEST=${PKGDEST} -_SRCDEST=${SRCDEST} - -#Source makepkg.conf; fail if it is not found -if [ -f /etc/makepkg.conf ]; then - source /etc/makepkg.conf -else - error "/etc/makepkg.conf not found. cannot continue" - exit 1 -fi - -#Source user-specific makepkg.conf overrides -if [ -f ~/.makepkg.conf ]; then - source ~/.makepkg.conf -fi - -# override settings with an environment variable for batch processing -PKGDEST=${_PKGDEST:-$PKGDEST} -PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined -SRCDEST=${_SRCDEST:-$SRCDEST} -SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined - -while [ "$#" -ne "0" ]; do - case $1 in - # pacman - --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;; - --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;; - # makepkg - --clean) CLEANUP=1 ;; - --cleancache) CLEANCACHE=1 ;; - --syncdeps) DEP_BIN=1 ;; - --usesudo) SUDO=1 ;; - --builddeps) DEP_SRC=1 ;; - --nodeps) NODEPS=1 ;; - --noextract) NOEXTRACT=1 ;; - --install) INSTALL=1 ;; - --force) FORCE=1 ;; - --nobuild) NOBUILD=1 ;; - --nocolor) USE_COLOR="n" ;; - --geninteg) GENINTEG=1 ;; - --rmdeps) RMDEPS=1 ;; - --repackage) REPKG=1 ;; - --log) LOGGING=1 ;; - --help) - usage - exit 0 - ;; - --*) - usage - exit 1 - ;; - -*) - while getopts "bcCdefghiLmop:rRsS-" opt; do - case $opt in - b) DEP_SRC=1 ;; - c) CLEANUP=1 ;; - C) CLEANCACHE=1 ;; - d) NODEPS=1 ;; - e) NOEXTRACT=1 ;; - f) FORCE=1 ;; - g) GENINTEG=1 ;; - h) - usage - exit 0 - ;; - i) INSTALL=1 ;; - L) LOGGING=1 ;; - m) USE_COLOR="n" ;; - o) NOBUILD=1 ;; - p) BUILDSCRIPT=$OPTARG ;; - r) RMDEPS=1 ;; - R) REPKG=1 ;; - s) DEP_BIN=1 ;; - S) SUDO=1 ;; - -) - OPTIND=0 - break - ;; - *) - usage - exit 1 - ;; - esac - done - ;; - *) - true - ;; - esac - shift -done - -# check for sudo -if [ "$SUDO" = "1" -a ! "$(type -p sudo)" ]; then - error "Cannot find the sudo binary! Is sudo installed?" - exit 1 -fi - -if [ "$CLEANCACHE" = "1" ]; then - #fix flyspray feature request #5223 - if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then - msg "Cleaning up ALL files from $SRCDEST." - echo -n " Are you sure you wish to do this? [Y/n] " - read answer - answer=$(echo $answer | tr [:upper:] [:lower:]) - if [ "$answer" = "yes" -o "$answer" = "y" ]; then - rm "$SRCDEST"/* - if [ $? -ne 0 ]; then - error "Problem removing files; you may not have correct permissions in $SRCDEST" - exit 1 - else - # removal worked - msg "Source cache cleaned." - exit 0 - fi - else - # answer = no - msg "No files have been removed." - exit 0 - fi - else - # $SRCDEST is $startdir, two possibilities - error "Source destination must be defined in makepkg.conf." - plain "In addition, please run makepkg -C outside of your cache directory." - exit 1 - fi -fi - -unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums force -unset replaces depends conflicts backup source install build makedepends -unset options noextract - -if [ ! -f $BUILDSCRIPT ]; then - error "$BUILDSCRIPT does not exist." - exit 1 - #TODO this is an attempt at a generic way to unset all package specific - #variables in a PKGBUILD - #else - # #this is fun.... we'll unset - # for var in $(grep "=" $BUILDSCRIPT | sed "s|.*\(\<.*\>\)=.*|\1|g"); do - # unset $var - # done -fi - -source $BUILDSCRIPT - -# check for no-no's in the build script -if [ -z "$pkgver" ]; then - error "pkgver is not allowed to be empty." - exit 1 -fi -if [ -z "$pkgrel" ]; then - error "pkgrel is not allowed to be empty." - exit 1 -fi -if [ $(echo "$pkgver" | grep '-') ]; then - error "pkgver is not allowed to contain hyphens." - exit 1 -fi -if [ $(echo "$pkgrel" | grep '-') ]; then - error "pkgrel is not allowed to contain hyphens." - exit 1 -fi -if ! in_array $CARCH ${arch[@]}; then - error "$pkgname is not available for the '$CARCH' architecture." - plain "Note that many packages may need a line added to their $BUILDSCRIPT" - plain "such as arch=('$CARCH')." - exit 1 -fi - -if [ "$install" -a ! -f "$install" ]; then - error "install scriptlet ($install) does not exist." - exit 1 -fi - -if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.${PKGEXT}" \ - -a "$FORCE" = "0" -a "$GENINTEG" = "0" ]; then - if [ "$INSTALL" = "1" ]; then - warning "a package has already been built, installing existing package." - installpackage - exit $? - else - error "a package has already been built. (use -f to overwrite)" - exit 1 - fi -fi - -# Enter the fakeroot environment if necessary. This will call the makepkg -# script again as the fake root user. We detect this by passing a sentinel -# option (-F) to makepkg. -if [ "$EUID" != "0" ]; then - if [ "$(check_buildenv fakeroot)" = "y" ]; then - if [ $(type -p fakeroot) ]; then - msg "Entering fakeroot environment" - fakeroot -- $0 -F $ARGLIST - exit $? - else - warning "Fakeroot is not installed. Building as an unprivileged user" - plain "will result in non-root ownership of the packaged files. Install" - plain "the fakeroot package to correctly build as a non-root user." - plain "" - sleep 1 - fi - else - warning "Running makepkg as an unprivileged user will result in non-root" - plain "ownership of the packaged files. Try using the fakeroot environment" - plain "by placing 'fakeroot' in the BUILDENV array in makepkg.conf." - plain "" - sleep 1 - fi -fi - -msg "Making package: $pkgname $pkgver-$pkgrel ($(date))" - -# fix flyspray bug #5973 -if [ "$NODEPS" = "1" -o "$GENINTEG" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then - if [ "$NODEPS" = "1" ]; then - warning "skipping dependency checks" - fi - # skip printing a warning message for the others: geninteg, nobuild, repkg -elif [ $(type -p pacman) ]; then - deperr=0 - # these two variables are needed later by removedeps - unset runtimedeps buildtimedeps - - msg "Checking Runtime Dependencies..." - resolvedeps ${depends[@]} - ret=$? - # deplist is a global variable set by resolvedeps - runtimedeps="$deplist" - if [ "$ret" != "0" ]; then - deperr=1 - fi - - msg "Checking Buildtime Dependencies..." - resolvedeps ${makedepends[@]} - ret=$? - # deplist is a global variable set by resolvedeps - buildtimedeps="$deplist" - if [ "$ret" != "0" ]; then - deperr=1 - fi - - if [ $deperr -eq 1 ]; then - error "could not resolve all dependencies." - exit 1 - fi -else - warning "pacman was not found in PATH. skipping dependency checks." -fi - -cd "$startdir" - -# retrieve sources -msg "Retrieving Sources..." -mkdir -p src -cd "$startdir/src" -for netfile in ${source[@]}; do - file=$(strip_url "$netfile") - if [ -f "../$file" ]; then - msg2 "Found $file in build dir" - cp "../$file" . - elif [ -f "$SRCDEST/$file" ]; then - msg2 "Using cached copy of $file" - cp "$SRCDEST/$file" . - else - # check for a download utility - if [ -z "$FTPAGENT" ]; then - error "FTPAGENT is not configured. Check the /etc/makepkg.conf file." - msg "Aborting..." - exit 1 - fi - ftpclient=$(echo $FTPAGENT | awk {'print $1'}) - if [ ! -x "$ftpclient" ]; then - error "ftpclient $(basename $ftpclient) is not installed." - msg "Aborting..." - exit 1 - fi - proto=$(echo "$netfile" | sed 's|://.*||') - if [ "$proto" != "ftp" -a "$proto" != "http" -a "$proto" != "https" ]; then - error "$netfile was not found in the build directory and is not a proper URL." - msg "Aborting..." - exit 1 - fi - msg2 "Downloading $file" - $FTPAGENT "$netfile" - # fix flyspray bug #3289 - ftpret=$? - if [ $ftpret -gt 0 ]; then - error "Failure while downloading $file" - msg "Aborting..." - #rm "$file" - exit 1 - fi - if [ -n "$SRCDEST" ]; then - mkdir -p $SRCDEST && cp "$file" $SRCDEST - if [ $? -ne 0 ]; then - warning "You do not have correct permissions to cache source in $SRCDEST" - cp "$file" .. - fi - else - cp "$file" .. - fi - fi -done - -if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then - warning "Skipping source integrity checks -- using existing src/ tree" -else - # TODO we end up checking $GENINTEG 3 times, could probably be refactored - if [ "$GENINTEG" = "1" ]; then - msg "Generating checksums for source files" - plain "" - fi - - for integ in ${INTEGRITY_CHECK[@]}; do - integ="$(echo $integ | tr A-Z a-z)" - case "$integ" in - md5) integrity_name="md5sum" ;; - sha1) integrity_name="sha1sum" ;; - sha256) integrity_name="sha256sum" ;; - sha384) integrity_name="sha384sum" ;; - sha512) integrity_name="sha512sum" ;; - *) error "Invalid integrity algorithm '$integ' specified"; exit 1;; - esac - if [ ! $(type -p $integrity_name) ]; then - error "Cannot find the $integrity_name program." - exit 1 - fi - - #Generate integrity checks - if [ "$GENINTEG" = "1" ]; then - ct=0 - numsrc=${#source[@]} - for netfile in "${source[@]}"; do - file=$(strip_url "$netfile") - sum=$(eval "$integrity_name '$file' | cut -d' ' -f 1") - if [ $ct -eq 0 ]; then - echo -n "${integrity_name}s=(" - else - indent=0 - while [ $indent -lt $((${#integrity_name}+3)) ]; do - echo -n " " - indent=$(($indent+1)) - done - fi - echo -n "'$sum'" - ct=$(($ct+1)) - if [ $ct -eq $numsrc ]; then - echo ')' - else - echo - fi - done - #Validate integrity checks - else - integrity_sums=($(eval echo \${${integrity_name}s[@]})) - - if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then - msg "Validating source files with ${integrity_name}s" - errors=0 - idx=0 - for netfile in "${source[@]}"; do - file=$(strip_url "$netfile") - echo -n " $file ... " >&2 - echo "${integrity_sums[$idx]} $file" | $integrity_name -c - >/dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "FAILED" >&2 - errors=1 - else - echo "Passed" >&2 - fi - idx=$(($idx+1)) - done - if [ $errors -gt 0 ]; then - error "One or more files did not pass the validity check!" - exit 1 - fi - else - warning "Integrity checks ($integ) are missing or incomplete." - fi - fi - done - - if [ "$GENINTEG" = "1" ]; then - plain "" - exit 0 - fi -fi - -#Extract sources -if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then - warning "Skipping source extraction -- using existing src/ tree" -else - msg "Extracting Sources..." - for netfile in "${source[@]}"; do - unziphack=0 - file=$(strip_url "$netfile") - if in_array "$file" ${noextract[@]}; then - #skip source files in the noextract=() array - # these are marked explicitly to NOT be extracted - continue - fi - # fix flyspray #6246 - file_type=$(file -biz "$file") - unset cmd - case "$file_type" in - *application/x-tar*application/x-compress*) - cmd="tar -xzf $file" ;; - *application/x-tar*) - cmd="tar -xf $file" ;; - *application/x-zip*) - unziphack=1 - cmd="unzip -qqo $file" ;; - *application/x-cpio*) - cmd="bsdtar -x -f $file" ;; - *application/x-gzip*) - cmd="gunzip -d -f $file" ;; - *application/x-bzip*) - cmd="bunzip2 -f $file" ;; - esac - if [ "$cmd" != "" ]; then - msg2 "$cmd" - $cmd - if [ $? -ne 0 ]; then - # unzip will return a 1 as a warning, it is not an error - if [ "$unziphack" != "1" -o $? -ne 1 ]; then - error "Failed to extract $file" - msg "Aborting..." - exit 1 - fi - fi - fi - done - - if [ "$EUID" = "0" ]; then - # chown all source files to root.root - chown -R root.root "$startdir/src" - fi -fi - -if [ "$NOBUILD" = "1" ]; then - msg "Sources are ready." - exit 0 -elif [ "$REPKG" = "1" ]; then - warning "Skipping build" -else - # check for existing pkg directory - if [ -d "$startdir/pkg" ]; then - msg "Removing existing pkg/ directory..." - rm -rf "$startdir/pkg" - fi - mkdir -p "$startdir/pkg" - - # use distcc if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then - [ -d /usr/lib/distcc/bin ] && export PATH=/usr/lib/distcc/bin:$PATH - export DISTCC_HOSTS - elif [ "$(check_option distcc)" = "n" ]; then - # if it is not wanted, clear the makeflags too - MAKEFLAGS="" - fi - - # use ccache if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then - [ -d /usr/lib/ccache/bin ] && export PATH=/usr/lib/ccache/bin:$PATH - fi - - # clear user-specified makeflags if requested - if [ "$(check_option makeflags)" = "n" ]; then - MAKEFLAGS="" - fi - - # build - msg "Starting build()..." - - # some applications (eg, blackbox) will not build with some languages - unset LC_ALL LC_MESSAGES LANG - umask 0022 - - # ensure all necessary build variables are exported - export CFLAGS CXXFLAGS MAKEFLAGS - - #check for "exit on syntax error" shell option - echo $SHELLOPTS | grep errexit 2>&1 >/dev/null - set_e=$? - - ret=0 - if [ "$LOGGING" = "1" ]; then - BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" - if [ -f "$BUILDLOG" ]; then - i=1 - while true; do - if [ -f "$BUILDLOG.$i" ]; then - i=$(($i +1)) - else - break - fi - done - mv "$BUILDLOG" "$BUILDLOG.$i" - fi - - #use 'errexit' to bail on syntax error - [ $set_e -eq 1 ] && set -e - build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} - [ $set_e -eq 1 ] && set +e - else - #use 'errexit' to bail on syntax error - [ $set_e -eq 1 ] && set -e - build 2>&1 || ret=$? - [ $set_e -eq 1 ] && set +e - fi - if [ $ret -gt 0 ]; then - error "Build Failed. Aborting..." - removedeps - exit 2 - fi -fi - -if [ "$(check_option docs)" = "n" ]; then - # remove info/doc files - msg "Removing info/doc files..." - cd "$startdir/pkg" - #fix flyspray bug #5021 - rm -rf ${DOC_DIRS[@]} -fi - -# move /usr/share/man files to /usr/man -if [ -d $startdir/pkg/usr/share/man ]; then - cd "$startdir" - mkdir -p pkg/usr/man - cp -a pkg/usr/share/man/* pkg/usr/man/ - rm -rf pkg/usr/share/man -fi - -# compress man pages -msg "Compressing man pages..." -find "$startdir"/pkg/{usr{,/local},opt/*}/man -type f 2>/dev/null | while read i ; do - ext="${i##*.}" - fn="${i##*/}" - if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then - # update symlinks to this manpage - find "$startdir"/pkg/{usr{,/local},opt/*}/man -lname "$fn" 2> /dev/null | while read ln ; do - rm -f "$ln" - ln -sf "${fn}.gz" "${ln}.gz" - done - # compress the original - gzip -9 "$i" - fi -done - -cd "$startdir" - -# strip binaries -if [ "$(check_option strip)" = "y" ]; then - msg "Stripping debugging symbols from libraries..." - find pkg/{,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \ - -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \ - | grep -v "No such file" | grep -v "format not recognized" - msg "Stripping symbols from binaries..." - find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \ - -exec /usr/bin/strip '{}' \; 2>&1 \ - | grep -v "No such file" | grep -v "format not recognized" -fi - -# remove libtool (.la) files -if [ "$(check_option libtool)" = "n" ]; then - msg "Removing libtool .la files..." - find pkg -type f -name "*.la" -exec rm -f -- '{}' \; -fi - -# remove empty directories -if [ "$(check_option emptydirs)" = "n" ]; then - msg "Removing empty directories..." - cd "$startdir/pkg" - find -depth -type d -empty -delete; -fi - -# get some package meta info -builddate=$(LC_ALL= ; LANG= ; date -u "+%a %b %e %H:%M:%S %Y") -if [ "$PACKAGER" != "" ]; then - packager="$PACKAGER" -else - packager="Arch Linux (http://www.archlinux.org)" -fi -size=$(du -cb "$startdir/pkg" | tail -n 1 | awk '{print $1}') - -# build a filelist - do this first to keep meta files out of the list -msg "Generating .FILELIST file..." -cd "$startdir/pkg" -tar cvf /dev/null * | sort >.FILELIST - -# write the .PKGINFO file -msg "Generating .PKGINFO file..." -cd "$startdir/pkg" -echo "# Generated by makepkg $myver" >.PKGINFO -echo -n "# " >>.PKGINFO -date >>.PKGINFO -echo "pkgname = $pkgname" >>.PKGINFO -echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO -echo "pkgdesc = $pkgdesc" >>.PKGINFO -echo "url = $url" >>.PKGINFO -echo "builddate = $builddate" >>.PKGINFO -echo "packager = $packager" >>.PKGINFO -echo "size = $size" >>.PKGINFO -if [ "$CARCH" != "" ]; then - echo "arch = $CARCH" >>.PKGINFO -fi - -for it in "${license[@]}"; do - echo "license = $it" >>.PKGINFO -done -for it in "${replaces[@]}"; do - echo "replaces = $it" >>.PKGINFO -done -for it in "${groups[@]}"; do - echo "group = $it" >>.PKGINFO -done -for it in "${depends[@]}"; do - echo "depend = $it" >>.PKGINFO -done -for it in "${conflicts[@]}"; do - echo "conflict = $it" >>.PKGINFO -done -for it in "${provides[@]}"; do - echo "provides = $it" >>.PKGINFO -done -for it in "${backup[@]}"; do - echo "backup = $it" >>.PKGINFO -done - -# TODO maybe remove this at some point -# warn if license array is not present or empty -if [ "$license" = "" ]; then - warning "Please add a license line to your $BUILDSCRIPT!" - plain "example for GPL'ed software: license=('GPL')." -fi - -# check for an install script -if [ "$install" != "" ]; then - msg "Copying install script..." - cp "$startdir/$install" "$startdir/pkg/.INSTALL" -fi - -# do we have a changelog? -have_changelog=0 -if [ -f "$startdir/ChangeLog" ]; then - msg "Copying package changelog" - cp "$startdir/ChangeLog" "$startdir/pkg/.CHANGELOG" - have_changelog=1 -fi - -# tar it up -msg "Compressing package..." -cd "$startdir/pkg" - -pkg_file="$PKGDEST/$pkgname-$pkgver-$pkgrel-${CARCH}.${PKGEXT}" -comp_files=".PKGINFO .FILELIST ${install:+.INSTALL}" -[ $have_changelog -eq 1 ] && comp_files=".CHANGELOG $comp_files" - -if ! tar czf $pkg_file $comp_files *; then - error "Failed to create package file." - exit 1 -fi - -cd "$startdir" -if [ "$CLEANUP" = "1" ]; then - msg "Cleaning up..." - rm -rf src pkg - rm -rf ${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log* -fi - -removedeps - -msg "Finished making: $pkgname ($(date))" - -installpackage - -exit 0 -# vim: set ts=2 sw=2 noet: - diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in new file mode 100644 index 00000000..953bda2a --- /dev/null +++ b/scripts/makepkg.sh.in @@ -0,0 +1,1470 @@ +#!/bin/bash -e +# +# makepkg - make packages compatable for use with pacman +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> +# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> +# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> +# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> +# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk> +# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +# makepkg uses quite a few external programs during its execution. You +# need to have at least the following installed for makepkg to function: +# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils), +# getopt (util-linux), gettext, grep, gzip, sed + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' +confdir='@sysconfdir@' +startdir="$PWD" +srcdir="$startdir/src" +pkgdir="$startdir/pkg" + +# Options +ASROOT=0 +CLEANUP=0 +CLEANCACHE=0 +DEP_BIN=0 +DEP_SRC=0 +FORCE=0 +INFAKEROOT=0 +GENINTEG=0 +INSTALL=0 +NOBUILD=0 +NODEPS=0 +NOEXTRACT=0 +RMDEPS=0 +REPKG=0 +LOGGING=0 +SOURCEONLY=0 +IGNOREARCH=0 + +# Forces the pkgver of the current PKGBUILD. Used by the fakeroot call +# when dealing with svn/cvs/etc PKGBUILDs. +FORCE_VER="" + +PACMAN_OPTS= + +### SUBROUTINES ### + +plain() { + local mesg=$1; shift + if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 + else + printf " ${mesg}\n" "$@" >&2 + fi +} + +msg() { + local mesg=$1; shift + if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 + else + printf "==> ${mesg}\n" "$@" >&2 + fi +} + +msg2() { + local mesg=$1; shift + if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 + else + printf " -> ${mesg}\n" "$@" >&2 + fi +} + +warning() { + local mesg=$1; shift + if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;33m==> $(gettext "WARNING:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 + else + printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 + fi +} + +error() { + local mesg=$1; shift + if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;31m==> $(gettext "ERROR:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2 + else + printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 + fi +} + + +## +# Special exit call for traps, Don't print any error messages when inside, +# the fakeroot call, the error message will be printed by the main call. +## +trap_exit() { + if [ "$INFAKEROOT" = "0" ]; then + echo + error "$@" + fi + exit 1 +} + + +## +# Clean up function. Called automatically when the script exits. +## +clean_up() { + local EXIT_CODE=$? + + if [ "$INFAKEROOT" = "1" ]; then + # Don't clean up when leaving fakeroot, we're not done yet. + return + fi + + if [ $EXIT_CODE -eq 0 -a "$CLEANUP" = "1" ]; then + # If it's a clean exit and -c/--clean has been passed... + msg "$(gettext "Cleaning up...")" + cd "$startdir" + rm -rf pkg src + if [ "$pkgname" != "" ]; then + # Can't do this unless the BUILDSCRIPT has been sourced. + rm -f "${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log*" + fi + fi + + remove_deps +} + + +## +# Signal Traps +## +trap 'clean_up' 0 +trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT +trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT +trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR + + +strip_url() { + echo "$1" | sed 's|^.*://.*/||g' +} + + +## +# Checks to see if options are present in makepkg.conf or PKGBUILD; +# PKGBUILD options always take precedence. +# +# usage : check_option( $option ) +# return : y - enabled +# n - disabled +# ? - not found +## +check_option() { + local ret=$(in_opt_array "$1" ${options[@]}) + if [ "$ret" != '?' ]; then + echo $ret + return + fi + + # BEGIN DEPRECATED + # TODO: This code should be removed in the next release of makepkg. + local needle=$(echo $1 | tr [:upper:] [:lower:]) + local opt + for opt in ${options[@]}; do + opt=$(echo $opt | tr [:upper:] [:lower:]) + if [ "$opt" = "no$needle" ]; then + warning "$(gettext "Options beginning with 'no' will be deprecated in the next version of makepkg!")" + plain "$(gettext "Please replace 'no' with '!': %s -> %s.")" "no$needle" "!$needle" + echo 'n' # Disabled + return + elif [ "$opt" = "keepdocs" -a "$needle" = "docs" ]; then + warning "$(gettext "Option 'keepdocs' may not work as intended. Please replace with 'docs'.")" + echo 'y' # Enabled + return + fi + done + # END DEPRECATED + + # fall back to makepkg.conf options + ret=$(in_opt_array "$1" ${OPTIONS[@]}) + if [ "$ret" != '?' ]; then + echo $ret + return + fi + + echo '?' # Not Found +} + + +## +# Check if option is present in BUILDENV +# +# usage : check_buildenv( $option ) +# return : y - enabled +# n - disabled +# ? - not found +## +check_buildenv() { + echo $(in_opt_array "$1" ${BUILDENV[@]}) +} + + +## +# usage : in_opt_array( $needle, $haystack ) +# return : y - enabled +# n - disabled +# ? - not found +## +in_opt_array() { + local needle=$(echo $1 | tr [:upper:] [:lower:]); shift + + local opt + for opt in "$@"; do + opt=$(echo $opt | tr [:upper:] [:lower:]) + if [ "$opt" = "$needle" ]; then + echo 'y' # Enabled + return + elif [ "$opt" = "!$needle" ]; then + echo 'n' # Disabled + return + fi + done + + echo '?' # Not Found +} + + +## +# usage : in_array( $needle, $haystack ) +# return : 0 - found +# 1 - not found +## +in_array() { + local needle=$1; shift + [ -z "$1" ] && return 1 # Not Found + local item + for item in "$@"; do + [ "$item" = "$needle" ] && return 0 # Found + done + return 1 # Not Found +} + +get_downloadclient() { + # $1 = url with valid protocol prefix + local url=$1 + local proto=$(echo $netfile | sed 's|://.*||') + + # loop through DOWNLOAD_AGENTS variable looking for protocol + local i + for i in "${DLAGENTS[@]}"; do + local handler=$(echo $i | sed 's|::.*||') + if [ "$proto" == "$handler" ]; then + agent=$(echo $i | sed 's|^.*::||') + break + fi + done + + # if we didn't find an agent, return an error + if [ -z "$agent" ]; then + error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$confdir/makepkg.conf" + plain "$(gettext "Aborting...")" + exit 1 # $E_CONFIG_ERROR + fi + + # ensure specified program is installed + local program="$(echo $agent | awk '{print $1 }')" + if [ ! -x "$program" ]; then + local baseprog=$(basename $program) + error "$(gettext "The download program %s is not installed.")" "$baseprog" + plain "$(gettext "Aborting...")" + exit 1 # $E_MISSING_PROGRAM + fi + + echo "$agent" +} + +check_deps() { + [ $# -gt 0 ] || return + + pmout=$(pacman $PACMAN_OPTS -T "$@") + ret=$? + if [ $ret -eq 127 ]; then #unresolved deps + echo "$pmout" + elif [ $ret -ne 0 ]; then + error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout" + exit 1 + fi +} + +handledeps() { + local R_DEPS_SATISFIED=0 + local R_DEPS_MISSING=1 + + [ $# -eq 0 ] && return $R_DEPS_SATISFIED + + local deplist="$*" + local dep depstrip striplist + for dep in $deplist; do + depstrip="$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')" + striplist="$striplist $depstrip" + done + + if [ "$DEP_SRC" = "0" -a "$DEP_BIN" = "0" ]; then + return $R_DEPS_MISSING + fi + + if [ "$DEP_BIN" = "1" ]; then + # install missing deps from binary packages (using pacman -S) + msg "$(gettext "Installing missing dependencies...")" + local ret=0 + + if [ "$ASROOT" = 0 ]; then + sudo pacman $PACMAN_OPTS -S --asdeps $striplist || ret=$? + else + pacman $PACMAN_OPTS -S --asdeps $striplist || ret=$? + fi + + if [ $ret -ne 0 ]; then + error "$(gettext "Pacman failed to install missing dependencies.")" + exit 1 # TODO: error code + fi + elif [ "$DEP_SRC" = "1" ]; then + msg "$(gettext "Building missing dependencies...")" + + # install missing deps by building them from source. + # we look for each package name in $SRCROOT and build it. + if [ "$SRCROOT" = "" ]; then + error "$(gettext "Source root cannot be found - please make sure it is specified in %s.")" "$confdir/makepkg.conf" + exit 1 # TODO: error code + fi + + # TODO: handle version comparators (eg, glibc>=2.2.5) + for dep in $striplist; do + local candidates="$(find "$SRCROOT" -type d -name "$dep")" + if [ "$candidates" = "" ]; then + error "$(gettext "Could not find '%s' under %s")" "$dep" "$SRCROOT" + exit 1 # TODO: error code + fi + + local makepkg_opts='-i -c -b' + [ "$RMDEPS" = "1" ] && makepkg_opts="$makepkg_opts -r" + local ret packagedir + for packagedir in $candidates; do + if [ -f "$packagedir/$BUILDSCRIPT" ]; then + cd "$packagedir" + ret=0 + PKGDEST="$PKGDEST" makepkg $makepkg_opts || ret=$? + [ $ret -eq 0 ] && continue 2 + fi + done + + error "$(gettext "Failed to build '%s'")" "$dep" + exit 1 # TODO: error code + done + fi + + # rerun any additional sh scripts found in /etc/profile.d/ + local script + for script in /etc/profile.d/*.sh; do + if [ -x $script ]; then + source $script &>/dev/null + fi + done + + return $R_DEPS_SATISFIED +} + +resolve_deps() { + # $pkgdeps is a GLOBAL variable, used by remove_deps() + local R_DEPS_SATISFIED=0 + local R_DEPS_MISSING=1 + + local deplist="$(check_deps $*)" + if [ "$deplist" = "" ]; then + return $R_DEPS_SATISFIED + else + pkgdeps="$pkgdeps $deplist" + fi + + if handledeps $deplist; then + # check deps again to make sure they were resolved + deplist="$(check_deps $*)" + [ "$deplist" = "" ] && return $R_DEPS_SATISFIED + elif [ "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" ]; then + error "$(gettext "Failed to install all missing dependencies.")" + fi + + msg "$(gettext "Missing Dependencies:")" + local dep + for dep in $deplist; do + msg2 "$dep" + done + + return $R_DEPS_MISSING +} + +# fix flyspray bug #5923 +remove_deps() { + # $pkgdeps is a GLOBAL variable, set by resolve_deps() + [ "$RMDEPS" = "0" ] && return + [ "$pkgdeps" = "" ] && return + + local dep depstrip deplist + for dep in $pkgdeps; do + depstrip=$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||') + deplist="$deplist $depstrip" + done + + msg "Removing installed dependencies..." + if [ "$ASROOT" = "0" ]; then + sudo pacman $PACMAN_OPTS -Rns $deplist + else + pacman $PACMAN_OPTS -Rns $deplist + fi +} + +download_sources() { + msg "$(gettext "Retrieving Sources...")" + + if [ ! -w "$SRCDEST" ] ; then + error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST" + plain "$(gettext "Aborting...")" + exit 1 + fi + + pushd "$SRCDEST" &>/dev/null + + local netfile + for netfile in ${source[@]}; do + local file=$(strip_url "$netfile") + if [ -f "$startdir/$file" ]; then + msg2 "$(gettext "Found %s in build dir")" "$file" + cp -s --remove-destination "$startdir/$file" "$srcdir/" + continue + elif [ -f "$SRCDEST/$file" ]; then + msg2 "$(gettext "Using cached copy of %s")" "$file" + cp -s --remove-destination "$SRCDEST/$file" "$srcdir/" + continue + fi + + # find the client we should use for this URL + local dlclient=$(get_downloadclient $netfile) || exit $? + + msg2 "$(gettext "Downloading %s...")" "$file" + # fix flyspray bug #3289 + local ret=0 + $dlclient "$netfile" || ret=$? + if [ $ret -gt 0 ]; then + error "$(gettext "Failure while downloading %s")" "$file" + plain "$(gettext "Aborting...")" + exit 1 + fi + cp -s --remove-destination "$SRCDEST/$file" "$srcdir/" + done + + popd &>/dev/null +} + +generate_checksums() { + msg "$(gettext "Generating checksums for source files...")" + plain "" + + local integ + for integ in ${INTEGRITY_CHECK[@]}; do + integ="$(echo $integ | tr [:upper:] [:lower:])" + case "$integ" in + md5|sha1|sha256|sha384|sha512) : ;; + *) + error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ" + exit 1;; # $E_CONFIG_ERROR + esac + + if [ ! $(type -p "${integ}sum") ]; then + error "$(gettext "Cannot find the '%s' program.")" "${integ}sum" + exit 1 # $E_MISSING_PROGRAM + fi + + local ct=0 + local numsrc=${#source[@]} + echo -n "${integ}sums=(" + + local i=0; + local indent='' + while [ $i -lt $((${#integ}+6)) ]; do + indent="$indent " + i=$(($i+1)) + done + + local netfile + for netfile in ${source[@]}; do + local file="$(strip_url "$netfile")" + + if [ ! -f "$file" ] ; then + if [ ! -f "$SRCDEST/$file" ] ; then + error "$(gettext "Unable to find source file %s to generate checksum.")" "$file" + plain "$(gettext "Aborting...")" + exit 1 + else + file=$SRCDEST/$file + fi + fi + + local sum="$(${integ}sum "$file" | cut -d ' ' -f 1)" + [ $ct -gt 0 ] && echo -n "$indent" + echo -n "'$sum'" + ct=$(($ct+1)) + [ $ct -lt $numsrc ] && echo + done + + echo ")" + done +} + +check_checksums() { + local integ + for integ in ${INTEGRITY_CHECK[@]}; do + integ="$(echo $integ | tr [:upper:] [:lower:])" + case "$integ" in + md5|sha1|sha256|sha384|sha512) : ;; + *) + error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ" + exit 1;; # $E_CONFIG_ERROR + esac + + if [ ! $(type -p "${integ}sum") ]; then + error "$(gettext "Cannot find the '%s' program.")" "${integ}sum" + exit 1 # $E_MISSING_PROGRAM + fi + + local integrity_sums=($(eval echo \${${integ}sums[@]})) + if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then + msg "$(gettext "Validating source files with %s...")" "${integ}sums" + local errors=0 + local idx=0 + local file + for file in "${source[@]}"; do + file="$(strip_url "$file")" + echo -n " $file ... " >&2 + + if [ ! -f "$file" ] ; then + if [ ! -f "$file" ] ; then + echo "$(gettext "NOT FOUND")" >&2 + errors=1 + continue + else + file=$SRCDEST/$file + fi + fi + + if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c - &>/dev/null; then + echo "$(gettext "Passed")" >&2 + else + echo "$(gettext "FAILED")" >&2 + errors=1 + fi + + idx=$((idx + 1)) + done + + if [ $errors -gt 0 ]; then + error "$(gettext "One or more files did not pass the validity check!")" + exit 1 # TODO: error code + fi + else + warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ" + fi + done +} + +extract_sources() { + msg "$(gettext "Extracting Sources...")" + local netfile + for netfile in "${source[@]}"; do + file=$(strip_url "$netfile") + if in_array "$file" ${noextract[@]}; then + #skip source files in the noextract=() array + # these are marked explicitly to NOT be extracted + continue + fi + + if [ ! -f "$file" ] ; then + if [ ! -f "$SRCDEST/$file" ] ; then + error "$(gettext "Unable to find source file %s for extraction.")" "$file" + plain "$(gettext "Aborting...")" + exit 1 + else + file=$SRCDEST/$file + fi + fi + + # fix flyspray #6246 + local file_type=$(file -bizL "$file") + local cmd='' + case "$file_type" in + *application/x-tar*|*application/x-zip*|*application/x-cpio*) + cmd="bsdtar -x -f $file" ;; + *application/x-gzip*) + cmd="gunzip -d -f $file" ;; + *application/x-bzip*) + cmd="bunzip2 -f $file" ;; + *) + # Don't know what to use to extract this file, + # skip to the next file + continue;; + esac + + local ret=0 + msg2 "$cmd" + $cmd || ret=$? + if [ $ret -ne 0 ]; then + error "$(gettext "Failed to extract %s")" "$file" + plain "$(gettext "Aborting...")" + exit 1 + fi + done + + if [ $EUID -eq 0 ]; then + # chown all source files to root.root + chown -R root.root "$srcdir" + fi +} + +run_build() { + # use distcc if it is requested (check buildenv and PKGBUILD opts) + if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then + [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH" + export DISTCC_HOSTS + elif [ "$(check_option distcc)" = "n" ]; then + # if it is not wanted, clear the makeflags too + MAKEFLAGS="" + fi + + # use ccache if it is requested (check buildenv and PKGBUILD opts) + if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then + [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH" + fi + + # clear user-specified makeflags if requested + if [ "$(check_option makeflags)" = "n" ]; then + MAKEFLAGS="" + fi + + msg "$(gettext "Starting build()...")" + cd "$srcdir" + + # ensure we have a sane umask set + umask 0022 + + # ensure all necessary build variables are exported + export CFLAGS CXXFLAGS MAKEFLAGS CHOST + + local ret=0 + if [ "$LOGGING" = "1" ]; then + BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" + if [ -f "$BUILDLOG" ]; then + local i=1 + while true; do + if [ -f "$BUILDLOG.$i" ]; then + i=$(($i +1)) + else + break + fi + done + mv "$BUILDLOG" "$BUILDLOG.$i" + fi + + build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} + else + build 2>&1 || ret=$? + fi + + if [ $ret -gt 0 ]; then + error "$(gettext "Build Failed.")" + plain "$(gettext "Aborting...")" + remove_deps + exit 2 # $E_BUILD_FAILED + fi +} + +tidy_install() { + cd "$pkgdir" + msg "$(gettext "Tidying install...")" + + if [ "$(check_option docs)" = "n" ]; then + msg2 "$(gettext "Removing info/doc files...")" + #fix flyspray bug #5021 + rm -rf ${DOC_DIRS[@]} + fi + + if [ -d usr/share/man ]; then + msg2 "$(gettext "Moving usr/share/man files to usr/man...")" + mkdir -p usr/man + cp -a usr/share/man/* usr/man/ + rm -rf usr/share/man + fi + + + msg2 "$(gettext "Compressing man pages...")" + local manpage ext file link + find {usr{,/local},opt/*}/man -type f 2>/dev/null | while read manpage ; do + ext="${manpage##*.}" + file="${manpage##*/}" + if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then + # update symlinks to this manpage + find {usr{,/local},opt/*}/man -lname "$file" 2>/dev/null | while read link ; do + rm -f "$link" + ln -sf "${file}.gz" "${link}.gz" + done + # compress the original + gzip -9 "$manpage" + fi + done + + + if [ "$(check_option strip)" = "y" ]; then + msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" + for file in $(find {,usr/{,local/},opt/}{bin,lib,sbin} -type f 2>/dev/null || true); do + case "$(file -biz "$file")" in + *application/x-sharedlib*) # Libraries + /usr/bin/strip --strip-debug "$file";; + *application/x-executable*) # Binaries + /usr/bin/strip "$file";; + esac + done + fi + + if [ "$(check_option libtool)" = "n" ]; then + msg2 "$(gettext "Removing libtool .la files...")" + find . -type f -name "*.la" -exec rm -f -- '{}' \; + fi + + if [ "$(check_option emptydirs)" = "n" ]; then + msg2 "$(gettext "Removing empty directories...")" + find . -depth -type d -empty -delete + fi +} + +create_package() { + if [ ! -d "$pkgdir" ]; then + error "$(gettext "Missing pkg/ directory.")" + plain "$(gettext "Aborting...")" + exit 1 # $E_MISSING_PKGDIR + fi + + cd "$pkgdir" + msg "$(gettext "Creating package...")" + + local builddate=$(date -u "+%s") + if [ "$PACKAGER" != "" ]; then + local packager="$PACKAGER" + else + local packager="Arch Linux (http://www.archlinux.org)" + fi + local size=$(du -sb | awk '{print $1}') + + msg2 "$(gettext "Generating .FILELIST file...")" + # The following command does the following: + # - find all directories and add a trailing / + # - find all other files/links + # - grep out dot files in root dir (e.g. .FILELIST .PKGINFO...) + # - sort the list + find . -mindepth 1 \( -type d -printf '%P/\n' \) , \( ! -type d -printf '%P\n' \) \ + 2>/dev/null | grep -v '^\.' | sort >.FILELIST + + # write the .PKGINFO file + msg2 "$(gettext "Generating .PKGINFO file...")" + echo "# Generated by makepkg $myver" >.PKGINFO + if [ "$INFAKEROOT" = "1" ]; then + echo "# using $(fakeroot -v)" >>.PKGINFO + fi + echo "# $(LC_ALL= LANG= date -u)" >>.PKGINFO + echo "pkgname = $pkgname" >>.PKGINFO + echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO + echo "pkgdesc = $pkgdesc" >>.PKGINFO + echo "url = $url" >>.PKGINFO + echo "builddate = $builddate" >>.PKGINFO + echo "packager = $packager" >>.PKGINFO + echo "size = $size" >>.PKGINFO + if [ "$CARCH" != "" ]; then + echo "arch = $CARCH" >>.PKGINFO + fi + + local it + for it in "${license[@]}"; do + echo "license = $it" >>.PKGINFO + done + for it in "${replaces[@]}"; do + echo "replaces = $it" >>.PKGINFO + done + for it in "${groups[@]}"; do + echo "group = $it" >>.PKGINFO + done + for it in "${depends[@]}"; do + echo "depend = $it" >>.PKGINFO + done + for it in "${optdepends[@]}"; do + echo "optdepend = $it" >>.PKGINFO + done + for it in "${conflicts[@]}"; do + echo "conflict = $it" >>.PKGINFO + done + for it in "${provides[@]}"; do + echo "provides = $it" >>.PKGINFO + done + for it in "${backup[@]}"; do + echo "backup = $it" >>.PKGINFO + done + + # TODO maybe remove this at some point + # warn if license array is not present or empty + if [ "$license" = "" ]; then + warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" + plain "$(gettext "Example for GPL'ed software: license=('GPL').")" + fi + + local comp_files=".PKGINFO .FILELIST" + + # check for an install script + # TODO: should we include ${pkgname}.install if it exists and $install is unset? + if [ "$install" != "" ]; then + msg2 "$(gettext "Adding install script...")" + cp "$startdir/$install" .INSTALL + comp_files="$comp_files .INSTALL" + fi + + # do we have a changelog? + if [ -f "$startdir/ChangeLog" ]; then + msg2 "$(gettext "Adding package changelog...")" + cp "$startdir/ChangeLog" .CHANGELOG + comp_files="$comp_files .CHANGELOG" + fi + + # tar it up + msg2 "$(gettext "Compressing package...")" + + local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + + if ! bsdtar -czf "$pkg_file" $comp_files $(ls); then + error "$(gettext "Failed to create package file.")" + exit 1 # TODO: error code + fi +} + +create_xdelta() { + if [ "$(check_buildenv xdelta)" != "y" ]; then + return + elif [ ! "$(type -p xdelta)" ]; then + error "$(gettext "Cannot find the xdelta binary! Is xdelta installed?")" + return + fi + + local pkg_file=$1 + local cache_dir="/var/cache/pacman/pkg" # TODO: autoconf me + local pkginfo="$(mktemp "$startdir"/xdelta-pkginfo.XXXXXXXXX)" + + local old_file old_version + for old_file in $(ls {"$cache_dir","$PKGDEST"}/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do + bsdtar -xOf "$old_file" .PKGINFO > "$pkginfo" || continue + if [ "$(cat "$pkginfo" | grep '^pkgname = ')" != "pkgname = $pkgname" ]; then + continue # Package name does not match. + elif [ "$(cat "$pkginfo" | grep '^arch = ')" != "arch = $CARCH" ] ; then + continue # Not same arch. + fi + + old_version="$(cat "$pkginfo" | grep '^pkgver = ' | sed 's/^pkgver = //')" + + # old_version may include the target package, only use the old versions + local vercmp=$(vercmp "$old_version" "$latest_version") + if [ "$old_version" != "$pkgver-$pkgrel" -a $vercmp -gt 0 ]; then + local latest_version=$old_version + local base_file=$old_file + fi + done + + rm -f "$pkginfo" + + if [ "$base_file" != "" ]; then + msg "$(gettext "Making delta from version %s...")" "$latest_version" + local delta_file="$PKGDEST/$pkgname-${latest_version}_to_$pkgver-$pkgrel-$CARCH.delta" + local ret=0 + + # xdelta will decompress base_file & pkg_file into TMP_DIR (or /tmp if + # TMP_DIR is unset) then perform the delta on the resulting tars + xdelta delta "$base_file" "$pkg_file" "$delta_file" || ret=$? + + if [ $ret -eq 0 -o $ret -eq 1 ]; then + # Generate the final gz using xdelta for compression. xdelta will be our + # common denominator compression utility between the packager and the + # users. makepkg and pacman must use the same compression algorithm or + # the delta generated package may not match, producing md5 checksum + # errors. + msg2 "$(gettext "Recreating package tarball from delta to match md5 signatures")" + msg2 "$(gettext "NOTE: the delta should ONLY be distributed with this tarball")" + ret=0 + xdelta patch "$delta_file" "$base_file" "$pkg_file" || ret=$? + if [ $ret -ne 0 ]; then + error "$(gettext "Could not generate the package from the delta.")" + exit 1 + fi + else + warning "$(gettext "Delta was not able to be created.")" + fi + else + warning "$(gettext "No previous version found, skipping xdelta.")" + fi +} + +create_srcpackage() { + cd "$startdir" + msg "$(gettext "Creating source package...")" + local comp_files="PKGBUILD" + msg2 "$(gettext "Adding %s...")" "PKGBUILD" + + if [ "$install" != "" ]; then + if [ -f $install ]; then + msg2 "$(gettext "Adding install script...")" + comp_files="$comp_files $install" + else + error "$(gettext "Install script %s not found.")" "$install" + fi + fi + + if [ -f ChangeLog ]; then + msg2 "$(gettext "Adding %s...")" "ChangeLog" + comp_files="$comp_files ChangeLog" + fi + + local i + for i in ${source[@]}; do + if [ -f $i ]; then + msg2 "$(gettext "Adding %s...")" "$i" + comp_files="$comp_files $i" + fi + done + + local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" + + # tar it up + msg2 "$(gettext "Compressing source package...")" + if ! bsdtar -czf "$pkg_file" $comp_files; then + error "$(gettext "Failed to create source package file.")" + exit 1 # TODO: error code + fi +} + +install_package() { + [ "$INSTALL" = "0" ] && return + + msg "$(gettext "Installing package with pacman -U...")" + if [ "$ASROOT" = "0" ]; then + sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $? + else + pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $? + fi +} + +devel_check() { + newpkgver="" + if [ "$FORCE_VER" = "" ]; then + # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so. + # This will only be used on the first call to makepkg; subsequent + # calls to makepkg via fakeroot will explicitly pass the version + # number to avoid having to determine the version number twice. + oldpkgver=$pkgver + if [ ! -z ${_darcstrunk} ] && [ ! -z ${_darcsmod} ] ; then + msg "$(gettext "Determining latest darcs revision...")" + newpkgver=$(date +%Y%m%d) + elif [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then + msg "$(gettext "Determining latest cvs revision...")" + newpkgver=$(date +%Y%m%d) + elif [ ! -z ${_gitroot} ] && [ ! -z ${_gitname} ] ; then + msg "$(gettext "Determining latest git revision...")" + newpkgver=$(date +%Y%m%d) + elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then + msg "$(gettext "Determining latest svn revision...")" + newpkgver=$(svn log $_svntrunk --limit 1 | sed -n 's/^r\([^ ]*\) .*$/\1/p') + elif [ ! -z ${_bzrtrunk} ] && [ ! -z ${_bzrmod} ] ; then + msg "$(gettext "Determining latest bzr revision...")" + newpkgver=$(bzr revno ${_bzrtrunk}) + elif [ ! -z ${_hgroot} ] && [ ! -z ${_hgrepo} ] ; then + msg "$(gettext "Determining latest hg revision...")" + if [ -d ./src/$_hgrepo ] ; then + cd ./src/$_hgrepo + hg pull + hg update + else + [[ ! -d ./src/ ]] && mkdir ./src/ + hg clone $_hgroot/$_hgrepo ./src/$_hgrepo + cd ./src/$_hgrepo + fi + newpkgver=$(hg tip | sed -n '1s/[^0-9]*\([^:]*\):.*$/\1/p') + cd ../../ + fi + + if [ "$newpkgver" != "" ]; then + msg2 "$(gettext "Version found: %s")" "$newpkgver" + pkgver=$newpkgver + fi + + else + # Version number retrieved from fakeroot->makepkg argument + newpkgver=$FORCE_VER + fi +} + +devel_update() { + # This is lame, but if we're wanting to use an updated pkgver for + # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with + # the new pkgver and then re-source it. This is the most robust + # method for dealing with PKGBUILDs that use, e.g.: + # + # pkgver=23 + # ... + # _foo=pkgver + # + if [ "$newpkgver" != "" ]; then + if [ "newpkgver" != "$pkgver" ]; then + sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" ./$BUILDSCRIPT + source $BUILDSCRIPT + fi + fi +} + +usage() { + printf "makepkg (pacman) %s\n" "$myver" + echo + printf "$(gettext "Usage: %s [options]")\n" "$0" + echo + echo "$(gettext "Options:")" + printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" + echo "$(gettext " -b, --builddeps Build missing dependencies from source")" + echo "$(gettext " -c, --clean Clean up work files after build")" + echo "$(gettext " -C, --cleancache Clean up source files from the cache")" + echo "$(gettext " -d, --nodeps Skip all dependency checks")" + echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" + echo "$(gettext " -f, --force Overwrite existing package")" + echo "$(gettext " -g, --geninteg Generate integrity checks for source files")" + echo "$(gettext " -h, --help This help")" + echo "$(gettext " -i, --install Install package after successful build")" + echo "$(gettext " -L, --log Log package build process")" + echo "$(gettext " -m, --nocolor Disable colorized output messages")" + echo "$(gettext " -o, --nobuild Download and extract files only")" + printf "$(gettext " -p <buildscript> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" + echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" + # fix flyspray feature request #2978 + echo "$(gettext " -R, --repackage Repackage contents of pkg/ without building")" + echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" + echo "$(gettext " --asroot Allow makepkg to run as root user")" + echo "$(gettext " --source Do not build package; generate a source-only tarball")" + echo + echo "$(gettext "These options can be passed to pacman:")" + echo + echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" + echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" + echo + printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT" + echo +} + +version() { + printf "makepkg (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +ARGLIST=$@ + +#preserve environment variables +_PKGDEST=${PKGDEST} +_SRCDEST=${SRCDEST} + +# Source makepkg.conf; fail if it is not found +if [ -r "$confdir/makepkg.conf" ]; then + source "$confdir/makepkg.conf" +else + error "$(gettext "%s not found.")" "$confdir/makepkg.conf" + plain "$(gettext "Aborting...")" + exit 1 # $E_CONFIG_ERROR +fi + +# Source user-specific makepkg.conf overrides +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# override settings with an environment variable for batch processing +PKGDEST=${_PKGDEST:-$PKGDEST} +PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined +SRCDEST=${_SRCDEST:-$SRCDEST} +SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined + +# Only use ABSROOT if we haven't been passed a SRCROOT on the command line. +if [ -z "$SRCROOT" ]; then + if [ -r "$confdir/abs/abs.conf" ]; then + source "$confdir/abs/abs.conf" + fi + if [ -r ~/.abs.conf ]; then + source ~/.abs.conf + fi + SRCROOT=$ABSROOT +fi + +# Parse Command Line Options. +OPT_SHORT="AbcCdefFghiLmop:rRsSV" +OPT_LONG="ignorearch,asroot,builddeps,clean,cleancache,nodeps,noextract,force,geninteg,help,install,log" +OPT_LONG="$OPT_LONG,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version,forcever:" +# Pacman Options +OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" +OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')" +if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then + # This is a small hack to stop the script bailing with 'set -e' + echo; usage; exit 1 # E_INVALID_OPTION; +fi +eval set -- "$OPT_TEMP" +unset OPT_SHORT OPT_LONG OPT_TEMP + +while true; do + case "$1" in + # Pacman Options + --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;; + --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;; + + # Makepkg Options + --asroot) ASROOT=1 ;; + -A|--ignorearch) IGNOREARCH=1 ;; + -b|--builddeps) DEP_SRC=1 ;; + -c|--clean) CLEANUP=1 ;; + -C|--cleancache) CLEANCACHE=1 ;; + -d|--nodeps) NODEPS=1 ;; + -e|--noextract) NOEXTRACT=1 ;; + -f|--force) FORCE=1 ;; + -F) INFAKEROOT=1 ;; + -g|--geninteg) GENINTEG=1 ;; + -i|--install) INSTALL=1 ;; + -L|--log) LOGGING=1 ;; + -m|--nocolor) USE_COLOR='n' ;; + -o|--nobuild) NOBUILD=1 ;; + -p) shift; BUILDSCRIPT=$1 ;; + -r|--rmdeps) RMDEPS=1 ;; + -R|--repackage) REPKG=1 ;; + --source) SOURCEONLY=1 ;; + -s|--syncdeps) DEP_BIN=1 ;; + + # Hidden option used by fakeroot call for svn/cvs/etc PKGBUILDs to set the pkgver + --forcever) shift; FORCE_VER=$1;; + + # BEGIN DEPRECATED + -S|--usesudo) + warning "$(gettext "Sudo is used by default now. The --usesudo option is deprecated!")" ;; + # END DEPRECATED + + -h|--help) usage; exit 0 ;; # E_OK + -V|--version) version; exit 0 ;; # E_OK + + --) OPT_IND=0; shift; break;; + *) usage; exit 1 ;; # E_INVALID_OPTION + esac + shift +done + +if [ "$CLEANCACHE" = "1" ]; then + #fix flyspray feature request #5223 + if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then + msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST" + echo -n "$(gettext " Are you sure you wish to do this? [Y/n] ")" + read answer + answer=$(echo $answer | tr [:upper:] [:lower:]) + if [ "$answer" = "yes" -o "$answer" = "y" ]; then + rm "$SRCDEST"/* + if [ $? -ne 0 ]; then + error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST" + exit 1 + else + # removal worked + msg "$(gettext "Source cache cleaned.")" + exit 0 + fi + else + # answer = no + msg "$(gettext "No files have been removed.")" + exit 0 + fi + else + # $SRCDEST is $startdir, two possibilities + error "$(gettext "Source destination must be defined in makepkg.conf.")" + plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")" + exit 1 + fi +fi + +if [ -z $BUILDSCRIPT ]; then + error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$confdir/makepkg.conf" + exit 1 +fi + +if [ "$INFAKEROOT" = "0" ]; then + if [ $EUID -eq 0 -a "$ASROOT" = "0" ]; then + # Warn those who like to live dangerously. + error "$(gettext "Running makepkg as root is a BAD idea and can cause")" + plain "$(gettext "permanent, catastrophic damage to your system. If you")" + plain "$(gettext "wish to run as root, please use the --asroot option.")" + exit 1 # $E_USER_ABORT + elif [ $EUID -gt 0 -a "$ASROOT" = "1" ]; then + # Warn those who try to use the --asroot option when they are not root + error "$(gettext "The --asroot option is meant for the root user only.")" + plain "$(gettext "Please rerun makepkg without the --asroot flag.")" + exit 1 # $E_USER_ABORT + elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then + if [ ! $(type -p fakeroot) ]; then + error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")" + plain "$(gettext "in the BUILDENV array in %s.")" "$confdir/makepkg.conf" + exit 1 + fi + elif [ $EUID -gt 0 ]; then + warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")" + plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")" + plain "$(gettext "placing 'fakeroot' in the BUILDENV array in makepkg.conf.")" + sleep 1 + fi +else + if [ "$FAKEROOTKEY" = "" ]; then + error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" + exit 1 # TODO: error code + fi +fi + +# check for sudo if we will need it during makepkg execution +if [ "$ASROOT" = "0" -a \( "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" \ + -o "$RMDEPS" = "1" -o "$INSTALL" = "1" \) ]; then + if [ ! "$(type -p sudo)" ]; then + error "$(gettext "Cannot find the sudo binary! Is sudo installed?")" + plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")" + plain "$(gettext "without sudo; install and configure sudo to auto-resolve dependencies.")" + exit 1 + fi +fi + +unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums force +unset replaces depends conflicts backup source install build makedepends +unset optdepends options noextract + +if [ ! -f "$BUILDSCRIPT" ]; then + error "$(gettext "%s does not exist.")" "$BUILDSCRIPT" + exit 1 + #TODO this is an attempt at a generic way to unset all package specific + #variables in a PKGBUILD + #else + # #this is fun.... we'll unset + # for var in $(grep "=" $BUILDSCRIPT | sed "s|.*\(\<.*\>\)=.*|\1|g"); do + # unset $var + # done +fi + +source "$BUILDSCRIPT" + +# check for no-no's in the build script +if [ -z "$pkgver" ]; then + error "$(gettext "%s is not allowed to be empty.")" "pkgver" + exit 1 +fi +if [ -z "$pkgrel" ]; then + error "$(gettext "%s is not allowed to be empty.")" "pkgrel" + exit 1 +fi +if [ $(echo "$pkgver" | grep '-') ]; then + error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver" + exit 1 +fi +if [ $(echo "$pkgrel" | grep '-') ]; then + error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel" + exit 1 +fi + +if [ "$arch" = 'any' ]; then + CARCH='any' +fi + +if ! in_array $CARCH ${arch[@]}; then + if [ "$IGNOREARCH" = "0" ]; then + error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH" + plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" + plain "$(gettext "such as arch=('%s').")" "$CARCH" + exit 1 + else + warning "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH" + plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" + plain "$(gettext "such as arch=('%s').")" "$CARCH" + fi +fi + +if [ "$install" -a ! -f "$install" ]; then + error "$(gettext "Install scriptlet (%s) does not exist.")" "$install" + exit 1 +fi + +devel_check + +if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ + -a "$FORCE" = "0" -a "$GENINTEG" = "0" -a "$SOURCEONLY" = "0" \ + -a "$FORCE_VER" = "" ]; then + if [ "$INSTALL" = "1" ]; then + warning "$(gettext "A package has already been built, installing existing package...")" + install_package + exit $? + else + error "$(gettext "A package has already been built. (use -f to overwrite)")" + exit 1 + fi +fi + +# Run the bare minimum in fakeroot +# fix flyspray bug 6208 -- using makepkg with fakeroot gives an error +if [ "$INFAKEROOT" = "1" ]; then + if [ "$REPKG" = "1" ]; then + warning "$(gettext "Skipping build.")" + else + devel_update + run_build + tidy_install + fi + + create_package + + msg "$(gettext "Leaving fakeroot environment.")" + exit 0 # $E_OK +fi + +msg "$(gettext "Making package: %s")" "$pkgname $pkgver-$pkgrel ($(date))" + +if [ $EUID -eq 0 ]; then + warning "$(gettext "Running makepkg as root...")" +fi + +# if we are creating a source-only package, go no further +if [ "$SOURCEONLY" = "1" ]; then + if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" \ + -a "$FORCE" = "0" ]; then + error "$(gettext "A package has already been built. (use -f to overwrite)")" + exit 1 + fi + create_srcpackage + msg "$(gettext "Source package created: %s")" "$pkgname ($(date))" + exit 0 +fi + +# fix flyspray bug #5973 +if [ "$NODEPS" = "1" -o "$GENINTEG" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then + if [ "$NODEPS" = "1" ]; then + warning "$(gettext "Skipping dependency checks.")" + fi + # skip printing a warning message for the others: geninteg, nobuild, repkg +elif [ $(type -p pacman) ]; then + unset pkgdeps # Set by resolve_deps() and used by remove_deps() + deperr=0 + + msg "$(gettext "Checking Runtime Dependencies...")" + resolve_deps ${depends[@]} || deperr=1 + + msg "$(gettext "Checking Buildtime Dependencies...")" + resolve_deps ${makedepends[@]} || deperr=1 + + if [ $deperr -eq 1 ]; then + error "$(gettext "Could not resolve all dependencies.")" + exit 1 + fi +else + warning "$(gettext "pacman was not found in PATH; skipping dependency checks.")" +fi + +# get back to our src directory so we can begin with sources +mkdir -p "$srcdir" +cd "$srcdir" + +if [ "$GENINTEG" = "1" ]; then + download_sources + generate_checksums + exit 0 # $E_OK +fi + +if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then + warning "$(gettext "Skipping source retrieval -- using existing src/ tree")" + warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")" + warning "$(gettext "Skipping source extraction -- using existing src/ tree")" + + if [ "$NOEXTRACT" = "1" -a "$(ls "$srcdir" 2>/dev/null)" = "" ]; then + error "$(gettext "The source directory is empty, there is nothing to build!")" + plain "$(gettext "Aborting...")" + exit 1 + elif [ "$REPKG" = "1" -a \( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \) ]; then + error "$(gettext "The package directory is empty, there is nothing to repackage!")" + plain "$(gettext "Aborting...")" + exit 1 + fi +else + download_sources + check_checksums + extract_sources +fi + +if [ "$NOBUILD" = "1" ]; then + msg "$(gettext "Sources are ready.")" + exit 0 #E_OK +else + # check for existing pkg directory; don't remove if we are repackaging + if [ -d "$pkgdir" -a "$REPKG" = "0" ]; then + msg "$(gettext "Removing existing pkg/ directory...")" + rm -rf "$pkgdir" + fi + mkdir -p "$pkgdir" + + if [ $EUID -eq 0 ]; then + # if we are root, then we don't need to recall makepkg with fakeroot + if [ "$REPKG" = "1" ]; then + warning "$(gettext "Skipping build.")" + else + devel_update + run_build + tidy_install + fi + + create_package + else + msg "$(gettext "Entering fakeroot environment...")" + cd "$startdir" + + if [ "$newpkgver" != "" ]; then + fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $? + else + fakeroot -- $0 -F $ARGLIST || exit $? + fi + fi + + create_xdelta "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" +fi + +msg "$(gettext "Finished making: %s")" "$pkgname ($(date))" + +install_package + +exit 0 #E_OK + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/makeworld b/scripts/makeworld deleted file mode 100755 index b9d318c6..00000000 --- a/scripts/makeworld +++ /dev/null @@ -1,172 +0,0 @@ -#!/bin/bash -# -# makeworld -# -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. -# - -version="3.0.0" -toplevel=$(pwd) - -usage() { - echo "makeworld version $version" - echo "usage: $0 [options] <destdir> <category> [category] ..." - echo "options:" - echo " -b, --builddeps Build missing dependencies from source" - echo " -B, --noccache Do not use ccache during build" - echo " -c, --clean Clean up work files after build" - echo " -C, --cleancache Clean up source files from the cache" - echo " -d, --nodeps Skip all dependency checks" - echo " -e, --noextract Do not extract source files (use existing src/ dir)" - echo " -f, --force Overwrite existing packages" - echo " -i, --install Install package after successful build" - echo " -m, --nocolor Disable colorized output messages" - echo " -h, --help This help" - echo " -o, --nobuild Download and extract files only" - echo " -r, --rmdeps Remove installed dependencies after a successful build" - echo " -s, --syncdeps Install missing dependencies with pacman" - echo " -S, --usesudo Use sudo when running pacman commands" - echo - echo "These options can be passed to pacman:" - echo - echo " --noconfirm Do not ask for confirmation when resolving dependencies" - echo " --noprogressbar Do not show a progress bar when downloading files" - echo - echo "Where <category> is one or more directory names under the ABS root" - echo "eg: makeworld -c /packages base lib editors" - echo - echo "This should be run from the toplevel directory of ABS (usually /var/abs)" -} - -if [ $# -lt 2 ]; then - usage - exit 1 -fi - -MAKEPKG_OPTS= -for arg in $*; do - case $arg in - # pacman - --noconfirm) MAKEPKG_OPTS="$MAKEPKG_OPTS --noconfirm" ;; - --noprogressbar) MAKEPKG_OPTS="$MAKEPKG_OPTS --noprogressbar" ;; - # makepkg - --clean) MAKEPKG_OPTS="$MAKEPKG_OPTS -c" ;; - --install) MAKEPKG_OPTS="$MAKEPKG_OPTS -i" ;; - --syncdeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -s" ;; - --usesudo) MAKEPKG_OPTS="$MAKEPKG_OPTS -S" ;; - --builddeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -b" ;; - --nodeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -d" ;; - --force) MAKEPKG_OPTS="$MAKEPKG_OPTS -f" ;; - --rmdeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -r" ;; - --noccache) MAKEPKG_OPTS="$MAKEPKG_OPTS -B" ;; - --cleancache) MAKEPKG_OPTS="$MAKEPKG_OPTS -C" ;; - --noextract) MAKEPKG_OPTS="$MAKEPKG_OPTS -e" ;; - --nobuild) MAKEPKG_OPTS="$MAKEPKG_OPTS -o" ;; - --nocolor) MAKEPKG_OPTS="$MAKEPKG_OPTS -m" ;; - --help) - usage - exit 0 - ;; - --*) - usage - exit 1 - ;; - -*) - while getopts "chisSbdfrBCemoS-" opt; do - case $opt in - c) MAKEPKG_OPTS="$MAKEPKG_OPTS -c" ;; - i) MAKEPKG_OPTS="$MAKEPKG_OPTS -i" ;; - s) MAKEPKG_OPTS="$MAKEPKG_OPTS -s" ;; - b) MAKEPKG_OPTS="$MAKEPKG_OPTS -b" ;; - d) MAKEPKG_OPTS="$MAKEPKG_OPTS -d" ;; - f) MAKEPKG_OPTS="$MAKEPKG_OPTS -f" ;; - r) MAKEPKG_OPTS="$MAKEPKG_OPTS -r" ;; - B) MAKEPKG_OPTS="$MAKEPKG_OPTS -B" ;; - C) MAKEPKG_OPTS="$MAKEPKG_OPTS -C" ;; - e) MAKEPKG_OPTS="$MAKEPKG_OPTS -e" ;; - m) MAKEPKG_OPTS="$MAKEPKG_OPTS -m" ;; - o) MAKEPKG_OPTS="$MAKEPKG_OPTS -o" ;; - S) MAKEPKG_OPTS="$MAKEPKG_OPTS -S" ;; - h) - usage - exit 0 - ;; - -) - OPTIND=0 - break - ;; - esac - done - ;; - *) - dest=$arg - shift - break - ;; - esac - shift - if [ "$dest" != "" ]; then - break - fi -done - -if [ "$dest" = "" ]; then - usage - exit 1 -fi - -# convert a (possibly) relative path to absolute -cd "$dest" -dest="$(pwd)" -cd - &>/dev/null - -sd=$(date +"[%b %d %H:%M]") - -for category in $*; do - for port in $(find "$toplevel/$category" -maxdepth 1 -mindepth 1 -type d | sort); do - cd $port - if [ -f PKGBUILD ]; then - . PKGBUILD - buildstatus=0 - if [ ! -f "$dest/$pkgname-$pkgver-$pkgrel.pkg.tar.gz" ]; then - PKGDEST="$dest" makepkg $MAKEPKG_OPTS -m 2>>$toplevel/makepkg.log - if [ $? -gt 0 ]; then - buildstatus=2 - else - buildstatus=1 - fi - fi - d=$(date +"[%b %d %H:%M]") - echo -n "$d " >>$toplevel/build.log - case $buildstatus in - 0) echo "$pkgname already built -- skipping" >>$toplevel/build.log ;; - 1) echo "$pkgname was built successfully" >>$toplevel/build.log ;; - 2) echo "$pkgname build failed" >>$toplevel/build.log ;; - esac - fi - done -done -ed=$(date +"[%b %d %H:%M]") - -echo "makeworld complete." >>$toplevel/build.log -echo " started: $sd" >>$toplevel/build.log -echo " finished: $ed" >>$toplevel/build.log - -exit 0 - -# vim: set ts=2 sw=2 noet: diff --git a/scripts/makeworld.sh.in b/scripts/makeworld.sh.in new file mode 100644 index 00000000..49b758c6 --- /dev/null +++ b/scripts/makeworld.sh.in @@ -0,0 +1,194 @@ +#!/bin/bash +# +# makeworld +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver="@PACKAGE_VERSION@" +BUG_REPORT_EMAIL='@PACKAGE_BUGREPORT@' +toplevel=$(pwd) + +usage() { + printf "makeworld (pacman) %s\n" "$myver" + echo "$(gettext "Usage: %s [options] <destdir> <category> [category] ...")" "$0" + echo "$(gettext "Options:")" + echo "$(gettext " -b, --builddeps Build missing dependencies from source")" + echo "$(gettext " -B, --noccache Do not use ccache during build")" + echo "$(gettext " -c, --clean Clean up work files after build")" + echo "$(gettext " -C, --cleancache Clean up source files from the cache")" + echo "$(gettext " -d, --nodeps Skip all dependency checks")" + echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" + echo "$(gettext " -f, --force Overwrite existing packages")" + echo "$(gettext " -i, --install Install package after successful build")" + echo "$(gettext " -m, --nocolor Disable colorized output messages")" + echo "$(gettext " -h, --help This help")" + echo "$(gettext " -o, --nobuild Download and extract files only")" + echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" + echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" + echo "$(gettext " -S, --usesudo Use sudo when running pacman commands")" + echo + echo "$(gettext "These options can be passed to pacman:")" + echo + echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" + echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" + echo + echo "$(gettext "Where <category> is one or more directory names under the ABS root")" + echo "$(gettext "eg: makeworld -c /packages base lib editors")" + echo + echo "$(gettext "This should be run from the toplevel directory of ABS (usually /var/abs)")" +} + +version() { + printf "makeworld (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +MAKEPKG_OPTS= +for arg in $*; do + case $arg in + # pacman + --noconfirm) MAKEPKG_OPTS="$MAKEPKG_OPTS --noconfirm" ;; + --noprogressbar) MAKEPKG_OPTS="$MAKEPKG_OPTS --noprogressbar" ;; + # makepkg + --clean) MAKEPKG_OPTS="$MAKEPKG_OPTS -c" ;; + --install) MAKEPKG_OPTS="$MAKEPKG_OPTS -i" ;; + --syncdeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -s" ;; + --usesudo) MAKEPKG_OPTS="$MAKEPKG_OPTS -S" ;; + --builddeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -b" ;; + --nodeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -d" ;; + --force) MAKEPKG_OPTS="$MAKEPKG_OPTS -f" ;; + --rmdeps) MAKEPKG_OPTS="$MAKEPKG_OPTS -r" ;; + --noccache) MAKEPKG_OPTS="$MAKEPKG_OPTS -B" ;; + --cleancache) MAKEPKG_OPTS="$MAKEPKG_OPTS -C" ;; + --noextract) MAKEPKG_OPTS="$MAKEPKG_OPTS -e" ;; + --nobuild) MAKEPKG_OPTS="$MAKEPKG_OPTS -o" ;; + --nocolor) MAKEPKG_OPTS="$MAKEPKG_OPTS -m" ;; + --help) + usage + exit 0 + ;; + --version) + version + exit 0 + ;; + --*) + usage + exit 1 + ;; + -*) + while getopts "chisSbdfrBCemoSV-" opt; do + case $opt in + c) MAKEPKG_OPTS="$MAKEPKG_OPTS -c" ;; + i) MAKEPKG_OPTS="$MAKEPKG_OPTS -i" ;; + s) MAKEPKG_OPTS="$MAKEPKG_OPTS -s" ;; + b) MAKEPKG_OPTS="$MAKEPKG_OPTS -b" ;; + d) MAKEPKG_OPTS="$MAKEPKG_OPTS -d" ;; + f) MAKEPKG_OPTS="$MAKEPKG_OPTS -f" ;; + r) MAKEPKG_OPTS="$MAKEPKG_OPTS -r" ;; + B) MAKEPKG_OPTS="$MAKEPKG_OPTS -B" ;; + C) MAKEPKG_OPTS="$MAKEPKG_OPTS -C" ;; + e) MAKEPKG_OPTS="$MAKEPKG_OPTS -e" ;; + m) MAKEPKG_OPTS="$MAKEPKG_OPTS -m" ;; + o) MAKEPKG_OPTS="$MAKEPKG_OPTS -o" ;; + S) MAKEPKG_OPTS="$MAKEPKG_OPTS -S" ;; + h) + usage + exit 0 + ;; + V) + version + exit 0 + ;; + -) + OPTIND=0 + break + ;; + esac + done + ;; + *) + dest=$arg + shift + break + ;; + esac + shift + if [ "$dest" != "" ]; then + break + fi +done + +if [ "$dest" = "" ]; then + usage + exit 1 +fi + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +# convert a (possibly) relative path to absolute +cd "$dest" +dest="$(pwd)" +cd - &>/dev/null + +sd=$(date +"[%b %d %H:%M]") + +for category in $*; do + for port in $(find "$toplevel/$category" -maxdepth 1 -mindepth 1 -type d | sort); do + cd $port + if [ -f PKGBUILD ]; then + . PKGBUILD + buildstatus=0 + if [ ! -f "$dest/$pkgname-$pkgver-$pkgrel.pkg.tar.gz" ]; then + PKGDEST="$dest" makepkg $MAKEPKG_OPTS -m 2>>$toplevel/makepkg.log + if [ $? -gt 0 ]; then + buildstatus=2 + else + buildstatus=1 + fi + fi + d=$(date +"[%b %d %H:%M]") + echo -n "$d " >>$toplevel/build.log + case $buildstatus in + 0) echo "$pkgname already built -- skipping" >>$toplevel/build.log ;; + 1) echo "$pkgname was built successfully" >>$toplevel/build.log ;; + 2) echo "$pkgname build failed" >>$toplevel/build.log ;; + esac + fi + done +done +ed=$(date +"[%b %d %H:%M]") + +echo "makeworld complete." >>$toplevel/build.log +echo " started: $sd" >>$toplevel/build.log +echo " finished: $ed" >>$toplevel/build.log + +exit 0 + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/pacman-optimize b/scripts/pacman-optimize deleted file mode 100755 index ca170334..00000000 --- a/scripts/pacman-optimize +++ /dev/null @@ -1,145 +0,0 @@ -#!/bin/bash -# -# pacman-optimize -# -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. -# - -myver='3.0.0' - -error() { - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e "\033[1;31m:: ERROR:\033[1;0m \033[1;1m$@\033[1;0m" >&2 - else - echo ":: ERROR: $@" >&2 - fi -} - -source /etc/rc.conf #for USECOLOR -source /etc/rc.d/functions - -usage() { - echo "pacman-optimize $myver" - echo "usage: $0 [pacman_db_root]" - echo - echo "pacman-optimize is a little hack that should improve the performance" - echo "of pacman when reading/writing to its filesystem-based database." - echo - echo "Because pacman uses many small files to keep track of packages," - echo "there is a tendency for these files to become fragmented over time." - echo "This script attempts to relocate these small files into one" - echo "continuous location on your hard drive. The result is that the hard" - echo "drive should be able to read them faster, since the hard drive head" - echo "does not have to move around the disk as much." - echo -} - -die() { - error $@ - exit 1 -} - -die_r() { - rm -f /tmp/pacman.lck - die $@ -} - -dbroot="/var/lib/pacman" - -if [ "$1" != "" ]; then - if [ "$1" = "-h" -o "$1" = "--help" ]; then - usage - exit 0 - fi - dbroot="$1" -fi - -# make sure pacman isn't running -if [ -f /tmp/pacman.lck ]; then - die "Pacman lockfile was found. Cannot run while pacman is running." -fi - -if [ ! -d "$dbroot" ]; then - die "$dbroot does not exist or is not a directory" -fi - -if [ ! -w "$dbroot" ]; then - die "You must have correct permissions to optimize the database" -fi - -# do not let pacman run while we do this -touch /tmp/pacman.lck - -# step 1: sum the old db -stat_busy "Md5sum'ing the old database" -find $dbroot -type f | sort | xargs md5sum > /tmp/pacsums.old -stat_done - -# step 2: tar it up -stat_busy "Tar'ing up $dbroot" -cd $dbroot -tar -czf /tmp/pacmanDB.tgz ./ -if [ $? -ne 0 ]; then - stat_fail - rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old - die_r "tar'ing up $dbroot failed" -fi -stat_done - -# step 3: make and sum the new db -stat_busy "Making and md5sum'ing the new db" -mkdir $dbroot.new -tar -zxpf /tmp/pacmanDB.tgz -C $dbroot.new/ -if [ $? -ne 0 ]; then - rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old - rm -rf "$dbroot.new" - die_r "untar'ing $dbroot failed" -fi -find "$dbroot.new" -type f | sort | sed -e 's/pacman.new/pacman/g' |\ - xargs md5sum > /tmp/pacsums.new -stat_done - -# step 4: compare the sums -stat_busy "Checking integrity" -diff /tmp/pacsums.old /tmp/pacsums.new >/dev/null 2>&1 -if [ $? -ne 0 ]; then - # failed - stat_fail - # leave /tmp/pacsums.old and .new for checking to see what doesn't match up - rm -rf "$dbroot.new" /tmp/pacman.lck /tmp/pacmanDB.tgz - die_r "integrity check FAILED, reverting to old database" -fi -stat_done - -# step 5: remove the new temporary database and the old one -# and use the .tgz to replace the old one -stat_busy "Putting the new database in place" -rm -rf "$dbroot.new" "$dbroot"/* -tar -zxpf /tmp/pacmanDB.tgz -C "$dbroot"/ -stat_done - -# remove the lock file, sum files, and .tgz of database -rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz - -echo -echo "Finished. Your pacman database has been optimized." -echo - -exit 0 - -# vim: set ts=2 sw=2 noet: diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in new file mode 100644 index 00000000..513ed481 --- /dev/null +++ b/scripts/pacman-optimize.sh.in @@ -0,0 +1,164 @@ +#!/bin/bash +# +# pacman-optimize +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' +dbroot='@localstatedir@/lib/pacman/' +lockfile="${dbroot}db.lck" + +msg() { + local mesg=$1; shift + printf "==> ${mesg}\n" "$@" >&2 +} + +error () { + local mesg=$1; shift + printf "==> ERROR: ${mesg}\n" "$@" >&2 +} + +usage() { + printf "pacman-optimize (pacman) %s\n\n" "$myver" + printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0" + printf "$(gettext "\ +pacman-optimize is a little hack that should improve the performance\n\ +of pacman when reading/writing to its filesystem-based database.\n\n")" + printf "$(gettext "\ +Because pacman uses many small files to keep track of packages,\n\ +there is a tendency for these files to become fragmented over time.\n\ +This script attempts to relocate these small files into one\n\ +continuous location on your hard drive. The result is that the hard\n\ +drive should be able to read them faster, since the hard drive head\n\ +does not have to move around the disk as much.\n")" +} + +version() { + printf "pacman-optimize (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +die() { + error "$@" + exit 1 +} + +die_r() { + rm -f "$lockfile" + die "$@" +} + +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage + exit 0 +fi + +if [ "$1" = "-V" -o "$1" = "--version" ]; then + version + exit 0 +fi + +if [ "$1" != "" ]; then + dbroot="$1" +fi + +# make sure diff is installed +if ! type diff >/dev/null 2>&1; then + die "$(gettext "diff tool was not found, please install diffutils.")" +fi + +# make sure pacman isn't running +if [ -f "$lockfile" ]; then + die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")" +fi + +if [ ! -d "$dbroot" ]; then + die "$(gettext "%s does not exist or is not a directory.")" "$dbroot" +fi + +if [ ! -w "$dbroot" ]; then + die "$(gettext "You must have correct permissions to optimize the database.")" +fi + +workdir=$(mktemp -d /tmp/pacman-optimize.XXXXXXXXXX) || + die_r "$(gettext "ERROR: Can not create temp directory for database building.")\n" >&2 + +# do not let pacman run while we do this +touch "$lockfile" + +# step 1: sum the old db +msg "$(gettext "MD5sum'ing the old database...")" +find "$dbroot" -type f | sort | xargs md5sum > "$workdir/pacsums.old" + +# step 2: tar it up +msg "$(gettext "Tar'ing up %s...")" "$dbroot" +cd "$dbroot" +bsdtar -czf "$workdir/pacmanDB.tgz" ./ +if [ $? -ne 0 ]; then + rm -rf "$workdir" + die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot" +fi + +# step 3: make and sum the new db +msg "$(gettext "Making and MD5sum'ing the new db...")" +mkdir "$dbroot.new" +bsdtar -zxpf "$workdir/pacmanDB.tgz" -C "$dbroot.new/" +if [ $? -ne 0 ]; then + rm -rf "$workdir" + die_r "$(gettext "Untar'ing %s failed.")" "$dbroot" +fi +find "$dbroot.new" -type f | sort | \ + xargs md5sum | sed 's#.new/##' > "$workdir/pacsums.new" + +# step 4: compare the sums +msg "$(gettext "Checking integrity...")" +diff "$workdir/pacsums.old" "$workdir/pacsums.new" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + # failed + # leave /tmp/pacsums.old and .new for checking to see what doesn't match up + rm -rf "$dbroot.new" + die_r "$(gettext "Integrity check FAILED, reverting to old database.")" +fi + +# step 5: remove the new temporary database and the old one +# and use the .tgz to replace the old one +msg "$(gettext "Putting the new database in place...")" +rm -rf "$dbroot.new" "$dbroot"/* +bsdtar -zxpf "$workdir/pacmanDB.tgz" -C "$dbroot/" + +# remove the lock file, sum files, and .tgz of database +rm -f "$lockfile" +rm -rf "$workdir" + +echo +msg "$(gettext "Finished. Your pacman database has been optimized.")" +msg "$(gettext "For full benefits of pacman-optimize, run 'sync' now.")" +echo + +exit 0 + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/rankmirrors b/scripts/rankmirrors.py.in index 3eb10b5a..0c50bdd8 100644 --- a/scripts/rankmirrors +++ b/scripts/rankmirrors.py.in @@ -1,9 +1,9 @@ #! /usr/bin/python # -# rankmirrors : read a list of mirrors from a file and rank them by speed +# rankmirrors - read a list of mirrors from a file and rank them by speed +# @configure_input@ # -# Original Idea copyright (c) 2006 R.G. <chesercat> -# Modified 2006 by Dan McGee <dan@archlinux.org> +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,13 +22,19 @@ # import os, sys, datetime, time, socket, urllib2 from optparse import OptionParser +from string import Template def createOptParser(): usage = "usage: %prog [options] MIRRORFILE | URL" + version = "%prog (pacman) @PACKAGE_VERSION@\n" \ + "Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n" \ + "This is free software; see the source for copying conditions.\n" \ + "There is NO WARRANTY, to the extent permitted by law." description = "Ranks pacman mirrors by their connection and opening " \ "speed. Pacman mirror files are located in /etc/pacman.d/. It " \ "can also rank one mirror if the URL is provided." - parser = OptionParser(usage = usage, description = description) + parser = OptionParser(usage = usage, version = version, + description = description) parser.add_option("-n", type = "int", dest = "num", default = 0, help = "number of servers to output, 0 for all") parser.add_option("-t", "--times", action = "store_true", @@ -39,6 +45,9 @@ def createOptParser(): parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False, help = "be verbose in ouptut") + # The following two options should be automatic + #parser.add_option("-h", "--help", action = "help") + #parser.add_option("-V", "--version", action = "version") return parser def timeCmd(cmd): @@ -112,11 +121,15 @@ if __name__ == "__main__": print args[0], ':', "%.2f" % serverToTime sys.exit(0) - if not os.path.isfile(args[0]): + if not os.path.isfile(args[0]) and args[0] != "-": print >>sys.stderr, 'rankmirrors: file', args[0], 'does not exist.' sys.exit(1) - fl = open(args[0], 'r') + if args[0] == "-": + fl = sys.stdin + else: + fl = open(args[0], 'r') + serverToTime = {} if options.times: print 'Querying servers, this may take some time...' @@ -141,12 +154,15 @@ if __name__ == "__main__": print ' * ', sys.stdout.flush() + # if the $repo var is used in the url, replace it by core + tempUrl = Template(serverUrl).safe_substitute(repo='core') + # add *.db.tar.gz to server name. the repo name is parsed # from the mirror url; it is the third (or fourth) dir # from the end, where the url is http://foo/bar/REPO/os/arch try: - splitted2 = serverUrl.split('/') - if serverUrl[-1] != '/': + splitted2 = tempUrl.split('/') + if tempUrl[-1] != '/': repoName = splitted2[-3] dbFileName = '/' + repoName + '.db.tar.gz' else: @@ -156,7 +172,7 @@ if __name__ == "__main__": dbFileName = '' try: - serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl + dbFileName)) + serverToTime[serverUrl] = timeCmd(getFuncToTime(tempUrl + dbFileName)) if options.verbose: try: print "%.2f" % serverToTime[serverUrl] diff --git a/scripts/repo-add b/scripts/repo-add deleted file mode 100755 index 642100d0..00000000 --- a/scripts/repo-add +++ /dev/null @@ -1,288 +0,0 @@ -#!/bin/bash -# -# repo-add : add a package to a given repo database file -# -# Copyright (c) 2006 Aaron Griffin <aaron@archlinux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. - -myver='3.0.3' - -FORCE=0 -REPO_DB_FILE="" - -DB_COMPRESSION="gz" #TODO this is gross -DB_CHECKSUMS=(md5) -TMP_DIR="" - -# print usage instructions -usage() { - echo "repo-add $myver" - echo - echo "usage: repo-add <path-to-db> [--force] <package> ..." - echo - echo "repo-add will update a package database by reading a package file." - echo "Multiple packages to add can be specified on the command line." - echo - echo "The --force flag will add a 'force' entry to the sync database, which" - echo "tells pacman to skip its internal version number checking and update" - echo "the package regardless." - echo - echo "Example:" - echo " repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz" - echo -} - -# return calculated checksum of package -# arg1 - checksum type -# arg2 - path to package -get_checksum () { - case "$(echo "$1" | tr A-Z a-z)" in - md5) sum=$(md5sum $2); echo ${sum% *} ;; - sha1) sum=$(sha1sum $2); echo ${sum% *} ;; - sha256) sum=$(sha256sum $2); echo ${sum% *} ;; - sha384) sum=$(sha256sum $2); echo ${sum% *} ;; - sha512) sum=$(sha256sum $2); echo ${sum% *} ;; - esac -} - -# return PKGINFO string for checksum type -# arg1 - checksum type -checksum_name () { - case "$(echo "$1" | tr A-Z a-z)" in - md5) echo "MD5SUM" ;; - sha1) echo "SHA1SUM" ;; - sha256) echo "SHA256SUM" ;; - sha384) echo "SHA384SUM" ;; - sha512) echo "SHA512SUM" ;; - esac -} - -# test if a file is a repository DB -test_repo_db_file () { - if [ -f "$REPO_DB_FILE" ]; then - [ "$(tar tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1 - else - true - fi -} - -# write an entry to the pacman database -# arg1 - path to package -db_write_entry() -{ - # blank out all variables and set pkgfile - pkgfile=$(readlink -f $1) - export pkgname="" - pkgver="" - pkgdesc="" - url="" - builddate="" - packager="" - csize="" - size="" - _groups="" - _depends="" - _backups="" - _licenses="" - _replaces="" - _provides="" - _conflicts="" - - OLDIFS="$IFS" - # IFS (field seperator) is only the newline character - IFS=" -" - - # read info from the zipped package - for i in $(tar xOf "$pkgfile" .PKGINFO | grep -v "^#" |sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do - eval "${i}" - case "$i" in - group=*) _groups="$_groups $group" ;; - depend=*) _depends="$_depends $depend" ;; - backup=*) _backups="$_backups $backup" ;; - license=*) _licenses="$_licenses $license" ;; - replaces=*) _replaces="$_replaces $replaces" ;; - provides=*) _provides="$_provides $provides" ;; - conflict=*) _conflicts="$_conflicts $conflict" ;; - esac - done - - IFS=$OLDIFS - - # get compressed size of package - csize="$(du -b $pkgfile | cut -f1)" - - cd $gstmpdir - - # ensure $pkgname and $pkgver variables were found - if [ -z "$pkgname" -o -z "$pkgver" ]; then - echo " error: invalid package file" - return 1 - fi - - # remove any other package in the DB with same name - for existing in *; do - if [ "${existing%-*-*}" = "$pkgname" ]; then - echo ":: removing existing package '$existing'" - rm -rf $existing - fi - done - - # create package directory - mkdir "$pkgname-$pkgver" - cd "$pkgname-$pkgver" - - # create desc entry - echo ":: creating 'desc' db entry" - echo -e "%FILENAME%\n$(basename $1)\n" >>desc - echo -e "%NAME%\n$pkgname\n" >>desc - echo -e "%VERSION%\n$pkgver\n" >>desc - if [ -n "$pkgdesc" ]; then - echo -e "%DESC%\n$pkgdesc\n" >>desc - fi - if [ -n "$_groups" ]; then - echo "%GROUPS%" >>desc - echo $_groups | tr -s ' ' '\n' >>desc - echo "" >>desc - fi - [ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc - [ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc - - # compute checksums - for chk in ${DB_CHECKSUMS[@]}; do - name="$(checksum_name $chk)" - echo ":: computing $name checksums" - if [ -n "$name" ]; then - echo -e "%$name%\n$(get_checksum $chk $pkgfile)\n" >>desc - fi - done - - [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc - if [ -n "$_licenses" ]; then - echo "%LICENSE%" >>desc - echo $_licenses | tr -s ' ' '\n' >>desc - echo "" >>desc - fi - [ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc - [ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc - [ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc - - if [ -n "$_replaces" ]; then - echo "%REPLACES%" >>desc - echo $_replaces | tr -s ' ' '\n' >>desc - echo "" >>desc - fi - [ "$FORCE" = "1" ] && echo -e "%FORCE%\n" >>desc - - # create depends entry - echo ":: creating 'depends' db entry" - if [ -n "$_depends" ]; then - echo "%DEPENDS%" >>depends - echo $_depends | tr -s ' ' '\n' >>depends - echo "" >>depends - fi - if [ -n "$_conflicts" ]; then - echo "%CONFLICTS%" >>depends - echo $_conflicts | tr -s ' ' '\n' >>depends - echo "" >>depends - fi - if [ -n "$_provides" ]; then - echo "%PROVIDES%" >>depends - echo $_provides | tr -s ' ' '\n' >>depends - echo "" >>depends - fi - - # preserve the modification time - touch -r "$pkgfile" desc depends -} # end db_write_entry - -# PROGRAM START - -# check for help flags -if [ "$1" = "-h" -o "$1" = "--help" ]; then - usage - exit 0 -fi - -# check for correct number of args -if [ $# -lt 2 ]; then - usage - exit 1 -fi - -# main routine -if [ $# -gt 1 ]; then - gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ - echo "cannot create temp directory for database building"; \ - exit 1) - - success=0 - # parse arguements - for arg in $@; do - if [ "$arg" == "--force" -o "$arg" == "-f" ]; then - FORCE=1 - elif [ -z "$REPO_DB_FILE" ]; then - REPO_DB_FILE="$(readlink -f $arg)" - if ! test_repo_db_file; then - echo "error: repository file '$REPO_DB_FILE' is not a proper pacman db" - exit 1 - elif [ -f "$REPO_DB_FILE" ]; then - echo ":: extracting database to a temporary location" - tar xf "$REPO_DB_FILE" -C "$gstmpdir" - fi - else - if [ -f "$arg" ]; then - if ! tar tf "$arg" .PKGINFO 2>&1 >/dev/null; then - echo "error: '$arg' is not a package file, skipping" - else - echo ":: adding package '$arg'" - - this_dir="$(pwd)" - if db_write_entry "$arg"; then - success=1 - fi - cd $this_dir - fi - else - echo "error: package '$arg' not found" - fi - fi - done - - # if all operations were a success, rezip database - if [ "$success" = "1" ]; then - echo ":: creating updated database file ${REPO_DB_FILE}" - cd $gstmpdir - if [ -n "$(ls)" ]; then - [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old" - [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old" - case "$DB_COMPRESSION" in - gz) tar c * | gzip -9 >$REPO_DB_FILE ;; - bz2) tar c * | bzip2 -9 >$REPO_DB_FILE ;; - *) echo "warning: no compression set" - tar c * >$REPO_DB_FILE;; - esac - fi - else - echo ":: no packages modified, nothing to do" - fi -fi - -# remove the temp directory used to unzip -[ -d "$gstmpdir" ] && rm -rf $gstmpdir - -# vim: set ts=2 sw=2 noet: diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in new file mode 100644 index 00000000..adcefc1d --- /dev/null +++ b/scripts/repo-add.sh.in @@ -0,0 +1,346 @@ +#!/bin/bash +# +# repo-add - add a package to a given repo database file +# @configure_input@ +# +# Copyright (c) 2006 Aaron Griffin <aaron@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' +confdir='@sysconfdir@' + +FORCE=0 +REPO_DB_FILE="" + +msg() { + local mesg=$1; shift + printf "==> ${mesg}\n" "$@" >&1 +} + +msg2() { + local mesg=$1; shift + printf " -> ${mesg}\n" "$@" >&1 +} + +warning() { + local mesg=$1; shift + printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 +} + +error() { + local mesg=$1; shift + printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 +} + +# print usage instructions +usage() { + printf "repo-add (pacman) %s\n\n" "$myver" + printf "$(gettext "Usage: %s <path-to-db> [--force] <package> ...\n\n")" "$0" + printf "$(gettext "\ +repo-add will update a package database by reading a package file.\n\ +Multiple packages to add can be specified on the command line.\n\n")" + printf "$(gettext "\ +The --force flag will add a 'force' entry to the sync database, which\n\ +tells pacman to skip its internal version number checking and update\n\ +the package regardless.\n\n")" + echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")" +} + +version() { + printf "repo-add (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2006 Aaron Griffin <aaron@archlinux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +# test if a file is a repository DB +test_repo_db_file () { + if [ -f "$REPO_DB_FILE" ]; then + if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then + return 0 # YES + fi + else + return 0 # YES - No database file is also aloud. + fi + + return 1 # NO +} + +# write a list entry +# arg1 - Entry name +# arg2 - List +# arg3 - File to write to +write_list_entry() { + if [ -n "$2" ]; then + echo "%$1%" >>$3 + echo $2 | tr -s ' ' '\n' >>$3 + echo "" >>$3 + fi +} + +# write a delta entry to the pacman database +# arg1 - path to delta +db_write_delta() +{ + # blank out all variables and set deltafile + local deltafile=$(readlink -f "$1") + local filename=$(basename "$deltafile") + local deltavars pkgname fromver tover arch csize md5sum + + # format of the delta filename: + # (package)-(fromver)_to_(tover)-(arch).delta + deltavars=( $(echo "$filename" | sed -e 's/\(.*\)-\(.*-.*\)_to_\(.*-.*\)-\(.*\).delta/\1 \2 \3 \4/') ) + pkgname=${deltavars[0]} + fromver=${deltavars[1]} + tover=${deltavars[2]} + arch=${deltavars[3]} + + # get md5sum and size of delta + md5sum="$(md5sum "$deltafile" | cut -d ' ' -f 1)" + csize=$(du -b -L "$deltafile" | cut -f 1) + + # ensure variables were found + if [ -z "$pkgname" -o -z "$fromver" -o -z "$tover" -o -z "$arch" ]; then + return 1 + fi + + # add the entry for this delta file + echo -e "$fromver $tover $csize $filename $md5sum" >>deltas +} # end db_write_delta + + +# write an entry to the pacman database +# arg1 - path to package +db_write_entry() +{ + # blank out all variables and set pkgfile + local pkgfile=$(readlink -f "$1") + local pkgname pkgver pkgdesc url builddate packager csize size \ + group depend backup license replaces provides conflict \ + _groups _depends _backups _licenses _replaces _provides _conflicts \ + startdir + + local OLDIFS="$IFS" + # IFS (field seperator) is only the newline character + IFS=" +" + + # read info from the zipped package + local line + for line in $(bsdtar -xOf "$pkgfile" .PKGINFO | \ + grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do + eval "$line" + case "$line" in + group=*) _groups="$_groups $group" ;; + depend=*) _depends="$_depends $depend" ;; + backup=*) _backups="$_backups $backup" ;; + license=*) _licenses="$_licenses $license" ;; + replaces=*) _replaces="$_replaces $replaces" ;; + provides=*) _provides="$_provides $provides" ;; + conflict=*) _conflicts="$_conflicts $conflict" ;; + esac + done + + IFS=$OLDIFS + + # get compressed size of package + csize=$(du -b -L "$pkgfile" | cut -f 1) + + startdir=$(pwd) + pushd "$gstmpdir" 2>&1 >/dev/null + + # ensure $pkgname and $pkgver variables were found + if [ -z "$pkgname" -o -z "$pkgver" ]; then + error "$(gettext "Invalid package file '%s'.")" "$pkgfile" + popd 2>&1 >/dev/null + return 1 + fi + + # remove any other package in the DB with same name + local existing + for existing in *; do + if [ "${existing%-*-*}" = "$pkgname" ]; then + msg2 "$(gettext "Removing existing package '%s'...")" "$existing" + rm -rf "$existing" + fi + done + + # create package directory + mkdir "$pkgname-$pkgver" + cd "$pkgname-$pkgver" + + # create desc entry + msg2 "$(gettext "Creating 'desc' db entry...")" + echo -e "%FILENAME%\n$(basename "$1")\n" >>desc + echo -e "%NAME%\n$pkgname\n" >>desc + echo -e "%VERSION%\n$pkgver\n" >>desc + [ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc + write_list_entry "GROUPS" "$_groups" "desc" + [ -n $csize ] && echo -e "%CSIZE%\n$csize\n" >>desc + [ -n $size ] && echo -e "%ISIZE%\n$size\n" >>desc + + # compute checksums + msg2 "$(gettext "Computing md5 checksums...")" + echo -e "%MD5SUM%\n$(md5sum "$pkgfile" | cut -d ' ' -f 1)\n" >>desc + + [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc + write_list_entry "LICENSE" "$_licenses" "desc" + [ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc + [ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc + [ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc + write_list_entry "REPLACES" "$_replaces" "desc" + [ $FORCE -eq 1 ] && echo -e "%FORCE%\n" >>desc + + # create depends entry + msg2 "$(gettext "Creating 'depends' db entry...")" + write_list_entry "DEPENDS" "$_depends" "depends" + write_list_entry "CONFLICTS" "$_conflicts" "depends" + write_list_entry "PROVIDES" "$_provides" "depends" + + # create deltas entry if there are delta files + for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do + # This for loop also pulls in all files that start with the current package + # name and are followed by a -whatever. For instance, running this loop for + # gcc would also grab gcc-libs. To guard against this, compare the package + # name of the delta to the current package name. + local filename=$(basename "$delta") + local dpkgname="$(echo "$filename" | sed -e 's/\(.*\)-.*-.*_to_.*-.*-.*.delta/\1/')" + if [ "$pkgname" = "$dpkgname" -a -f "$delta" ]; then + # create deltas file if it does not already exist + if [ ! -f "deltas" ]; then + msg2 "$(gettext "Creating 'deltas' db entry...")" + echo -e "%DELTAS%" >>deltas + fi + + # write this delta entry + if db_write_delta "$delta"; then + msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")" + else + msg2 "$(gettext "Could not add delta '%s'")" "$(basename "$delta")" + fi + fi + done + # add the final newline + [ -f "deltas" ] && echo -e "" >>deltas + + # preserve the modification time + touch -r "$pkgfile" desc depends + [ -f "deltas" ] && touch -r "$pkgfile" deltas + + popd 2>&1 >/dev/null +} # end db_write_entry + +# PROGRAM START + +# check for help flags +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage + exit 0 +fi + +# check for version flags +if [ "$1" = "-V" -o "$1" = "--version" ]; then + version + exit 0 +fi + +# check for correct number of args +if [ $# -lt 2 ]; then + usage + exit 1 +fi + +# source system and user makepkg.conf +if [ -r "$confdir/makepkg.conf" ]; then + source "$confdir/makepkg.conf" +else + error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf" + exit 1 # $E_CONFIG_ERROR +fi + +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# main routine +gstmpdir=$(mktemp -d /tmp/repo-add.XXXXXXXXXX) || (\ + error "$(gettext "Cannot create temp directory for database building.")"; \ + exit 1) + +success=0 +# parse arguements +for arg in "$@"; do + if [ "$arg" == "--force" -o "$arg" == "-f" ]; then + FORCE=1 + elif [ -z "$REPO_DB_FILE" ]; then + REPO_DB_FILE=$(readlink -f "$arg") + if ! test_repo_db_file; then + error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE" + exit 1 + elif [ -f "$REPO_DB_FILE" ]; then + msg "$(gettext "Extracting database to a temporary location...")" + bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir" + fi + else + if [ -f "$arg" ]; then + if ! bsdtar -tf "$arg" .PKGINFO 2>&1 >/dev/null; then + error "$(gettext "'%s' is not a package file, skipping")" "$arg" + else + msg "$(gettext "Adding package '%s'")" "$arg" + + if db_write_entry "$arg"; then + success=1 + fi + fi + else + error "$(gettext "Package '%s' not found.")" "$arg" + fi + fi +done + +# if all operations were a success, rezip database +if [ $success -eq 1 ]; then + msg "$(gettext "Creating updated database file %s")" "$REPO_DB_FILE" + pushd "$gstmpdir" 2>&1 >/dev/null + + if [ -n "$(ls)" ]; then + [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old" + [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old" + + case "$DB_COMPRESSION" in + gz) TAR_OPT="z" ;; + bz2) TAR_OPT="j" ;; + *) warning "$(gettext "No compression set.")" ;; + esac + + bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" * + fi + + popd 2>&1 >/dev/null +else + msg "$(gettext "No packages modified, nothing to do.")" +fi + +# remove the temp directory used to unzip +[ -d "$gstmpdir" ] && rm -rf "$gstmpdir" + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/repo-remove b/scripts/repo-remove deleted file mode 100755 index eeee2406..00000000 --- a/scripts/repo-remove +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash -# -# repo-remove : remove a package entry from a given repo database file -# -# Copyright (c) 2007 Dan McGee <dan@archlinux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. - -myver='3.0.0' - -FORCE=0 -REPO_DB_FILE="" - -DB_COMPRESSION="gz" #TODO this is gross -DB_CHECKSUMS=(md5) -TMP_DIR="" - -# print usage instructions -usage() { - echo "repo-remove $myver" - echo - echo "usage: repo-remove <path-to-db> <packagename> ..." - echo - echo "repo-remove will update a package database by removing the package name" - echo "specified on the command line from the given repo database. Multiple" - echo "packages to remove can be specified on the command line." - echo - echo "Example:" - echo " repo-remove /path/to/repo.db.tar.gz kernel26" - echo -} - -# test if a file is a repository DB -test_repo_db_file () { - if [ -f "$REPO_DB_FILE" ]; then - [ "$(tar tf "$REPO_DB_FILE" | grep -c "/desc")" -gt 0 ] || return 1 - else - true - fi -} - -# remove existing entries from the DB -db_remove_entry() -{ - cd $gstmpdir - - # remove any other package in the DB with same name - for existing in *; do - if [ "${existing%-*-*}" = "$1" ]; then - echo ":: removing existing package '$existing'" - rm -rf $existing - fi - done -} # end db_remove_entry - -# PROGRAM START - -# check for help flags -if [ "$1" = "-h" -o "$1" = "--help" ]; then - usage - exit 0 -fi - -# check for correct number of args -if [ $# -lt 2 ]; then - usage - exit 1 -fi - -# main routine -if [ $# -gt 1 ]; then - gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ - echo "cannot create temp directory for database building"; \ - exit 1) - - success=0 - # parse arguements - for arg in $@; do - if [ -z "$REPO_DB_FILE" ]; then - REPO_DB_FILE="$(readlink -f $arg)" - if ! test_repo_db_file; then - echo "error: repository file '$REPO_DB_FILE' is not a proper pacman db" - exit 1 - elif [ -f "$REPO_DB_FILE" ]; then - echo ":: extracting database to a temporary location" - tar xf "$REPO_DB_FILE" -C "$gstmpdir" - fi - else - echo ":: searching for package '$arg'" - - this_dir="$(pwd)" - if db_remove_entry "$arg"; then - success=1 - else - echo "error: package matching '$arg' not found" - fi - cd $this_dir - fi - done - - # if all operations were a success, rezip database - if [ "$success" = "1" ]; then - echo ":: creating updated database file ${REPO_DB_FILE}" - cd $gstmpdir - if [ -n "$(ls)" ]; then - [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old" - [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old" - case "$DB_COMPRESSION" in - gz) tar c * | gzip -9 >$REPO_DB_FILE ;; - bz2) tar c * | bzip2 -9 >$REPO_DB_FILE ;; - *) echo "warning: no compression set" - tar c * >$REPO_DB_FILE;; - esac - fi - else - echo ":: no packages modified, nothing to do" - fi -fi - -# remove the temp directory used to unzip -[ -d "$gstmpdir" ] && rm -rf $gstmpdir - -# vim: set ts=2 sw=2 noet: diff --git a/scripts/repo-remove.sh.in b/scripts/repo-remove.sh.in new file mode 100644 index 00000000..617f04cf --- /dev/null +++ b/scripts/repo-remove.sh.in @@ -0,0 +1,184 @@ +#!/bin/bash +# +# repo-remove - remove a package entry from a given repo database file +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' +confdir='@sysconfdir@' + +FORCE=0 +REPO_DB_FILE="" + +msg() { + local mesg=$1; shift + printf "==> ${mesg}\n" "$@" >&1 +} + +msg2() { + local mesg=$1; shift + printf " -> ${mesg}\n" "$@" >&1 +} + +warning() { + local mesg=$1; shift + printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 +} + +error() { + local mesg=$1; shift + printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 +} + +# print usage instructions +usage() { + printf "$(gettext "repo-remove %s\n\n")" $myver + printf "$(gettext "usage: %s <path-to-db> <packagename> ...\n\n")" "$0" + printf "$(gettext "\ +repo-remove will update a package database by removing the package name\n\ +specified on the command line from the given repo database. Multiple\n\ +packages to remove can be specified on the command line.\n\n")" + echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")" +} + +version() { + printf "repo-remove (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +# test if a file is a repository DB +test_repo_db_file () { + if [ -f "$REPO_DB_FILE" ]; then + if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then + return 0 # YES + fi + fi + + return 1 # NO +} + +# remove existing entries from the DB +db_remove_entry() { + pushd "$gstmpdir" 2>&1 >/dev/null + + # remove any other package in the DB with same name + local existing + for existing in *; do + if [ "${existing%-*-*}" = "$1" ]; then + msg2 "$(gettext "Removing existing package '%s'...")" "$existing" + rm -rf "$existing" + fi + done + + popd 2>&1 >/dev/null +} # end db_remove_entry + +# PROGRAM START + +# check for help flags +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage + exit 0 +fi + +# check for version flags +if [ "$1" = "-V" -o "$1" = "--version" ]; then + version + exit 0 +fi + +# check for correct number of args +if [ $# -lt 2 ]; then + usage + exit 1 +fi + +# source system and user makepkg.conf +if [ -r "$confdir/makepkg.conf" ]; then + source "$confdir/makepkg.conf" +else + error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf" + exit 1 # $E_CONFIG_ERROR +fi + +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# main routine +gstmpdir=$(mktemp -d /tmp/repo-remove.XXXXXXXXXX) || (\ + error "$(gettext "Cannot create temp directory for database building.")"; \ + exit 1) + +success=0 +# parse arguements +for arg in "$@"; do + if [ -z "$REPO_DB_FILE" ]; then + REPO_DB_FILE=$(readlink -f "$arg") + if ! test_repo_db_file; then + error "$(gettext "Repository file '%s' is not a proper pacman database.")\n" "$REPO_DB_FILE" + exit 1 + elif [ -f "$REPO_DB_FILE" ]; then + msg "$(gettext "Extracting database to a temporary location...")" + bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir" + fi + else + msg "$(gettext "Searching for package '%s'...")" "$arg" + + if db_remove_entry "$arg"; then + success=1 + else + error "$(gettext "Package matching '%s' not found.")" "$arg" + fi + fi +done + +# if all operations were a success, rezip database +if [ $success -eq 1 ]; then + msg "$(gettext "Creating updated database file '%s'...")" "$REPO_DB_FILE" + pushd "$gstmpdir" 2>&1 >/dev/null + + if [ -n "$(ls)" ]; then + [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old" + [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old" + case "$DB_COMPRESSION" in + gz) TAR_OPT="z" ;; + bz2) TAR_OPT="j" ;; + *) warning "$(gettext "No compression set.")" ;; + esac + + bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" * + fi + + popd 2>&1 >/dev/null +else + msg "$(gettext "No packages modified, nothing to do.")" +fi + +# remove the temp directory used to unzip +[ -d "$gstmpdir" ] && rm -rf $gstmpdir + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/updatesync b/scripts/updatesync deleted file mode 100755 index a4a6847f..00000000 --- a/scripts/updatesync +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash -# -# updatesync -# -# Copyright (c) 2004 by Jason Chu <jason@archlinux.org> -# Derived from gensync (c) 2002-2006 Judd Vinet <jvinet@zeroflux.org> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, -# USA. -# - -myver='3.0.0' - -usage() { - echo "updatesync $myver" - echo "usage: $0 <action> <destfile> <option> [package_directory]" - echo - echo "updatesync will update a sync database by reading a PKGBUILD and" - echo "modifying the destfile. updatesync updates the database in a temporary" - echo "directory and then compresses it to <destfile>." - echo - echo "There are two types of actions:" - echo - echo "upd - Will update a package's entry or create it if it doesn't exist." - echo " It takes the package's PKGBUILD as an option." - echo "del - Will remove a package's entry from the db." - echo " It takes the package's name as an option." - echo - echo "updatesync will calculate md5sums of packages in the same directory as" - echo "<destfile>, unless an alternate [package_directory] is specified." - echo - echo "example: updatesync upd /home/mypkgs/custom.db.tar.gz PKGBUILD" - echo - echo - exit 0 -} - -BUILDSCRIPT="PKGBUILD" -PKGEXT="pkg.tar.gz" - -source /etc/makepkg.conf - -error () { - echo "==> ERROR: $*" >&2 -} - -die () { - error $* - exit 1 -} - -check_force () { - local i - for i in ${options[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "force" ]; then - true - fi - done - false -} - -if [ $# -lt 3 ]; then - usage - exit 1 -fi - -if [ "$1" = "-h" -o "$1" = "--help" ]; then - usage - exit 0 -fi - -if [ "$1" != "upd" -a "$1" != "del" ]; then - usage - exit 1 -fi - -action=$1 -pkgdb=$2 -option=$3 -pkgdir="$(pwd)" -if [ "$4" != "" ]; then - pkgdir="$4" -fi -opt_force="" - -if [ ! -f "$option" ]; then - die "$option not found" -fi - -if [ "$action" = "upd" ]; then # INSERT / UPDATE - unset pkgname pkgver pkgrel options - - source $option || die "failed to parse $option" - pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT" - - if [ ! -f "$pkgfile" ]; then - die "could not find $pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT - aborting" - fi - - if check_force; then - opt_force="--force" - fi - - repo-add "$pkgdb" $opt_force "$pkgfile" -else # DELETE - fname="$(basename $option)" - if [ "$fname" = "PKGBUILD" ]; then - unset pkgname pkgver pkgrel options - source $option - else - pkgname=$1 - fi - - repo-remove "$pkgdb" "$pkgname" -fi - -exit 0 -# vim: set ts=2 sw=2 noet: diff --git a/scripts/updatesync.sh.in b/scripts/updatesync.sh.in new file mode 100644 index 00000000..57bd39cb --- /dev/null +++ b/scripts/updatesync.sh.in @@ -0,0 +1,157 @@ +#!/bin/bash +# +# updatesync +# @configure_input@ +# +# Copyright (c) 2004 by Jason Chu <jason@archlinux.org> +# Derived from gensync (c) 2002-2006 Judd Vinet <jvinet@zeroflux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +# gettext initialization +export TEXTDOMAIN='pacman' +export TEXTDOMAINDIR='@localedir@' + +myver='@PACKAGE_VERSION@' + +# functions + +usage() { + printf "updatesync (pacman) %s\n\n" "$myver" + printf "$(gettext "Usage: %s <action> <destfile> <option> [package_directory]")\n\n" "$0" + printf "$(gettext "\ +updatesync will update a sync database by reading a PKGBUILD and\n\ +modifying the destfile. updatesync updates the database in a temporary\n\ +directory and then compresses it to <destfile>.\n\n")" + printf "$(gettext "There are two types of actions:\n\n")" + printf "$(gettext "upd - Will update a package's entry or create it if it doesn't exist.\n It takes the package's PKGBUILD as an option.\n")" + printf "$(gettext "del - Will remove a package's entry from the db. It takes the package's\n name as an option.\n")" + echo + printf "$(gettext "\ +updatesync will calculate md5sums of packages in the same directory as\n\ +<destfile>, unless an alternate [package_directory] is specified.\n\n")" + echo "$(gettext "Example: updatesync upd /home/mypkgs/custom.db.tar.gz PKGBUILD")" + exit 0 +} + +version() { + printf "updatesync (pacman) %s\n" "$myver" + printf "$(gettext "\ +Copyright (C) 2004 Jason Chu <jason@archlinux.org>.\n\n\ +This is free software; see the source for copying conditions.\n\ +There is NO WARRANTY, to the extent permitted by law.\n")" +} + +error () { + local mesg=$1; shift + printf "==> ERROR: ${mesg}\n" "$@" >&2 +} + +die () { + error $* + exit 1 +} + +check_force () { + local i + for i in ${options[@]}; do + local lc=$(echo $i | tr [:upper:] [:lower:]) + if [ "$lc" = "force" ]; then + true + fi + done + false +} + +# PROGRAM START + +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage + exit 0 +fi + +if [ "$1" = "-V" -o "$1" = "--version" ]; then + version + exit 0 +fi + +if [ $# -lt 3 ]; then + usage + exit 1 +fi + +# source system and user makepkg.conf +if [ -r @sysconfdir@/makepkg.conf ]; then + source @sysconfdir@/makepkg.conf +else + die "$(gettext "%s not found. Can not continue.")" "@sysconfdir@/makepkg.conf" +fi + +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +if [ "$1" != "upd" -a "$1" != "del" ]; then + usage + exit 1 +fi + +action=$1 +pkgdb=$2 +option=$3 +pkgdir="$(pwd)" +if [ "$4" != "" ]; then + pkgdir="$4" +fi +opt_force="" + +if [ ! -f "$option" ]; then + die "$(gettext "%s not found")" $option +fi + +if [ "$action" = "upd" ]; then # INSERT / UPDATE + unset pkgname pkgver pkgrel options + + source $option || die "$(gettext "failed to parse %s")" $option + if [ "$arch" = 'any' ]; then + CARCH='any' + fi + pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-$CARCH.$PKGEXT" + + if [ ! -f "$pkgfile" ]; then + die "$(gettext "could not find %s-%s-%s-%s.%s - aborting")" $pkgname $pkgver $pkgrel $CARCH $PKGEXT + fi + + if check_force; then + opt_force="--force" + fi + + repo-add "$pkgdb" $opt_force "$pkgfile" +else # DELETE + fname="$(basename $option)" + if [ "$fname" = "PKGBUILD" ]; then + unset pkgname pkgver pkgrel options + source $option + else + pkgname=$1 + fi + + repo-remove "$pkgdb" "$pkgname" +fi + +exit 0 +# vim: set ts=2 sw=2 noet: |