source: src-sh/pc-sysinstall/backend/functions-installpackages.sh

Last change on this file was bdf4cac, checked in by Kris Moore <kris@…>, 11 months ago

Improve pc-sysinstall for pkgng 1.2.x, when doing installations from
local media, we can avoid doing a "pkg install", since it does unnecessary
steps of copying the media from DVD -> DISK -> INSTALL. Instead we will
do a 'pkg rquery' to get the filename of the requested package, and
install it with 'pkg add' which will stream from the DVD/USB directly.

  • Property mode set to 100755
File size: 4.1 KB
Line 
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: head/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh 247734 2013-03-03 23:01:46Z jpaetzel $
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# Check for any packages specified, and begin loading them
34install_packages()
35{
36  echo "Checking for packages to install..."
37  sleep 2
38
39  # First, lets check and see if we even have any packages to install
40  get_value_from_cfg installPackages
41
42  # Nothing to do?
43  if [ -z "${VAL}" ]; then return; fi
44
45  echo "Installing packages..."
46  sleep 3
47
48  local PKGPTH
49
50  HERE=`pwd`
51  rc_halt "mkdir -p ${FSMNT}${PKGTMPDIR}"
52
53  # Determine the directory we will install packages from
54  get_package_location
55  rc_halt "cd ${PKGDLDIR}"
56
57  # We dont want to be bothered with scripts asking questions
58  PACKAGE_BUILDING=yes
59  export PACKAGE_BUILDING
60
61  # Install PKGNG into the chroot
62  bootstrap_pkgng
63
64  # Update the repo database
65  echo "Updating pkgng database"
66  case "${INSTALLMEDIUM}" in
67    usb|dvd|local) run_chroot_cmd "pkg -R /mnt/repo-installer update -f" ;;
68                *) run_chroot_cmd "pkg update -f" ;;
69  esac
70
71  # Lets start by cleaning up the string and getting it ready to parse
72  get_value_from_cfg_with_spaces installPackages
73  PACKAGES="${VAL}"
74  echo_log "Packages to install: `echo $PACKAGES | wc -w | awk '{print $1}'`"
75  for i in $PACKAGES
76  do
77    PKGNAME="${i}"
78
79    # When doing a pkg install, if on local media, use a pkg.conf from /dist/
80    if [ "${INSTALLMEDIUM}" != "ftp" ] ; then
81      # Get the package file-name
82      PKGFILENAME=""
83      PKGFILENAME=`chroot ${FSMNT} pkg -R /mnt/repo-installer rquery '%n-%v' ${PKGNAME}`
84      if [ -z "$PKGFILENAME" ] ; then
85         echo_log "Warning: No such package in repo: ${PKGNAME}"
86         sleep 2
87         continue
88      fi
89      if [ ! -e "${FSMNT}/mnt/All/${PKGFILENAME}.txz" ] ; then
90         echo_log "Warning: No such package file in repo: ${PKGFILENAME}"
91         sleep 2
92         continue
93      fi
94      PKGADD="pkg add /mnt/All/${PKGFILENAME}.txz"
95    else
96      # Doing a network install, use the default pkg.conf
97      PKGADD="pkg install -y ${PKGNAME}"
98    fi
99
100    PKGINFO="pkg info"
101
102    # If the package is not already installed, install it!
103    if ! run_chroot_cmd "${PKGINFO} -e ${PKGNAME}" >/dev/null 2>/dev/null
104    then
105      echo_log "Installing package: ${PKGNAME}"
106      run_chroot_cmd "$PKGADD" | tee -a ${LOGOUT}
107      run_chroot_cmd "rm -rf /usr/local/tmp/All"
108    fi
109  done
110
111  echo_log "Package installation complete!"
112
113  # Cleanup after ourselves
114  echo_log "Cleaning up: ${FSMNT}${PKGTMPDIR}"
115  sleep 1
116  rc_halt "cd ${HERE}"
117  if [ "${INSTALLMEDIUM}" != "ftp" ] ; then
118    rc_halt "umount ${FSMNT}/mnt" >/dev/null 2>/dev/null
119    rc_halt "rmdir ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null
120  fi
121};
Note: See TracBrowser for help on using the repository browser.