195d45410SDevin Teskeif [ ! "$_PACKAGES_MUSTHAVEPKG_SUBR" ]; then _PACKAGES_MUSTHAVEPKG_SUBR=1 295d45410SDevin Teske# 3c4ba6882SDevin Teske# Copyright (c) 2014-2016 Devin Teske 495d45410SDevin Teske# All rights reserved. 595d45410SDevin Teske# 695d45410SDevin Teske# Redistribution and use in source and binary forms, with or without 795d45410SDevin Teske# modification, are permitted provided that the following conditions 895d45410SDevin Teske# are met: 995d45410SDevin Teske# 1. Redistributions of source code must retain the above copyright 1095d45410SDevin Teske# notice, this list of conditions and the following disclaimer. 1195d45410SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 1295d45410SDevin Teske# notice, this list of conditions and the following disclaimer in the 1395d45410SDevin Teske# documentation and/or other materials provided with the distribution. 1495d45410SDevin Teske# 1595d45410SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1695d45410SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1795d45410SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1895d45410SDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1995d45410SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2095d45410SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2195d45410SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2295d45410SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2395d45410SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2495d45410SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2595d45410SDevin Teske# SUCH DAMAGE. 2695d45410SDevin Teske# 2795d45410SDevin Teske# 2895d45410SDevin Teske############################################################ INCLUDES 2995d45410SDevin Teske 3095d45410SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 3195d45410SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 3295d45410SDevin Teskef_dprintf "%s: loading includes..." packages/musthavepkg.subr 3395d45410SDevin Teskef_include $BSDCFG_SHARE/dialog.subr 3495d45410SDevin Teskef_include $BSDCFG_SHARE/mustberoot.subr 3595d45410SDevin Teske 3695d45410SDevin Teske############################################################ FUNCTIONS 3795d45410SDevin Teske 3895d45410SDevin Teske# f_musthavepkg_init 3995d45410SDevin Teske# 4095d45410SDevin Teske# Validate pkg(8) is installed and set $PKG_ABI global if not already set. 4195d45410SDevin Teske# Returns success unless pkg(8) is not installed and user refuses to install 4295d45410SDevin Teske# it (upon prompt when running interactively). 4395d45410SDevin Teske# 4495d45410SDevin Teskef_musthavepkg_init() 4595d45410SDevin Teske{ 4695d45410SDevin Teske local funcname=f_musthavepkg_init 4795d45410SDevin Teske 48*4ab01932SBaptiste Daroussin if f_quietly pkg -N; then 49*4ab01932SBaptiste Daroussin if [ -n "$PKG_ABI" ]; then 5095d45410SDevin Teske export PKG_ABI 5195d45410SDevin Teske return $SUCCESS 5295d45410SDevin Teske fi 53*4ab01932SBaptiste Daroussin if f_eval_catch -k PKG_ABI $funcname pkg "pkg config abi"; then 54*4ab01932SBaptiste Daroussin export PKG_ABI 55*4ab01932SBaptiste Daroussin return $SUCCESS 56*4ab01932SBaptiste Daroussin fi 57*4ab01932SBaptiste Daroussin fi 5895d45410SDevin Teske 5995d45410SDevin Teske # pkg(8) not yet bootstrapped; ask for permission unless nonInteractive 6095d45410SDevin Teske f_dialog_yesno "$msg_pkg_not_yet_installed_install_now" || 6195d45410SDevin Teske f_die 1 "$msg_must_have_pkg_to_execute" "$pgm" 6295d45410SDevin Teske 6395d45410SDevin Teske f_mustberoot_init # Have to be root to install pkg(8) 6495d45410SDevin Teske 6595d45410SDevin Teske # Bootstrap pkg(8) 6695d45410SDevin Teske f_dialog_info "$msg_bootstrapping_pkg" 67*4ab01932SBaptiste Daroussin f_eval_catch $funcname pkg \ 68*4ab01932SBaptiste Daroussin "pkg bootstrap -y" || 6995d45410SDevin Teske f_die 1 "$msg_must_have_pkg_to_execute" "$pgm" 70*4ab01932SBaptiste Daroussin f_eval_catch -k PKG_ABI $funcname pkg "pkg config abi" 7195d45410SDevin Teske f_dprintf "PKG_ABI=[%s]" "$PKG_ABI" 7295d45410SDevin Teske export PKG_ABI 7395d45410SDevin Teske return $SUCCESS 7495d45410SDevin Teske} 7595d45410SDevin Teske 7695d45410SDevin Teske############################################################ MAIN 7795d45410SDevin Teske 7895d45410SDevin Teskef_dprintf "%s: Successfully loaded." packages/musthavepkg.subr 7995d45410SDevin Teske 8095d45410SDevin Teskefi # ! $_PACKAGES_MUSTHAVEPKG_SUBR 81