diff options
author | jpaetzel <jpaetzel@FreeBSD.org> | 2013-03-03 23:01:46 +0000 |
---|---|---|
committer | jpaetzel <jpaetzel@FreeBSD.org> | 2013-03-03 23:01:46 +0000 |
commit | 3da475a963077e2df4022d88c2fba553595f4e9b (patch) | |
tree | 6aa4ff315eb7f8728315569dc1f65aa1699a51c6 /usr.sbin/pc-sysinstall | |
parent | 8bb3da133f0682d6d4de1df7fcc02836faaddb68 (diff) | |
download | FreeBSD-src-3da475a963077e2df4022d88c2fba553595f4e9b.zip FreeBSD-src-3da475a963077e2df4022d88c2fba553595f4e9b.tar.gz |
Improves and enhances using the "installPackages=" variable.
Adds "pkgExt=" variable to set if pkgs are .tbz or .txz or other.
Auto-detects if packages are PKGNG or old PKG format.
Auto-bootstrap of PKGNG for the new installed environment.
Fixes issues with installing packages from local media, such as DVD/USB.
Switch to using a space-delimiter for installPackages, since a number
of packages use a "," in their version string.
Fix pc-sysinstall to ignore install scripts, and not hang on
user interaction prompts when installing pkgs.
Add pkg2ng command as apart of pkgng bootstrap process.
Obtained from: PC-BSD
Diffstat (limited to 'usr.sbin/pc-sysinstall')
-rwxr-xr-x | usr.sbin/pc-sysinstall/backend/functions-installpackages.sh | 131 | ||||
-rwxr-xr-x | usr.sbin/pc-sysinstall/backend/functions-packages.sh | 137 |
2 files changed, 185 insertions, 83 deletions
diff --git a/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh b/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh index 7572efb..c1a879a 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-installpackages.sh @@ -76,50 +76,113 @@ fetch_package_dependencies() # Check for any packages specified, and begin loading them install_packages() { + echo "Checking for packages to install..." + sleep 2 + # First, lets check and see if we even have any packages to install get_value_from_cfg installPackages - if [ -n "${VAL}" ] - then - HERE=`pwd` - rc_nohalt "mkdir -p ${FSMNT}/${PKGTMPDIR}" - rc_nohalt "cd ${FSMNT}/${PKGTMPDIR}" - if [ ! -f "${CONFDIR}/INDEX" ] + # Nothing to do? + if [ -z "${VAL}" ]; then return; fi + + echo "Installing packages..." + sleep 3 + + local PKGPTH + + HERE=`pwd` + rc_halt "mkdir -p ${FSMNT}${PKGTMPDIR}" + + # Determine the directory we will install packages from + get_package_location + rc_halt "cd ${PKGDLDIR}" + + # Set the location of the INDEXFILE + INDEXFILE="${TMPDIR}/INDEX" + + if [ ! -f "${INDEXFILE}" ]; then + get_package_index + fi + + if [ ! -f "${TMPDIR}/INDEX.parsed" -a "$INSTALLMEDIUM" = "ftp" ]; then + parse_package_index + fi + + # What extension are we using for pkgs? + PKGEXT="txz" + get_value_from_cfg pkgExt + if [ -n "${VAL}" ]; then + strip_white_space ${VAL} + PKGEXT="$VAL" + fi + export PKGEXT + + # We dont want to be bothered with scripts asking questions + PACKAGE_BUILDING=yes + export PACKAGE_BUILDING + + # Lets start by cleaning up the string and getting it ready to parse + get_value_from_cfg_with_spaces installPackages + PACKAGES="${VAL}" + echo_log "Packages to install: `echo $PACKAGES | wc -w | awk '{print $1}'`" + for i in $PACKAGES + do + if ! get_package_name "${i}" then - get_package_index + echo_log "Unable to locate package ${i}" + continue fi - if [ ! -f "${CONFDIR}/INDEX.parsed" ] - then - parse_package_index + PKGNAME="${VAL}" + + # Fetch package + deps, but skip if installing from local media + if [ "${INSTALLMEDIUM}" = "ftp" ] ; then + DEPFILE="${FSMNT}/${PKGTMPDIR}/.${PKGNAME}.deps" + rc_nohalt "touch ${DEPFILE}" + determine_package_dependencies "${PKGNAME}" "${DEPFILE}" + fetch_package_dependencies "${DEPFILE}" "${FSMNT}/${PKGTMPDIR}" fi - # Lets start by cleaning up the string and getting it ready to parse - strip_white_space ${VAL} - PACKAGES=`echo ${VAL} | sed -e "s|,| |g"` - for i in $PACKAGES - do - if get_package_name "${i}" - then - PKGNAME="${VAL}" - DEPFILE="${FSMNT}/${PKGTMPDIR}/.${PKGNAME}.deps" - - rc_nohalt "touch ${DEPFILE}" - determine_package_dependencies "${PKGNAME}" "${DEPFILE}" - fetch_package_dependencies "${DEPFILE}" "${FSMNT}/${PKGTMPDIR}" - - # If the package is not already installed, install it! - if ! run_chroot_cmd "pkg_info -e ${PKGNAME}" - then - rc_nohalt "pkg_add -C ${FSMNT} ${PKGTMPDIR}/${PKGNAME}.tbz" - fi - - rc_nohalt "rm ${DEPFILE}" + # Set package location + case "${INSTALLMEDIUM}" in + usb|dvd|local) PKGPTH="${PKGTMPDIR}/All/${PKGNAME}" ;; + *) PKGPTH="${PKGTMPDIR}/${PKGNAME}" ;; + esac + + # See if we need to determine the package format we are working with + if [ -z "${PKGINFO}" ] ; then + tar tqf "${FSMNT}${PKGPTH}" '+MANIFEST' >/dev/null 2>/dev/null + if [ $? -ne 0 ] ; then + PKGADD="pkg_add -C ${FSMNT}" + PKGINFO="pkg_info" + else + PKGADD="pkg -c ${FSMNT} add" + PKGINFO="pkg info" + bootstrap_pkgng fi + fi - rc_nohalt "cd ${HERE}" - done + # If the package is not already installed, install it! + if ! run_chroot_cmd "${PKGINFO} -e ${PKGNAME}" >/dev/null 2>/dev/null + then + echo_log "Installing package: ${PKGNAME}" + rc_nohalt "${PKGADD} ${PKGPTH}" + fi + + if [ "${INSTALLMEDIUM}" = "ftp" ] ; then + rc_nohalt "rm ${DEPFILE}" + fi + + done + + echo_log "Package installation complete!" - rm -rf "${FSMNT}/${PKGTMPDIR}" + # Cleanup after ourselves + rc_halt "cd ${HERE}" + if [ "${INSTALLMEDIUM}" = "ftp" ] ; then + rc_halt "rm -rf ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null + else + rc_halt "umount ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null + rc_halt "rmdir ${FSMNT}${PKGTMPDIR}" >/dev/null 2>/dev/null fi }; diff --git a/usr.sbin/pc-sysinstall/backend/functions-packages.sh b/usr.sbin/pc-sysinstall/backend/functions-packages.sh index c426778..ee41928 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-packages.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-packages.sh @@ -45,9 +45,11 @@ get_package_index_by_ftp() then INDEX_FILE="${INDEX_FILE}.bz2" USE_BZIP2=1 + INDEX_PATH="${INDEXFILE}.bz2" + else + INDEX_PATH="${INDEXFILE}" fi - INDEX_PATH="${CONFDIR}/${INDEX_FILE}" fetch_file "${FTP_SERVER}/${INDEX_FILE}" "${INDEX_PATH}" "1" if [ -f "${INDEX_PATH}" ] && [ "${USE_BZIP2}" -eq "1" ] then @@ -57,17 +59,18 @@ get_package_index_by_ftp() get_package_index_by_fs() { - local INDEX_FILE - - INDEX_FILE="${CDMNT}/packages/INDEX" - fetch_file "${INDEX_FILE}" "${CONFDIR}/" "0" + if [ "$INSTALLMEDIUM" = "local" ] ; then + INDEXFILE="${LOCALPATH}/packages/INDEX" + else + INDEXFILE="${CDMNT}/packages/INDEX" + fi }; get_package_index_size() { - if [ -f "${CONFDIR}/INDEX" ] + if [ -f "${INDEXFILE}" ] then - SIZE=`ls -l ${CONFDIR}/INDEX | awk '{ print $5 }'` + SIZE=`ls -l ${INDEXFILE} | awk '{ print $5 }'` else get_ftp_mirror FTPHOST="${VAL}" @@ -94,28 +97,24 @@ get_package_index() get_package_index_by_ftp "${FTPPATH}" else - get_value_from_cfg ftpHost - if [ -z "$VAL" ] - then - exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" - fi - - FTPHOST="${VAL}" - - get_value_from_cfg ftpDir - if [ -z "$VAL" ] - then - exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" - fi - - FTPDIR="${VAL}" - FTPPATH="ftp://${FTPHOST}${FTPDIR}" case "${INSTALLMEDIUM}" in - usb|dvd) get_package_index_by_fs ;; - ftp) get_package_index_by_ftp "${FTPPATH}" ;; - sftp) ;; - *) RES=1 ;; + usb|dvd|local) get_package_index_by_fs ;; + ftp) get_value_from_cfg ftpHost + if [ -z "$VAL" ]; then + exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" + fi + FTPHOST="${VAL}" + + get_value_from_cfg ftpDir + if [ -z "$VAL" ]; then + exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" + fi + FTPDIR="${VAL}" + FTPPATH="ftp://${FTPHOST}${FTPDIR}" + get_package_index_by_ftp "${FTPPATH}" ;; + sftp) ;; + *) RES=1 ;; esac fi @@ -125,10 +124,11 @@ get_package_index() parse_package_index() { + echo_log "Building package dep list.. Please wait.." INDEX_FILE="${PKGDIR}/INDEX" exec 3<&0 - exec 0<"${INDEX_FILE}" + exec 0<"${INDEXFILE}" while read -r line do @@ -257,20 +257,38 @@ get_package_name() { PACKAGE="${1}" RES=0 + local PKGPTH - INDEX_FILE="${PKGDIR}/INDEX.deps" - REGEX="^${PACKAGE}|" + # If we are on a local medium, we can parse the Latest/ directory + if [ "${INSTALLMEDIUM}" != "ftp" ] ; then + case "${INSTALLMEDIUM}" in + usb|dvd) PKGPTH="${CDMNT}/packages" ;; + *) PKGPTH="${LOCALPATH}/packages" ;; + esac + + # Check the /Latest dir for generic names, then look for specific version in All/ + if [ -e "${PKGPTH}/Latest/${PACKAGE}.${PKGEXT}" ] ; then + NAME=`ls -al ${PKGPTH}/Latest/${PACKAGE}.${PKGEXT} 2>/dev/null | cut -d '>' -f 2 | rev | cut -f1 -d'/' | rev | tr -s ' '` + else + NAME=`ls -al ${PKGPTH}/All/${PACKAGE}.${PKGEXT} 2>/dev/null | cut -d '>' -f 2 | rev | cut -f1 -d'/' | rev | tr -s ' '` + fi + export VAL="${NAME}" + else + # Doing remote fetch, we we will look up, but some generic names like + # "perl" wont work, since we don't know the default version + INDEX_FILE="${PKGDIR}/INDEX.deps" + REGEX="^${PACKAGE}|" - LINE=`grep "${REGEX}" "${INDEX_FILE}" 2>/dev/null` - NAME=`echo "${LINE}"|cut -f2 -d'|'` + LINE=`grep "${REGEX}" "${INDEX_FILE}" 2>/dev/null` + NAME=`echo "${LINE}"|cut -f2 -d'|'` - export VAL="${NAME}" + export VAL="${NAME}" + fi if [ -z "${VAL}" ] then RES=1 fi - return ${RES} }; @@ -334,7 +352,7 @@ fetch_package_by_ftp() fi FTPDIR="${VAL}" - PACKAGE="${PACKAGE}.tbz" + PACKAGE="${PACKAGE}.${PKGEXT}" FTP_SERVER="ftp://${FTPHOST}${FTPDIR}" if [ ! -f "${SAVEDIR}/${PACKAGE}" ] @@ -345,28 +363,49 @@ fetch_package_by_ftp() fi }; -fetch_package_by_fs() -{ - CATEGORY="${1}" - PACKAGE="${2}" - SAVEDIR="${3}" - - PACKAGE="${PACKAGE}.tbz" - if [ ! -f "${SAVEDIR}/${PACKAGE}" ] - then - fetch_file "${CDMNT}/packages/${CATEGORY}/${PACKAGE}" "${SAVEDIR}/" "0" - fi -}; - fetch_package() { CATEGORY="${1}" PACKAGE="${2}" SAVEDIR="${3}" + # Fetch package, but skip if installing from local media case "${INSTALLMEDIUM}" in - usb|dvd) fetch_package_by_fs "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;; + usb|dvd|local) return ;; ftp) fetch_package_by_ftp "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;; sftp) ;; esac }; + +bootstrap_pkgng() +{ + # Check if we need to boot-strap pkgng + if run_chroot_cmd "which pkg-static" >/dev/null 2>/dev/null + then + return + fi + local PKGPTH + + # Ok, lets boot-strap this sucker + echo_log "Bootstraping pkgng.." + fetch_package "Latest" "pkg" "${PKGDLDIR}" + + # Figure out real location of "pkg" package + case "${INSTALLMEDIUM}" in + usb|dvd|local) PKGPTH="${PKGTMPDIR}/Latest/pkg.${PKGEXT}" ;; + *) PKGPTH="${PKGTMPDIR}/pkg.${PKGEXT}" ;; + esac + rc_halt "pkg -c ${FSMNT} add ${PKGPTH}" ; run_chroot_cmd "pkg2ng" +} + +get_package_location() +{ + case "${INSTALLMEDIUM}" in + usb|dvd) rc_halt "mount_nullfs ${CDMNT}/packages ${FSMNT}${PKGTMPDIR}" + PKGDLDIR="${FSMNT}${PKGTMPDIR}/All" ;; + local) rc_halt "mount_nullfs ${LOCALPATH}/packages ${FSMNT}${PKGTMPDIR}" + PKGDLDIR="${FSMNT}${PKGTMPDIR}/All" ;; + *) PKGDLDIR="${FSMNT}${PKGTMPDIR}" ;; + esac + export PKGDLDIR +} |