diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh new file mode 100644 index 00000000000..a76167967e2 --- /dev/null +++ b/common/xbps-src/shutils/bulk.sh @@ -0,0 +1,78 @@ +# vim: set ts=4 sw=4 et: + +bulk_getlink() { + local p="$(basename $1)" + local target="$(readlink $XBPS_SRCPKGDIR/$p)" + + if [ $? -eq 0 -a -n "$target" ]; then + p=$target + fi + echo $p +} + +bulk_build() { + local args="$1" pkg= pkgs= _pkgs= _realdep= _deps= found= x= result= + + if ! command -v xbps-checkvers &>/dev/null; then + msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n" + fi + _pkgs=$(xbps-checkvers ${args} -d $XBPS_DISTDIR | awk '{print $2}') + # Only add to the list real pkgs, not subpkgs. + for pkg in ${_pkgs}; do + _realdep=$(bulk_getlink $pkg) + unset found + for x in ${pkgs}; do + if [ "$x" = "${_realdep}" ]; then + found=1 + break + fi + done + if [ -z "$found" ]; then + pkgs="$pkgs ${_realdep}" + fi + done + for pkg in ${pkgs}; do + unset found + setup_pkg $pkg $XBPS_CROSS_BUILD + _deps="$(show_pkg_build_deps | sed -e 's|[<>].*\$||g')" + _realdep=$(bulk_getlink $pkg) + for x in ${_deps}; do + if [ "${_realdep}" = "${pkg}" ]; then + found=1 + break + fi + done + [ -n $found ] && result="${_realdep} ${result}" + done + [ -n "$result" ] && echo "$result" +} + +bulk_update() { + local args="$1" pkgs= + + pkgs="$(bulk_build ${args})" + msg_normal "xbps-src: the following packages must be rebuilt and updated:\n" + for f in ${pkgs}; do + echo " $f" + done + echo + for f in ${pkgs}; do + BEGIN_INSTALL=1 + XBPS_TARGET_PKG="$f" + read_pkg + msg_normal "xbps-src: building ${pkgver} ...\n" + if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then + chroot_handler pkg $XBPS_TARGET_PKG + else + install_pkg pkg $XBPS_CROSS_BUILD + fi + if [ $? -ne 0 ]; then + msg_error "xbps-src: failed to build $pkgver pkg!\n" + fi + done + if [ -n "$pkgs" -a -n "$args" ]; then + echo + msg_normal "xbps-src: updating your system, confirm to proceed...\n" + ${XBPS_SUCMD} "xbps-install --repository=$XBPS_REPOSITORY --repository=$XBPS_REPOSITORY/nonfree -u ${pkgs}" + fi +} diff --git a/etc/defaults.conf b/etc/defaults.conf index bdc154c20c8..9412182d213 100644 --- a/etc/defaults.conf +++ b/etc/defaults.conf @@ -59,6 +59,12 @@ XBPS_CXXFLAGS="${XBPS_CFLAGS}" # XBPS_LDFLAGS="-Wl,--as-needed" +# [REQUIRED] +# Command to execute to gain root privileges when using the `update-sys` +# target to update your system. +# +XBPS_SUCMD="sudo /bin/sh -c" + # [OPTIONAL] # Enable or disable ccache when building packages. # diff --git a/xbps-src b/xbps-src index cedaf7670c4..5f28b3d823f 100755 --- a/xbps-src +++ b/xbps-src @@ -79,11 +79,17 @@ Targets: (only one may be specified) Prints the value of if it's defined in xbps-src. show-repo-updates - Prints the list of outdated packages in repositories. + Prints the list of outdated packages in XBPS repositories. show-sys-updates Prints the list of oudated packages in your system. + update-bulk + Rebuilds all packages in the system repositories that are outdated. + + update-sys + Rebuilds all packages in your system that are outdated and updates them. + zap Removes a masterdir but preserving ccache, distcc and host directories. @@ -479,53 +485,6 @@ check_build_requirements trap 'exit_func' INT TERM HUP -bulk_getlink() { - local p="$(basename $1)" - local target="$(readlink $XBPS_SRCPKGDIR/$p)" - - if [ $? -eq 0 -a -n "$target" ]; then - p=$target - fi - echo $p -} - -bulk_build() { - local args="$1" pkg= pkgs= _pkgs= _realdep= _deps= found= x= result= - - if ! command -v xbps-checkvers &>/dev/null; then - msg_error "xbps-src: cannot find xbps-{repo,}checkvers command!\n" - fi - _pkgs=$(xbps-checkvers ${args} -d $XBPS_DISTDIR | awk '{print $2}') - # Only add to the list real pkgs, not subpkgs. - for pkg in ${_pkgs}; do - _realdep=$(bulk_getlink $pkg) - unset found - for x in ${pkgs}; do - if [ "$x" = "${_realdep}" ]; then - found=1 - break - fi - done - if [ -z "$found" ]; then - pkgs="$pkgs ${_realdep}" - fi - done - for pkg in ${pkgs}; do - unset found - setup_pkg $pkg $XBPS_CROSS_BUILD - _deps="$(show_pkg_build_deps | sed -e 's|[<>].*\$||g')" - _realdep=$(bulk_getlink $pkg) - for x in ${_deps}; do - if [ "${_realdep}" = "${pkg}" ]; then - found=1 - break - fi - done - [ -n $found ] && result="${_realdep} ${result}" - done - echo "$result" -} - # # Main switch. # @@ -625,6 +584,12 @@ show-repo-updates) show-sys-updates) bulk_build -i ;; +update-bulk) + bulk_update + ;; +update-sys) + bulk_update -i + ;; zap) masterdir_zap ;;