]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/pc-sysinstall/backend/functions-installpackages.sh
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.sbin / pc-sysinstall / backend / functions-installpackages.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 # SUCH DAMAGE.
25 #
26 # $FreeBSD$
27
28 # Functions which check and load any optional packages specified in the config
29
30 . ${BACKEND}/functions.sh
31 . ${BACKEND}/functions-parse.sh
32
33 # Recursively determine all dependencies for this package
34 determine_package_dependencies()
35 {
36   local PKGNAME="${1}"
37   local DEPFILE="${2}"
38
39   grep -q "${PKGNAME}" "${DEPFILE}"
40   if [ $? -ne 0 ]
41   then
42     echo "${PKGNAME}" >> "${DEPFILE}"
43     get_package_dependencies "${PKGNAME}" "1"
44
45     local DEPS="${VAL}"
46     for d in ${DEPS}
47     do
48       determine_package_dependencies "${d}" "${DEPFILE}"
49     done
50   fi
51 };
52
53 # Fetch packages dependencies from a file
54 fetch_package_dependencies()
55 {
56   local DEPFILE
57   local DEPS
58   local SAVEDIR
59
60   DEPFILE="${1}"
61   DEPS=`cat "${DEPFILE}"`
62   SAVEDIR="${2}"
63
64   for d in ${DEPS}
65   do
66     get_package_short_name "${d}"
67     SNAME="${VAL}"
68
69     get_package_category "${SNAME}"
70     CATEGORY="${VAL}"
71
72     fetch_package "${CATEGORY}" "${d}" "${SAVEDIR}"
73   done
74 };
75
76 # Check for any packages specified, and begin loading them
77 install_packages()
78 {
79   # First, lets check and see if we even have any packages to install
80   get_value_from_cfg installPackages
81   if [ -n "${VAL}" ]
82   then
83     HERE=`pwd`
84     rc_nohalt "mkdir -p ${FSMNT}/${PKGTMPDIR}"
85     rc_nohalt "cd ${FSMNT}/${PKGTMPDIR}"
86
87     if [ ! -f "${CONFDIR}/INDEX" ]
88     then
89       get_package_index
90     fi
91
92     if [ ! -f "${CONFDIR}/INDEX.parsed" ]
93     then
94       parse_package_index
95     fi
96
97     # Lets start by cleaning up the string and getting it ready to parse
98     strip_white_space ${VAL}
99     PACKAGES=`echo ${VAL} | sed -e "s|,| |g"`
100     for i in $PACKAGES
101     do
102       if get_package_name "${i}"
103       then
104         PKGNAME="${VAL}"
105         DEPFILE="${FSMNT}/${PKGTMPDIR}/.${PKGNAME}.deps"
106
107         rc_nohalt "touch ${DEPFILE}"
108         determine_package_dependencies "${PKGNAME}" "${DEPFILE}"
109         fetch_package_dependencies "${DEPFILE}" "${FSMNT}/${PKGTMPDIR}"
110
111         # If the package is not already installed, install it!
112         if ! run_chroot_cmd "pkg_info -e ${PKGNAME}"
113         then
114           rc_nohalt "pkg_add -C ${FSMNT} ${PKGTMPDIR}/${PKGNAME}.tbz"
115         fi
116
117         rc_nohalt "rm ${DEPFILE}"
118       fi
119
120       rc_nohalt "cd ${HERE}"
121     done
122
123   rm -rf "${FSMNT}/${PKGTMPDIR}"
124   fi
125 };