2009-10-18 11:17:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2010-01-09 15:49:36 +01:00
|
|
|
# Copyright (c) 2008-2010 Juan Romero Pardines.
|
2009-10-18 11:17:26 +02:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
trap "echo && exit 1" INT QUIT
|
|
|
|
|
|
|
|
: ${XBPS_CONFIG_FILE:=@@XBPS_INSTALL_ETCDIR@@/xbps-src.conf}
|
|
|
|
|
|
|
|
: ${progname:=$(basename $0)}
|
|
|
|
: ${fakeroot_cmd:=fakeroot}
|
2010-01-16 02:11:44 +01:00
|
|
|
: ${fakeroot_cmd_args:=--}
|
|
|
|
: ${sudo_cmd:=sudo}
|
|
|
|
: ${chroot_cmd:=chroot}
|
2009-10-18 11:17:26 +02:00
|
|
|
: ${xbps_machine:=$(uname -m)}
|
2010-01-21 03:33:26 +01:00
|
|
|
: ${XBPS_UTILS_REQVER:=20100121}
|
2009-10-18 11:17:26 +02:00
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat << _EOF
|
2009-11-22 08:31:44 +01:00
|
|
|
$progname: [-C] [-c <config_file>] [-u] <target>
|
2009-10-18 11:17:26 +02:00
|
|
|
|
|
|
|
Targets:
|
2009-11-22 08:31:44 +01:00
|
|
|
build Build a package (fetch + extract + configure + build).
|
|
|
|
build-pkg [all] Build a binary package from <pkg>.
|
|
|
|
Package must be installed into destdir. If the <all>
|
|
|
|
keyword is used all packages currently installed will
|
|
|
|
be used.
|
|
|
|
chroot Enter to the chroot in masterdir.
|
|
|
|
configure Configure a package (fetch + extract + configure).
|
|
|
|
extract Extract distribution file(s) into build directory.
|
|
|
|
fetch Download distribution file(s).
|
|
|
|
info Show information for current pkg build template.
|
|
|
|
install-destdir build + install into destdir.
|
|
|
|
install install-destdir + stow.
|
|
|
|
list List installed packages in masterdir.
|
|
|
|
listfiles List installed files from <pkg>.
|
|
|
|
remove Remove package completely (destdir + masterdir).
|
|
|
|
stow Copy <pkg> files from destdir into masterdir and
|
|
|
|
register package in database.
|
|
|
|
unstow Remove <pkg> files from masterdir and unregister
|
|
|
|
package from database.
|
2009-10-18 11:17:26 +02:00
|
|
|
|
|
|
|
Options:
|
|
|
|
-C Do not remove build directory after successful installation.
|
|
|
|
-c Path to global configuration file:
|
|
|
|
if not specified @@XBPS_INSTALL_ETCDIR@@/xbps-src.conf is used.
|
|
|
|
_EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2009-11-22 08:31:44 +01:00
|
|
|
basename_cwd()
|
|
|
|
{
|
|
|
|
echo $(basename $(pwd))
|
|
|
|
}
|
|
|
|
|
2009-10-18 11:17:26 +02:00
|
|
|
check_path()
|
|
|
|
{
|
|
|
|
eval local orig="$1"
|
|
|
|
|
|
|
|
case "$orig" in
|
|
|
|
/) ;;
|
|
|
|
/*) orig="${orig%/}" ;;
|
|
|
|
*) orig="$(pwd)/${orig%/}" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
path_fixed="$orig"
|
|
|
|
}
|
|
|
|
|
|
|
|
run_file()
|
|
|
|
{
|
|
|
|
local file="$1"
|
|
|
|
|
|
|
|
check_path "$file"
|
|
|
|
. $path_fixed
|
|
|
|
}
|
|
|
|
|
|
|
|
check_config_vars()
|
|
|
|
{
|
|
|
|
local cffound f
|
|
|
|
|
|
|
|
if [ -z "$config_file_specified" ]; then
|
|
|
|
config_file_paths="$XBPS_CONFIG_FILE ./etc/xbps-src.conf"
|
|
|
|
for f in $config_file_paths; do
|
|
|
|
[ -f $f ] && XBPS_CONFIG_FILE=$f && \
|
|
|
|
cffound=yes && break
|
|
|
|
done
|
|
|
|
[ -z "$cffound" ] && msg_error "cannot find a config file"
|
|
|
|
fi
|
|
|
|
|
|
|
|
run_file ${XBPS_CONFIG_FILE}
|
|
|
|
XBPS_CONFIG_FILE=$path_fixed
|
|
|
|
|
|
|
|
if [ ! -f "$XBPS_CONFIG_FILE" ]; then
|
|
|
|
msg_error "cannot find configuration file: $XBPS_CONFIG_FILE"
|
|
|
|
fi
|
|
|
|
|
2010-01-09 23:35:11 +01:00
|
|
|
local XBPS_VARS="XBPS_MASTERDIR XBPS_BUILDDIR XBPS_SRCDISTDIR"
|
2009-10-18 11:17:26 +02:00
|
|
|
for f in ${XBPS_VARS}; do
|
|
|
|
eval val="\$$f"
|
|
|
|
[ -z "$val" ] && msg_error "'$f' not set in configuration file"
|
|
|
|
|
|
|
|
if [ ! -d "$val" ]; then
|
|
|
|
mkdir "$val"
|
|
|
|
[ $? -ne 0 ] && msg_error "couldn't create '$f' directory"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2009-10-30 22:14:09 +01:00
|
|
|
export PATH="@@XBPS_INSTALL_PREFIX@@/sbin:$PATH"
|
2009-10-18 11:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# main()
|
|
|
|
#
|
2010-01-09 15:49:36 +01:00
|
|
|
while getopts "Cc:" opt; do
|
2009-10-18 11:17:26 +02:00
|
|
|
case $opt in
|
2010-01-09 15:49:36 +01:00
|
|
|
C) export dontrm_builddir=yes;;
|
2009-10-18 11:17:26 +02:00
|
|
|
c) config_file_specified=yes; XBPS_CONFIG_FILE="$OPTARG";;
|
|
|
|
--) shift; break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
[ $# -eq 0 -o $# -gt 2 ] && usage
|
|
|
|
|
|
|
|
target="$1"
|
|
|
|
if [ -z "$target" ]; then
|
|
|
|
echo "=> ERROR: missing target."
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check configuration vars before anyting else, and set defaults vars.
|
|
|
|
#
|
|
|
|
check_config_vars
|
2010-01-16 02:11:44 +01:00
|
|
|
. @@XBPS_INSTALL_SHAREDIR@@/shutils/init_funcs.sh
|
2009-10-18 11:17:26 +02:00
|
|
|
set_defvars
|
2010-01-16 02:11:44 +01:00
|
|
|
|
2009-10-18 11:17:26 +02:00
|
|
|
. $XBPS_SHUTILSDIR/common_funcs.sh
|
|
|
|
|
2010-01-16 02:11:44 +01:00
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
# disable sudo and fakeroot if uid==0
|
|
|
|
unset sudo_cmd
|
|
|
|
if [ -n "$in_chroot" ]; then
|
|
|
|
unset fakeroot_cmd
|
|
|
|
unset fakeroot_cmd_args
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$XBPS_USE_CAPCHROOT" ]; then
|
|
|
|
chroot_cmd="capchroot"
|
|
|
|
fi
|
|
|
|
|
2009-10-18 11:17:26 +02:00
|
|
|
# Main switch
|
|
|
|
case "$target" in
|
|
|
|
build|configure)
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $(basename_cwd)
|
2009-10-18 11:17:26 +02:00
|
|
|
|
|
|
|
if [ -z "$base_chroot" -a -z "$in_chroot" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/chroot.sh
|
2010-01-16 02:11:44 +01:00
|
|
|
xbps_chroot_handler $target $pkgname
|
2009-10-18 11:17:26 +02:00
|
|
|
else
|
|
|
|
. $XBPS_SHUTILSDIR/fetch_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
fetch_distfiles
|
2009-10-18 11:17:26 +02:00
|
|
|
if [ ! -f "$XBPS_EXTRACT_DONE" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/extract_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
extract_distfiles
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
if [ "$target" = "configure" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/configure_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
configure_src_phase
|
2009-10-18 11:17:26 +02:00
|
|
|
else
|
|
|
|
if [ ! -f "$XBPS_CONFIGURE_DONE" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/configure_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
configure_src_phase
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
. $XBPS_SHUTILSDIR/build_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
build_src_phase
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
build-pkg)
|
|
|
|
. $XBPS_SHUTILSDIR/make-binpkg.sh
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
|
|
|
if [ "$2" = "all" ]; then
|
|
|
|
for f in $($XBPS_BIN_CMD list|awk '{print $1}'); do
|
2009-10-30 22:14:09 +01:00
|
|
|
pkg=$(${XBPS_PKGDB_CMD} getpkgname $f)
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $pkg
|
|
|
|
if [ "${pkg}" = "${sourcepkg}" ]; then
|
|
|
|
xbps_make_binpkg
|
2009-10-20 10:49:41 +02:00
|
|
|
fi
|
2009-10-18 11:17:26 +02:00
|
|
|
done
|
|
|
|
else
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $(basename_cwd)
|
|
|
|
xbps_make_binpkg
|
2009-10-18 11:17:26 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
chroot)
|
|
|
|
. $XBPS_SHUTILSDIR/chroot.sh
|
|
|
|
xbps_chroot_handler chroot dummy
|
|
|
|
;;
|
|
|
|
extract|fetch|info)
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $(basename_cwd)
|
2009-10-18 11:17:26 +02:00
|
|
|
if [ "$target" = "info" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
info_tmpl
|
2009-10-18 11:17:26 +02:00
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
if [ "$target" = "fetch" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/fetch_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
fetch_distfiles $update_checksum
|
2009-10-18 11:17:26 +02:00
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
. $XBPS_SHUTILSDIR/extract_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
extract_distfiles
|
2009-10-18 11:17:26 +02:00
|
|
|
;;
|
|
|
|
install|install-destdir)
|
2010-01-16 02:11:44 +01:00
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
|
|
|
[ ! -r ./template ] && msg_error "missing build template file."
|
|
|
|
. ./template
|
|
|
|
|
2009-10-18 11:17:26 +02:00
|
|
|
[ "$target" = "install-destdir" ] && install_destdir_target=yes
|
2010-01-16 02:11:44 +01:00
|
|
|
if [ -z "$in_chroot" -a -z "$base_chroot" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/chroot.sh
|
|
|
|
xbps_chroot_handler install $(basename_cwd) \
|
|
|
|
$install_destdir_target $dontrm_builddir
|
|
|
|
else
|
|
|
|
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
|
|
|
|
setup_tmpl $(basename_cwd)
|
|
|
|
install_pkg $pkgname
|
|
|
|
fi
|
2009-10-18 11:17:26 +02:00
|
|
|
;;
|
|
|
|
list|listfiles)
|
|
|
|
if [ "$target" = "list" ]; then
|
|
|
|
$XBPS_BIN_CMD list
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
|
|
|
|
list_pkg_files $2
|
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $(basename_cwd)
|
|
|
|
remove_pkg
|
2009-10-18 11:17:26 +02:00
|
|
|
;;
|
|
|
|
stow)
|
|
|
|
stow_flag=yes
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $(basename_cwd)
|
2009-10-18 11:17:26 +02:00
|
|
|
. $XBPS_SHUTILSDIR/stow_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
stow_pkg_handler stow
|
2009-10-18 11:17:26 +02:00
|
|
|
;;
|
|
|
|
unstow)
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
setup_tmpl $(basename_cwd)
|
2009-10-18 11:17:26 +02:00
|
|
|
. $XBPS_SHUTILSDIR/stow_funcs.sh
|
2009-11-22 08:31:44 +01:00
|
|
|
stow_pkg_handler unstow
|
2009-10-18 11:17:26 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "=> ERROR: invalid target: $target."
|
|
|
|
usage
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Agur
|
|
|
|
exit $?
|