1*95d45410SDevin Teskeif [ ! "$_PACKAGES_MUSTHAVEPKG_SUBR" ]; then _PACKAGES_MUSTHAVEPKG_SUBR=1 2*95d45410SDevin Teske# 3*95d45410SDevin Teske# Copyright (c) 2014 Devin Teske 4*95d45410SDevin Teske# All rights reserved. 5*95d45410SDevin Teske# 6*95d45410SDevin Teske# Redistribution and use in source and binary forms, with or without 7*95d45410SDevin Teske# modification, are permitted provided that the following conditions 8*95d45410SDevin Teske# are met: 9*95d45410SDevin Teske# 1. Redistributions of source code must retain the above copyright 10*95d45410SDevin Teske# notice, this list of conditions and the following disclaimer. 11*95d45410SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 12*95d45410SDevin Teske# notice, this list of conditions and the following disclaimer in the 13*95d45410SDevin Teske# documentation and/or other materials provided with the distribution. 14*95d45410SDevin Teske# 15*95d45410SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*95d45410SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*95d45410SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*95d45410SDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*95d45410SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*95d45410SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*95d45410SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*95d45410SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*95d45410SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*95d45410SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*95d45410SDevin Teske# SUCH DAMAGE. 26*95d45410SDevin Teske# 27*95d45410SDevin Teske# $FreeBSD$ 28*95d45410SDevin Teske# 29*95d45410SDevin Teske############################################################ INCLUDES 30*95d45410SDevin Teske 31*95d45410SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 32*95d45410SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 33*95d45410SDevin Teskef_dprintf "%s: loading includes..." packages/musthavepkg.subr 34*95d45410SDevin Teskef_include $BSDCFG_SHARE/dialog.subr 35*95d45410SDevin Teskef_include $BSDCFG_SHARE/mustberoot.subr 36*95d45410SDevin Teske 37*95d45410SDevin Teske############################################################ FUNCTIONS 38*95d45410SDevin Teske 39*95d45410SDevin Teske# f_musthavepkg_init 40*95d45410SDevin Teske# 41*95d45410SDevin Teske# Validate pkg(8) is installed and set $PKG_ABI global if not already set. 42*95d45410SDevin Teske# Returns success unless pkg(8) is not installed and user refuses to install 43*95d45410SDevin Teske# it (upon prompt when running interactively). 44*95d45410SDevin Teske# 45*95d45410SDevin Teskef_musthavepkg_init() 46*95d45410SDevin Teske{ 47*95d45410SDevin Teske local funcname=f_musthavepkg_init 48*95d45410SDevin Teske local pkg_abi_awk='$1~/^ABI/{print $NF; exit}' 49*95d45410SDevin Teske 50*95d45410SDevin Teske if [ "$PKG_ABI" ]; then # Already set 51*95d45410SDevin Teske f_dprintf "PKG_ABI=[%s]" "$PKG_ABI" 52*95d45410SDevin Teske export PKG_ABI 53*95d45410SDevin Teske f_quietly pkg -N -vv # return status (pkg(8) functional?) 54*95d45410SDevin Teske return $? 55*95d45410SDevin Teske fi 56*95d45410SDevin Teske 57*95d45410SDevin Teske # Attempt to get PKG_ABI without prematurely bootstrapping pkg(8) 58*95d45410SDevin Teske if f_eval_catch -k PKG_ABI $funcname pkg \ 59*95d45410SDevin Teske "pkg -N -vv | awk '%s'" "$pkg_abi_awk" 60*95d45410SDevin Teske then 61*95d45410SDevin Teske f_dprintf "PKG_ABI=[%s]" "$PKG_ABI" 62*95d45410SDevin Teske export PKG_ABI 63*95d45410SDevin Teske return $SUCCESS 64*95d45410SDevin Teske fi 65*95d45410SDevin Teske 66*95d45410SDevin Teske # pkg(8) not yet bootstrapped; ask for permission unless nonInteractive 67*95d45410SDevin Teske f_dialog_yesno "$msg_pkg_not_yet_installed_install_now" || 68*95d45410SDevin Teske f_die 1 "$msg_must_have_pkg_to_execute" "$pgm" 69*95d45410SDevin Teske 70*95d45410SDevin Teske f_mustberoot_init # Have to be root to install pkg(8) 71*95d45410SDevin Teske 72*95d45410SDevin Teske # Bootstrap pkg(8) 73*95d45410SDevin Teske f_dialog_info "$msg_bootstrapping_pkg" 74*95d45410SDevin Teske f_eval_catch -k PKG_ABI $funcname pkg \ 75*95d45410SDevin Teske "ASSUME_ALWAYS_YES=1 pkg -vv | awk '%s'" "$pkg_abi_awk" || 76*95d45410SDevin Teske f_die 1 "$msg_must_have_pkg_to_execute" "$pgm" 77*95d45410SDevin Teske 78*95d45410SDevin Teske f_dprintf "PKG_ABI=[%s]" "$PKG_ABI" 79*95d45410SDevin Teske export PKG_ABI 80*95d45410SDevin Teske return $SUCCESS 81*95d45410SDevin Teske} 82*95d45410SDevin Teske 83*95d45410SDevin Teske############################################################ MAIN 84*95d45410SDevin Teske 85*95d45410SDevin Teskef_dprintf "%s: Successfully loaded." packages/musthavepkg.subr 86*95d45410SDevin Teske 87*95d45410SDevin Teskefi # ! $_PACKAGES_MUSTHAVEPKG_SUBR 88