From b5f8a44bebc906bf6a29d30c159802b0c1a7dbb1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 6 Jul 2007 18:43:24 -0400 Subject: Move scripts from *.in to *.sh.in so gettext can determine type If we move the scripts from *.in to *.sh.in and *.py.in, gettext can pull the required strings to translate a whole lot easier. Do this. Signed-off-by: Dan McGee --- scripts/Makefile.am | 44 +- scripts/abs.in | 175 ------ scripts/abs.sh.in | 175 ++++++ scripts/gensync.in | 159 ----- scripts/gensync.sh.in | 159 +++++ scripts/makepkg.in | 1334 ----------------------------------------- scripts/makepkg.sh.in | 1334 +++++++++++++++++++++++++++++++++++++++++ scripts/makeworld.in | 190 ------ scripts/makeworld.sh.in | 190 ++++++ scripts/pacman-optimize.in | 158 ----- scripts/pacman-optimize.sh.in | 158 +++++ scripts/rankmirrors.in | 179 ------ scripts/rankmirrors.py.in | 179 ++++++ scripts/repo-add.in | 317 ---------- scripts/repo-add.sh.in | 317 ++++++++++ scripts/repo-remove.in | 165 ----- scripts/repo-remove.sh.in | 165 +++++ scripts/updatesync.in | 161 ----- scripts/updatesync.sh.in | 161 +++++ 19 files changed, 2862 insertions(+), 2858 deletions(-) delete mode 100644 scripts/abs.in create mode 100644 scripts/abs.sh.in delete mode 100644 scripts/gensync.in create mode 100644 scripts/gensync.sh.in delete mode 100644 scripts/makepkg.in create mode 100644 scripts/makepkg.sh.in delete mode 100644 scripts/makeworld.in create mode 100644 scripts/makeworld.sh.in delete mode 100644 scripts/pacman-optimize.in create mode 100644 scripts/pacman-optimize.sh.in delete mode 100644 scripts/rankmirrors.in create mode 100644 scripts/rankmirrors.py.in delete mode 100644 scripts/repo-add.in create mode 100644 scripts/repo-add.sh.in delete mode 100644 scripts/repo-remove.in create mode 100644 scripts/repo-remove.sh.in delete mode 100644 scripts/updatesync.in create mode 100644 scripts/updatesync.sh.in (limited to 'scripts') diff --git a/scripts/Makefile.am b/scripts/Makefile.am index ba392fa9..01250f5b 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -16,15 +16,15 @@ bin_SCRIPTS += abs endif EXTRA_DIST = \ - abs.in \ - gensync.in \ - makepkg.in \ - makeworld.in \ - pacman-optimize.in \ - rankmirrors.in \ - repo-add.in \ - repo-remove.in \ - updatesync.in + 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 @@ -43,22 +43,26 @@ edit = sed \ ## 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 - $(edit) `test -f ./$@.in || echo $(srcdir)/`$@.in >$@.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.in -gensync: $(srcdir)/gensync.in -makepkg: $(srcdir)/makepkg.in -makeworld: $(srcdir)/makeworld.in -pacman-optimize: $(srcdir)/pacman-optimize.in -rankmirrors: $(srcdir)/rankmirrors.in -repo-add: $(srcdir)/repo-add.in -repo-remove: $(srcdir)/repo-remove.in -re-pacman: $(srcdir)/re-pacman.in -updatesync: $(srcdir)/updatesync.in +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.in b/scripts/abs.in deleted file mode 100644 index 491b965a..00000000 --- a/scripts/abs.in +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash -e -# -# abs - download a PKGBUILD tree from a CVS repository -# @configure_input@ -# -# Copyright (c) 2002-2007 by Judd Vinet -# -# 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 unknow/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" "$myver" - echo - printf "$(gettext "Usage %s [options] [repository...]")\n" "$0" - echo - 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" - printf "$(gettext "into %s. You can follow different package trees by")\n" "$ABSROOT" - printf "$(gettext "editing %s files. If no argument is given, abs")\n" "$CONFDIR/supfile.*" - printf "$(gettext "will synchronize from supfiles specified in %s.")\n" "$CONFDIR/abs.conf" - echo - 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 ").\n" - echo - printf "$(gettext "This is free software; see the source for copying conditions.")\n" - printf "$(gettext "There is NO WARRANTY, to the extent permitted by law.")\n" - echo -} - - -## -# 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 cvsup)" ]; then - CVSUP="cvsup" -elif [ "$(type -p csup)" ]; then - CVSUP="csup" -else - error "$(gettext "Missing CVS synchronization utility. Install cvsup or csup.")" - 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/abs.sh.in b/scripts/abs.sh.in new file mode 100644 index 00000000..491b965a --- /dev/null +++ b/scripts/abs.sh.in @@ -0,0 +1,175 @@ +#!/bin/bash -e +# +# abs - download a PKGBUILD tree from a CVS repository +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet +# +# 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 unknow/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" "$myver" + echo + printf "$(gettext "Usage %s [options] [repository...]")\n" "$0" + echo + 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" + printf "$(gettext "into %s. You can follow different package trees by")\n" "$ABSROOT" + printf "$(gettext "editing %s files. If no argument is given, abs")\n" "$CONFDIR/supfile.*" + printf "$(gettext "will synchronize from supfiles specified in %s.")\n" "$CONFDIR/abs.conf" + echo + 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 ").\n" + echo + printf "$(gettext "This is free software; see the source for copying conditions.")\n" + printf "$(gettext "There is NO WARRANTY, to the extent permitted by law.")\n" + echo +} + + +## +# 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 cvsup)" ]; then + CVSUP="cvsup" +elif [ "$(type -p csup)" ]; then + CVSUP="csup" +else + error "$(gettext "Missing CVS synchronization utility. Install cvsup or csup.")" + 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.in b/scripts/gensync.in deleted file mode 100644 index ca83c17b..00000000 --- a/scripts/gensync.in +++ /dev/null @@ -1,159 +0,0 @@ -#!/bin/bash -# -# gensync -# @configure_input@ -# -# Copyright (c) 2002-2007 by Judd Vinet -# -# 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" "$myver" - echo - printf "$(gettext "Usage: %s [package_directory]")\n" "$0" - echo - echo "$(gettext "gensync will generate a sync database by reading all PKGBUILD files")" - echo "$(gettext "from . gensync builds the database in a temporary directory")" - echo "$(gettext "and then compresses it to .")" - echo - echo "$(gettext "gensync will calculate md5sums of packages in the same directory as")" - echo "$(gettext ", unless an alternate [package_directory] is specified.")" - echo - echo "$(gettext "note: The name is important. It must be of the form")" - echo "$(gettext " {treename}.db.tar.gz where {treename} is the name of the custom")" - echo "$(gettext " package repository you configured in /etc/pacman.conf. The")" - echo "$(gettext " generated database must reside in the same directory as your")" - echo "$(gettext " custom packages (also configured in /etc/pacman.conf)")" - echo - echo "$(gettext "example: gensync /var/abs/local /home/mypkgs/custom.db.tar.gz")" - echo - exit 0 -} - -version() { - printf "gensync (pacman) %s\n" "$myver" - printf "Copyright (C) 2002-2007 Judd Vinet .\n" - echo - printf "This is free software; see the source for copying conditions.\n" - printf "There is NO WARRANTY, to the extent permitted by law.\n" - echo -} - -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 [ "$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/gensync.sh.in b/scripts/gensync.sh.in new file mode 100644 index 00000000..ca83c17b --- /dev/null +++ b/scripts/gensync.sh.in @@ -0,0 +1,159 @@ +#!/bin/bash +# +# gensync +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet +# +# 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" "$myver" + echo + printf "$(gettext "Usage: %s [package_directory]")\n" "$0" + echo + echo "$(gettext "gensync will generate a sync database by reading all PKGBUILD files")" + echo "$(gettext "from . gensync builds the database in a temporary directory")" + echo "$(gettext "and then compresses it to .")" + echo + echo "$(gettext "gensync will calculate md5sums of packages in the same directory as")" + echo "$(gettext ", unless an alternate [package_directory] is specified.")" + echo + echo "$(gettext "note: The name is important. It must be of the form")" + echo "$(gettext " {treename}.db.tar.gz where {treename} is the name of the custom")" + echo "$(gettext " package repository you configured in /etc/pacman.conf. The")" + echo "$(gettext " generated database must reside in the same directory as your")" + echo "$(gettext " custom packages (also configured in /etc/pacman.conf)")" + echo + echo "$(gettext "example: gensync /var/abs/local /home/mypkgs/custom.db.tar.gz")" + echo + exit 0 +} + +version() { + printf "gensync (pacman) %s\n" "$myver" + printf "Copyright (C) 2002-2007 Judd Vinet .\n" + echo + printf "This is free software; see the source for copying conditions.\n" + printf "There is NO WARRANTY, to the extent permitted by law.\n" + echo +} + +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 [ "$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.in b/scripts/makepkg.in deleted file mode 100644 index 8be44c65..00000000 --- a/scripts/makepkg.in +++ /dev/null @@ -1,1334 +0,0 @@ -#!/bin/bash -e -# -# makepkg - make packages compatable for use with pacman -# @configure_input@ -# -# Copyright (c) 2002-2007 by Judd Vinet -# Copyright (c) 2005 by Aurelien Foret -# Copyright (c) 2006 by Miklos Vajna -# Copyright (c) 2005 by Christian Hamar -# Copyright (c) 2006 by Alex Smith -# Copyright (c) 2006 by Andras Voroskoi -# -# 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@' -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 - -PACMAN_OPTS= - -### SUBROUTINES ### - -plain() { - local mesg=$1; shift - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - printf "\033[1;37m ${mesg}\033[0m\n" "$@" >&2 - else - printf " ${mesg}\n" "$@" >&2 - fi -} - -msg() { - local mesg=$1; shift - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - printf "\033[1;32m==>\033[1;37m ${mesg}\033[0m\n" "$@" >&2 - else - printf "==> ${mesg}\n" "$@" >&2 - fi -} - -msg2() { - local mesg=$1; shift - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - printf "\033[1;34m ->\033[1;37m ${mesg}\033[0m\n" "$@" >&2 - else - printf " -> ${mesg}\n" "$@" >&2 - fi -} - -warning() { - local mesg=$1; shift - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - printf "\033[1;33m==> $(gettext "WARNING:")\033[1;37m ${mesg}\033[0m\n" "$@" >&2 - else - printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 - fi -} - -error() { - local mesg=$1; shift - if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then - printf "\033[1;31m==> $(gettext "ERROR:")\033[1;37m ${mesg}\033[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 1 ]; 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 $striplist || ret=$? - else - pacman $PACMAN_OPTS -S $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 -Rs $deplist - else - pacman $PACMAN_OPTS -Rs $deplist - fi -} - -download_sources() { - msg "$(gettext "Retrieving Sources...")" - local netfile - for netfile in ${source[@]}; do - local file=$(strip_url "$netfile") - if [ -f "../$file" ]; then - msg2 "$(gettext "Found %s in build dir")" "$file" - cp "../$file" . - continue - elif [ -f "$SRCDEST/$file" ]; then - msg2 "$(gettext "Using cached copy of %s")" "$file" - cp "$SRCDEST/$file" . - 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 - - if [ -n "$SRCDEST" ]; then - mkdir -p "$SRCDEST" && cp "$file" "$SRCDEST" || ret=$? - if [ $ret -gt 0 ]; then - warning "$(gettext "You do not have correct permissions to cache source in %s")" "$SRCDEST" - cp "$file" .. - fi - else - cp "$file" .. - fi - done -} - -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")" - 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 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 - - # fix flyspray #6246 - local file_type=$(file -biz "$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 - - 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 {,*/}{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=$(LC_ALL= LANG= date -u "+%a %b %e %H:%M:%S %Y") - 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 "${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 "$oldfile" .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" - - # 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" - - # 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")" - xdelta patch "$delta_file" "$base_file" "$pkg_file" - 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 -} - -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 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 "$(gettext "makepkg (pacman) %s")\n" "$myver" - echo "$(gettext "Copyright (C) 2002-2007 Judd Vinet .")" - echo - echo "$(gettext "This is free software; see the source for copying conditions.")" - echo "$(gettext "There is NO WARRANTY, to the extent permitted by law.")" - echo -} - -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="bcCdefFghiLmop:rRsSV" -OPT_LONG="asroot,builddeps,clean,cleancache,nodeps,noextract,force,geninteg,help,install,log" -OPT_LONG="$OPT_LONG,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version" -# 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 ;; - -r|--rmdeps) RMDEPS=1 ;; - -R|--repackage) REPKG=1 ;; - --source) SOURCEONLY=1 ;; - -s|--syncdeps) DEP_BIN=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" ]; 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 - else - 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 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 ! 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 - -if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ - -a "$FORCE" = "0" -a "$GENINTEG" = "0" -a "$SOURCEONLY" = "0" ]; 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 bear 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 - 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 - run_build - tidy_install - fi - - create_package - else - msg "$(gettext "Entering fakeroot environment...")" - cd "$startdir" - - fakeroot -- $0 -F $ARGLIST || exit $? - 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/makepkg.sh.in b/scripts/makepkg.sh.in new file mode 100644 index 00000000..8be44c65 --- /dev/null +++ b/scripts/makepkg.sh.in @@ -0,0 +1,1334 @@ +#!/bin/bash -e +# +# makepkg - make packages compatable for use with pacman +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet +# Copyright (c) 2005 by Aurelien Foret +# Copyright (c) 2006 by Miklos Vajna +# Copyright (c) 2005 by Christian Hamar +# Copyright (c) 2006 by Alex Smith +# Copyright (c) 2006 by Andras Voroskoi +# +# 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@' +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 + +PACMAN_OPTS= + +### SUBROUTINES ### + +plain() { + local mesg=$1; shift + if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;37m ${mesg}\033[0m\n" "$@" >&2 + else + printf " ${mesg}\n" "$@" >&2 + fi +} + +msg() { + local mesg=$1; shift + if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;32m==>\033[1;37m ${mesg}\033[0m\n" "$@" >&2 + else + printf "==> ${mesg}\n" "$@" >&2 + fi +} + +msg2() { + local mesg=$1; shift + if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;34m ->\033[1;37m ${mesg}\033[0m\n" "$@" >&2 + else + printf " -> ${mesg}\n" "$@" >&2 + fi +} + +warning() { + local mesg=$1; shift + if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;33m==> $(gettext "WARNING:")\033[1;37m ${mesg}\033[0m\n" "$@" >&2 + else + printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 + fi +} + +error() { + local mesg=$1; shift + if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then + printf "\033[1;31m==> $(gettext "ERROR:")\033[1;37m ${mesg}\033[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 1 ]; 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 $striplist || ret=$? + else + pacman $PACMAN_OPTS -S $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 -Rs $deplist + else + pacman $PACMAN_OPTS -Rs $deplist + fi +} + +download_sources() { + msg "$(gettext "Retrieving Sources...")" + local netfile + for netfile in ${source[@]}; do + local file=$(strip_url "$netfile") + if [ -f "../$file" ]; then + msg2 "$(gettext "Found %s in build dir")" "$file" + cp "../$file" . + continue + elif [ -f "$SRCDEST/$file" ]; then + msg2 "$(gettext "Using cached copy of %s")" "$file" + cp "$SRCDEST/$file" . + 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 + + if [ -n "$SRCDEST" ]; then + mkdir -p "$SRCDEST" && cp "$file" "$SRCDEST" || ret=$? + if [ $ret -gt 0 ]; then + warning "$(gettext "You do not have correct permissions to cache source in %s")" "$SRCDEST" + cp "$file" .. + fi + else + cp "$file" .. + fi + done +} + +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")" + 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 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 + + # fix flyspray #6246 + local file_type=$(file -biz "$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 + + 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 {,*/}{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=$(LC_ALL= LANG= date -u "+%a %b %e %H:%M:%S %Y") + 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 "${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 "$oldfile" .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" + + # 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" + + # 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")" + xdelta patch "$delta_file" "$base_file" "$pkg_file" + 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 +} + +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 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 "$(gettext "makepkg (pacman) %s")\n" "$myver" + echo "$(gettext "Copyright (C) 2002-2007 Judd Vinet .")" + echo + echo "$(gettext "This is free software; see the source for copying conditions.")" + echo "$(gettext "There is NO WARRANTY, to the extent permitted by law.")" + echo +} + +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="bcCdefFghiLmop:rRsSV" +OPT_LONG="asroot,builddeps,clean,cleancache,nodeps,noextract,force,geninteg,help,install,log" +OPT_LONG="$OPT_LONG,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version" +# 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 ;; + -r|--rmdeps) RMDEPS=1 ;; + -R|--repackage) REPKG=1 ;; + --source) SOURCEONLY=1 ;; + -s|--syncdeps) DEP_BIN=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" ]; 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 + else + 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 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 ! 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 + +if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ + -a "$FORCE" = "0" -a "$GENINTEG" = "0" -a "$SOURCEONLY" = "0" ]; 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 bear 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 + 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 + run_build + tidy_install + fi + + create_package + else + msg "$(gettext "Entering fakeroot environment...")" + cd "$startdir" + + fakeroot -- $0 -F $ARGLIST || exit $? + 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.in b/scripts/makeworld.in deleted file mode 100644 index 23976b5e..00000000 --- a/scripts/makeworld.in +++ /dev/null @@ -1,190 +0,0 @@ -#!/bin/bash -# -# makeworld -# @configure_input@ -# -# Copyright (c) 2002-2007 by Judd Vinet -# -# 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="@PACKAGE_VERSION@" -toplevel=$(pwd) - -usage() { - printf "makeworld (pacman) %s\n" "$myver" - echo "usage: $0 [options] [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 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)" -} - -version() { - printf "makeworld (pacman) %s\n" "$myver" - printf "Copyright (C) 2002-2007 Judd Vinet .\n" - echo - printf "This is free software; see the source for copying conditions.\n" - printf "There is NO WARRANTY, to the extent permitted by law.\n" - echo -} - -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/makeworld.sh.in b/scripts/makeworld.sh.in new file mode 100644 index 00000000..23976b5e --- /dev/null +++ b/scripts/makeworld.sh.in @@ -0,0 +1,190 @@ +#!/bin/bash +# +# makeworld +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet +# +# 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="@PACKAGE_VERSION@" +toplevel=$(pwd) + +usage() { + printf "makeworld (pacman) %s\n" "$myver" + echo "usage: $0 [options] [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 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)" +} + +version() { + printf "makeworld (pacman) %s\n" "$myver" + printf "Copyright (C) 2002-2007 Judd Vinet .\n" + echo + printf "This is free software; see the source for copying conditions.\n" + printf "There is NO WARRANTY, to the extent permitted by law.\n" + echo +} + +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.in b/scripts/pacman-optimize.in deleted file mode 100644 index d4c926d8..00000000 --- a/scripts/pacman-optimize.in +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/bash -# -# pacman-optimize -# @configure_input@ -# -# Copyright (c) 2002-2007 by Judd Vinet -# -# 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" "$myver" - echo - printf "$(gettext "Usage: %s[pacman_db_root]")\n" "$0" - echo - echo "$(gettext "pacman-optimize is a little hack that should improve the performance")" - echo "$(gettext "of pacman when reading/writing to its filesystem-based database.")" - echo - echo "$(gettext "Because pacman uses many small files to keep track of packages,")" - echo "$(gettext "there is a tendency for these files to become fragmented over time.")" - echo "$(gettext "This script attempts to relocate these small files into one")" - echo "$(gettext "continuous location on your hard drive. The result is that the hard")" - echo "$(gettext "drive should be able to read them faster, since the hard drive head")" - echo "$(gettext "does not have to move around the disk as much.")" - echo -} - -version() { - printf "pacman-optimize (pacman) %s\n" "$myver" - printf "Copyright (C) 2002-2007 Judd Vinet .\n" - echo - printf "This is free software; see the source for copying conditions.\n" - printf "There is NO WARRANTY, to the extent permitted by law.\n" - echo -} - -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 pacman isn't running -if [ -f $lockfile ]; then - die "$(gettext "Pacman lockfile 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 - -# 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 > /tmp/pacsums.old - -# step 2: tar it up -msg "$(gettext "Tar'ing up %s...")" "$dbroot" -cd $dbroot -tar -czf /tmp/pacmanDB.tgz ./ -if [ $? -ne 0 ]; then - rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old - 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 -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 "$(gettext "Untar'ing $dbroot failed.")" -fi -find "$dbroot.new" -type f | sort | sed -e 's/pacman.new/pacman/g' | \ - xargs md5sum > /tmp/pacsums.new - -# step 4: compare the sums -msg "$(gettext "Checking integrity...")" -diff /tmp/pacsums.old /tmp/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" $lockfile /tmp/pacmanDB.tgz - 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"/* -tar -zxpf /tmp/pacmanDB.tgz -C "$dbroot"/ - -# remove the lock file, sum files, and .tgz of database -rm -f $lockfile /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz - -echo -echo "$(gettext "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..d4c926d8 --- /dev/null +++ b/scripts/pacman-optimize.sh.in @@ -0,0 +1,158 @@ +#!/bin/bash +# +# pacman-optimize +# @configure_input@ +# +# Copyright (c) 2002-2007 by Judd Vinet +# +# 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" "$myver" + echo + printf "$(gettext "Usage: %s[pacman_db_root]")\n" "$0" + echo + echo "$(gettext "pacman-optimize is a little hack that should improve the performance")" + echo "$(gettext "of pacman when reading/writing to its filesystem-based database.")" + echo + echo "$(gettext "Because pacman uses many small files to keep track of packages,")" + echo "$(gettext "there is a tendency for these files to become fragmented over time.")" + echo "$(gettext "This script attempts to relocate these small files into one")" + echo "$(gettext "continuous location on your hard drive. The result is that the hard")" + echo "$(gettext "drive should be able to read them faster, since the hard drive head")" + echo "$(gettext "does not have to move around the disk as much.")" + echo +} + +version() { + printf "pacman-optimize (pacman) %s\n" "$myver" + printf "Copyright (C) 2002-2007 Judd Vinet .\n" + echo + printf "This is free software; see the source for copying conditions.\n" + printf "There is NO WARRANTY, to the extent permitted by law.\n" + echo +} + +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 pacman isn't running +if [ -f $lockfile ]; then + die "$(gettext "Pacman lockfile 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 + +# 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 > /tmp/pacsums.old + +# step 2: tar it up +msg "$(gettext "Tar'ing up %s...")" "$dbroot" +cd $dbroot +tar -czf /tmp/pacmanDB.tgz ./ +if [ $? -ne 0 ]; then + rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old + 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 +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 "$(gettext "Untar'ing $dbroot failed.")" +fi +find "$dbroot.new" -type f | sort | sed -e 's/pacman.new/pacman/g' | \ + xargs md5sum > /tmp/pacsums.new + +# step 4: compare the sums +msg "$(gettext "Checking integrity...")" +diff /tmp/pacsums.old /tmp/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" $lockfile /tmp/pacmanDB.tgz + 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"/* +tar -zxpf /tmp/pacmanDB.tgz -C "$dbroot"/ + +# remove the lock file, sum files, and .tgz of database +rm -f $lockfile /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz + +echo +echo "$(gettext "Finished. Your pacman database has been optimized.")" +echo + +exit 0 + +# vim: set ts=2 sw=2 noet: diff --git a/scripts/rankmirrors.in b/scripts/rankmirrors.in deleted file mode 100644 index 2b284efe..00000000 --- a/scripts/rankmirrors.in +++ /dev/null @@ -1,179 +0,0 @@ -#! /usr/bin/python -# -# rankmirrors - read a list of mirrors from a file and rank them by speed -# @configure_input@ -# -# Original Idea copyright (c) 2006 R.G. -# Modified 2006 by Dan McGee -# -# 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. -# -import os, sys, datetime, time, socket, urllib2 -from optparse import OptionParser - -def createOptParser(): - usage = "usage: %prog [options] MIRRORFILE | URL" - version = '%prog (pacman) @PACKAGE_VERSION@' - 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, 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", - dest = "times", default = False, - help = "only output mirrors and their response times") - parser.add_option("-u", "--url", action = "store_true", dest = "url", - default = False, help = "test a specific url") - 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): - before = time.time() - try: - cmd() - except KeyboardInterrupt, ki: - raise ki - except socket.timeout, ioe: - return 'timeout' - except Exception, e: - return 'unreachable' - return time.time() - before - -def talkToServer(serverUrl): - opener = urllib2.build_opener() - # retrieve first 50,000 bytes only - tmp = opener.open(serverUrl).read(50000) - -def getFuncToTime(serverUrl): - return lambda : talkToServer(serverUrl) - -def cmpPairBySecond(p1, p2): - if p1[1] == p2[1]: - return 0 - if p1[1] < p2[1]: - return -1 - return 1 - -def printResults(servers, time, verbose, num): - items = servers.items() - items.sort(cmpPairBySecond) - itemsLen = len(items) - numToShow = num - if numToShow > itemsLen or numToShow == 0: - numToShow = itemsLen - if itemsLen > 0: - if time: - print - print ' Servers sorted by time (seconds):' - for i in items[0:numToShow]: - if i[1] == 'timeout' or i[1] == 'unreachable': - print i[0], ':', i[1] - else: - print i[0], ':', "%.2f" % i[1] - else: - for i in items[0:numToShow]: - print 'Server =', i[0] - -if __name__ == "__main__": - parser = createOptParser() - (options, args) = parser.parse_args() - - if len(args) != 1: - parser.print_help(sys.stderr) - sys.exit(0) - - # allows connections to time out if they take too long - socket.setdefaulttimeout(10) - - if options.url: - if options.verbose: - print 'Testing', args[0] + '...' - try: - serverToTime = timeCmd(getFuncToTime(args[0])) - except KeyboardInterrupt, ki: - sys.exit(1) - if serverToTime == 'timeout' or serverToTime == 'unreachable': - print args[0], ':', serverToTime - else: - print args[0], ':', "%.2f" % serverToTime - sys.exit(0) - - if not os.path.isfile(args[0]): - print >>sys.stderr, 'rankmirrors: file', args[0], 'does not exist.' - sys.exit(1) - - fl = open(args[0], 'r') - serverToTime = {} - if options.times: - print 'Querying servers, this may take some time...' - else: - print "# Server list generated by rankmirrors on", - print datetime.date.today() - for ln in fl.readlines(): - splitted = ln.split('=') - if splitted[0].strip() != 'Server': - if not options.times: - print ln, - continue - - serverUrl = splitted[1].strip() - if serverUrl[-1] == '\n': - serverUrl = serverUrl[0:-1] - if options.verbose and options.times: - print serverUrl, '...', - elif options.verbose: - print '#', serverUrl, '...', - elif options.times: - print ' * ', - sys.stdout.flush() - - # 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] != '/': - repoName = splitted2[-3] - dbFileName = '/' + repoName + '.db.tar.gz' - else: - repoName = splitted2[-4] - dbFileName = repoName + '.db.tar.gz' - except: - dbFileName = '' - - try: - serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl + dbFileName)) - if options.verbose: - try: - print "%.2f" % serverToTime[serverUrl] - except: - print serverToTime[serverUrl] - except: - print - printResults(serverToTime, options.times, options.verbose, - options.num) - sys.exit(0) - - printResults(serverToTime, options.times, options.verbose, options.num) - -# vim: set ts=4 sw=4 et: diff --git a/scripts/rankmirrors.py.in b/scripts/rankmirrors.py.in new file mode 100644 index 00000000..2b284efe --- /dev/null +++ b/scripts/rankmirrors.py.in @@ -0,0 +1,179 @@ +#! /usr/bin/python +# +# rankmirrors - read a list of mirrors from a file and rank them by speed +# @configure_input@ +# +# Original Idea copyright (c) 2006 R.G. +# Modified 2006 by Dan McGee +# +# 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. +# +import os, sys, datetime, time, socket, urllib2 +from optparse import OptionParser + +def createOptParser(): + usage = "usage: %prog [options] MIRRORFILE | URL" + version = '%prog (pacman) @PACKAGE_VERSION@' + 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, 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", + dest = "times", default = False, + help = "only output mirrors and their response times") + parser.add_option("-u", "--url", action = "store_true", dest = "url", + default = False, help = "test a specific url") + 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): + before = time.time() + try: + cmd() + except KeyboardInterrupt, ki: + raise ki + except socket.timeout, ioe: + return 'timeout' + except Exception, e: + return 'unreachable' + return time.time() - before + +def talkToServer(serverUrl): + opener = urllib2.build_opener() + # retrieve first 50,000 bytes only + tmp = opener.open(serverUrl).read(50000) + +def getFuncToTime(serverUrl): + return lambda : talkToServer(serverUrl) + +def cmpPairBySecond(p1, p2): + if p1[1] == p2[1]: + return 0 + if p1[1] < p2[1]: + return -1 + return 1 + +def printResults(servers, time, verbose, num): + items = servers.items() + items.sort(cmpPairBySecond) + itemsLen = len(items) + numToShow = num + if numToShow > itemsLen or numToShow == 0: + numToShow = itemsLen + if itemsLen > 0: + if time: + print + print ' Servers sorted by time (seconds):' + for i in items[0:numToShow]: + if i[1] == 'timeout' or i[1] == 'unreachable': + print i[0], ':', i[1] + else: + print i[0], ':', "%.2f" % i[1] + else: + for i in items[0:numToShow]: + print 'Server =', i[0] + +if __name__ == "__main__": + parser = createOptParser() + (options, args) = parser.parse_args() + + if len(args) != 1: + parser.print_help(sys.stderr) + sys.exit(0) + + # allows connections to time out if they take too long + socket.setdefaulttimeout(10) + + if options.url: + if options.verbose: + print 'Testing', args[0] + '...' + try: + serverToTime = timeCmd(getFuncToTime(args[0])) + except KeyboardInterrupt, ki: + sys.exit(1) + if serverToTime == 'timeout' or serverToTime == 'unreachable': + print args[0], ':', serverToTime + else: + print args[0], ':', "%.2f" % serverToTime + sys.exit(0) + + if not os.path.isfile(args[0]): + print >>sys.stderr, 'rankmirrors: file', args[0], 'does not exist.' + sys.exit(1) + + fl = open(args[0], 'r') + serverToTime = {} + if options.times: + print 'Querying servers, this may take some time...' + else: + print "# Server list generated by rankmirrors on", + print datetime.date.today() + for ln in fl.readlines(): + splitted = ln.split('=') + if splitted[0].strip() != 'Server': + if not options.times: + print ln, + continue + + serverUrl = splitted[1].strip() + if serverUrl[-1] == '\n': + serverUrl = serverUrl[0:-1] + if options.verbose and options.times: + print serverUrl, '...', + elif options.verbose: + print '#', serverUrl, '...', + elif options.times: + print ' * ', + sys.stdout.flush() + + # 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] != '/': + repoName = splitted2[-3] + dbFileName = '/' + repoName + '.db.tar.gz' + else: + repoName = splitted2[-4] + dbFileName = repoName + '.db.tar.gz' + except: + dbFileName = '' + + try: + serverToTime[serverUrl] = timeCmd(getFuncToTime(serverUrl + dbFileName)) + if options.verbose: + try: + print "%.2f" % serverToTime[serverUrl] + except: + print serverToTime[serverUrl] + except: + print + printResults(serverToTime, options.times, options.verbose, + options.num) + sys.exit(0) + + printResults(serverToTime, options.times, options.verbose, options.num) + +# vim: set ts=4 sw=4 et: diff --git a/scripts/repo-add.in b/scripts/repo-add.in deleted file mode 100644 index 3f009af8..00000000 --- a/scripts/repo-add.in +++ /dev/null @@ -1,317 +0,0 @@ -#!/bin/bash -# -# repo-add - add a package to a given repo database file -# @configure_input@ -# -# Copyright (c) 2006 Aaron Griffin -# -# 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@' - -FORCE=0 -REPO_DB_FILE="" -TMP_DIR="" - -# print usage instructions -usage() { - printf "repo-add (pacman) %s\n" "$myver" - echo - echo "$(gettext "usage: repo-add [--force] ...")" - echo - echo "$(gettext "repo-add will update a package database by reading a package file.")" - echo "$(gettext "Multiple packages to add can be specified on the command line.")" - echo - echo "$(gettext "The --force flag will add a 'force' entry to the sync database, which")" - echo "$(gettext "tells pacman to skip its internal version number checking and update")" - echo "$(gettext "the package regardless.")" - echo - echo "$(gettext "Example:")" - echo "$(gettext " repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")" - echo -} - -version() { - printf "repo-add (pacman) %s\n" "$myver" - printf "Copyright (C) 2006 Aaron Griffin .\n" - echo - printf "This is free software; see the source for copying conditions.\n" - printf "There is NO WARRANTY, to the extent permitted by law.\n" - 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 -L $pkgfile | cut -f1)" - - cd $gstmpdir - - # ensure $pkgname and $pkgver variables were found - if [ -z "$pkgname" -o -z "$pkgver" ]; then - echo "$(gettext " 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 "$(gettext ":: removing existing package '%s'")" $existing - rm -rf $existing - fi - done - - # create package directory - mkdir "$pkgname-$pkgver" - cd "$pkgname-$pkgver" - - # create desc entry - echo "$(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 - 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 "$(gettext ":: computing %s checksums")" $name - 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 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 @sysconfdir@/makepkg.conf ]; then - source @sysconfdir@/makepkg.conf -else - echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2 - exit 1 # $E_CONFIG_ERROR -fi - -if [ -r ~/.makepkg.conf ]; then - source ~/.makepkg.conf -fi - -# main routine -if [ $# -gt 1 ]; then - gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ - echo "$(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 - echo "$(gettext "error: repository file '%s' is not a proper pacman db")" $REPO_DB_FILE - exit 1 - elif [ -f "$REPO_DB_FILE" ]; then - echo "$(gettext ":: 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 "$(gettext "error: '%s' is not a package file, skipping")" $arg - else - echo "$(gettext ":: adding package '%s'")" $arg - - this_dir="$(pwd)" - if db_write_entry "$arg"; then - success=1 - fi - cd $this_dir - fi - else - echo "$(gettext "error: package '%s' not found")" $arg - fi - fi - done - - # if all operations were a success, rezip database - if [ "$success" = "1" ]; then - echo "$(gettext ":: creating updated database file %s")" ${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 "$(gettext "warning: no compression set")" - tar c * >$REPO_DB_FILE;; - esac - fi - else - echo "$(gettext ":: 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..3f009af8 --- /dev/null +++ b/scripts/repo-add.sh.in @@ -0,0 +1,317 @@ +#!/bin/bash +# +# repo-add - add a package to a given repo database file +# @configure_input@ +# +# Copyright (c) 2006 Aaron Griffin +# +# 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@' + +FORCE=0 +REPO_DB_FILE="" +TMP_DIR="" + +# print usage instructions +usage() { + printf "repo-add (pacman) %s\n" "$myver" + echo + echo "$(gettext "usage: repo-add [--force] ...")" + echo + echo "$(gettext "repo-add will update a package database by reading a package file.")" + echo "$(gettext "Multiple packages to add can be specified on the command line.")" + echo + echo "$(gettext "The --force flag will add a 'force' entry to the sync database, which")" + echo "$(gettext "tells pacman to skip its internal version number checking and update")" + echo "$(gettext "the package regardless.")" + echo + echo "$(gettext "Example:")" + echo "$(gettext " repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")" + echo +} + +version() { + printf "repo-add (pacman) %s\n" "$myver" + printf "Copyright (C) 2006 Aaron Griffin .\n" + echo + printf "This is free software; see the source for copying conditions.\n" + printf "There is NO WARRANTY, to the extent permitted by law.\n" + 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 -L $pkgfile | cut -f1)" + + cd $gstmpdir + + # ensure $pkgname and $pkgver variables were found + if [ -z "$pkgname" -o -z "$pkgver" ]; then + echo "$(gettext " 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 "$(gettext ":: removing existing package '%s'")" $existing + rm -rf $existing + fi + done + + # create package directory + mkdir "$pkgname-$pkgver" + cd "$pkgname-$pkgver" + + # create desc entry + echo "$(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 + 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 "$(gettext ":: computing %s checksums")" $name + 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 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 @sysconfdir@/makepkg.conf ]; then + source @sysconfdir@/makepkg.conf +else + echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2 + exit 1 # $E_CONFIG_ERROR +fi + +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# main routine +if [ $# -gt 1 ]; then + gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ + echo "$(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 + echo "$(gettext "error: repository file '%s' is not a proper pacman db")" $REPO_DB_FILE + exit 1 + elif [ -f "$REPO_DB_FILE" ]; then + echo "$(gettext ":: 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 "$(gettext "error: '%s' is not a package file, skipping")" $arg + else + echo "$(gettext ":: adding package '%s'")" $arg + + this_dir="$(pwd)" + if db_write_entry "$arg"; then + success=1 + fi + cd $this_dir + fi + else + echo "$(gettext "error: package '%s' not found")" $arg + fi + fi + done + + # if all operations were a success, rezip database + if [ "$success" = "1" ]; then + echo "$(gettext ":: creating updated database file %s")" ${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 "$(gettext "warning: no compression set")" + tar c * >$REPO_DB_FILE;; + esac + fi + else + echo "$(gettext ":: 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.in b/scripts/repo-remove.in deleted file mode 100644 index 02021f33..00000000 --- a/scripts/repo-remove.in +++ /dev/null @@ -1,165 +0,0 @@ -#!/bin/bash -# -# repo-remove - remove a package entry from a given repo database file -# @configure_input@ -# -# Copyright (c) 2007 Dan McGee -# -# 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@' - -FORCE=0 -REPO_DB_FILE="" -TMP_DIR="" - -# print usage instructions -usage() { - echo "$(gettext "repo-remove %s")" $myver - echo - echo "$(gettext "usage: repo-remove ...")" - echo - echo "$(gettext "repo-remove will update a package database by removing the package name")" - echo "$(gettext "specified on the command line from the given repo database. Multiple")" - echo "$(gettext "packages to remove can be specified on the command line.")" - echo - echo "$(gettext "Example:")" - echo "$(gettext " repo-remove /path/to/repo.db.tar.gz kernel26")" - echo -} - -version() { - printf "repo-remove (pacman) %s\n" "$myver" - printf "Copyright (C) 2007 Dan McGee .\n" - echo - printf "This is free software; see the source for copying conditions.\n" - printf "There is NO WARRANTY, to the extent permitted by law.\n" - 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 "$(gettext ":: removing existing package '%s'")" $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 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 @sysconfdir@/makepkg.conf ]; then - source @sysconfdir@/makepkg.conf -else - echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2 - exit 1 # $E_CONFIG_ERROR -fi - -if [ -r ~/.makepkg.conf ]; then - source ~/.makepkg.conf -fi - -# main routine -if [ $# -gt 1 ]; then - gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ - echo "$(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 - echo "$(gettext "error: repository file '%s' is not a proper pacman db")" $REPO_DB_FILE - exit 1 - elif [ -f "$REPO_DB_FILE" ]; then - echo "$(gettext ":: extracting database to a temporary location")" - tar xf "$REPO_DB_FILE" -C "$gstmpdir" - fi - else - echo "$(gettext ":: searching for package '%s'")" - - this_dir="$(pwd)" - if db_remove_entry "$arg"; then - success=1 - else - echo "$(gettext "error: package matching '%s' not found")" $arg - fi - cd $this_dir - fi - done - - # if all operations were a success, rezip database - if [ "$success" = "1" ]; then - echo "$(gettext ":: creating updated database file %s")" ${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 "$(gettext "warning: no compression set")" - tar c * >$REPO_DB_FILE;; - esac - fi - else - echo "$(gettext ":: 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..02021f33 --- /dev/null +++ b/scripts/repo-remove.sh.in @@ -0,0 +1,165 @@ +#!/bin/bash +# +# repo-remove - remove a package entry from a given repo database file +# @configure_input@ +# +# Copyright (c) 2007 Dan McGee +# +# 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@' + +FORCE=0 +REPO_DB_FILE="" +TMP_DIR="" + +# print usage instructions +usage() { + echo "$(gettext "repo-remove %s")" $myver + echo + echo "$(gettext "usage: repo-remove ...")" + echo + echo "$(gettext "repo-remove will update a package database by removing the package name")" + echo "$(gettext "specified on the command line from the given repo database. Multiple")" + echo "$(gettext "packages to remove can be specified on the command line.")" + echo + echo "$(gettext "Example:")" + echo "$(gettext " repo-remove /path/to/repo.db.tar.gz kernel26")" + echo +} + +version() { + printf "repo-remove (pacman) %s\n" "$myver" + printf "Copyright (C) 2007 Dan McGee .\n" + echo + printf "This is free software; see the source for copying conditions.\n" + printf "There is NO WARRANTY, to the extent permitted by law.\n" + 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 "$(gettext ":: removing existing package '%s'")" $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 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 @sysconfdir@/makepkg.conf ]; then + source @sysconfdir@/makepkg.conf +else + echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2 + exit 1 # $E_CONFIG_ERROR +fi + +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# main routine +if [ $# -gt 1 ]; then + gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\ + echo "$(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 + echo "$(gettext "error: repository file '%s' is not a proper pacman db")" $REPO_DB_FILE + exit 1 + elif [ -f "$REPO_DB_FILE" ]; then + echo "$(gettext ":: extracting database to a temporary location")" + tar xf "$REPO_DB_FILE" -C "$gstmpdir" + fi + else + echo "$(gettext ":: searching for package '%s'")" + + this_dir="$(pwd)" + if db_remove_entry "$arg"; then + success=1 + else + echo "$(gettext "error: package matching '%s' not found")" $arg + fi + cd $this_dir + fi + done + + # if all operations were a success, rezip database + if [ "$success" = "1" ]; then + echo "$(gettext ":: creating updated database file %s")" ${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 "$(gettext "warning: no compression set")" + tar c * >$REPO_DB_FILE;; + esac + fi + else + echo "$(gettext ":: 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/updatesync.in b/scripts/updatesync.in deleted file mode 100644 index 1526e285..00000000 --- a/scripts/updatesync.in +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/bash -# -# updatesync -# @configure_input@ -# -# Copyright (c) 2004 by Jason Chu -# Derived from gensync (c) 2002-2006 Judd Vinet -# -# 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" "$myver" - echo - printf "$(gettext "Usage: %s