From c07c5231a154f8805d3b84e86f86f2c2c8f8a25b Mon Sep 17 00:00:00 2001 From: imp Date: Tue, 13 Jul 2010 23:47:12 +0000 Subject: Add support for packages. PR: 148584 Submitted by: John Hixon --- usr.sbin/pc-sysinstall/backend-query/Makefile | 10 +- .../pc-sysinstall/backend-query/get-packages.sh | 60 +++++++++ .../pc-sysinstall/backend-query/list-config.sh | 2 +- .../pc-sysinstall/backend-query/list-mirrors.sh | 2 +- .../pc-sysinstall/backend-query/list-packages.sh | 74 +++++++++++ usr.sbin/pc-sysinstall/backend/Makefile | 5 +- usr.sbin/pc-sysinstall/backend/functions-ftp.sh | 2 +- .../pc-sysinstall/backend/functions-packages.sh | 148 +++++++++++++++++++++ usr.sbin/pc-sysinstall/doc/help-index | 32 +++-- .../pc-sysinstall/pc-sysinstall/pc-sysinstall.sh | 14 +- 10 files changed, 325 insertions(+), 24 deletions(-) create mode 100755 usr.sbin/pc-sysinstall/backend-query/get-packages.sh create mode 100755 usr.sbin/pc-sysinstall/backend-query/list-packages.sh create mode 100755 usr.sbin/pc-sysinstall/backend/functions-packages.sh (limited to 'usr.sbin') diff --git a/usr.sbin/pc-sysinstall/backend-query/Makefile b/usr.sbin/pc-sysinstall/backend-query/Makefile index 1deed3f..c042ac3 100644 --- a/usr.sbin/pc-sysinstall/backend-query/Makefile +++ b/usr.sbin/pc-sysinstall/backend-query/Makefile @@ -1,11 +1,11 @@ # $FreeBSD$ FILES= detect-laptop.sh detect-nics.sh detect-emulation.sh disk-info.sh \ - disk-list.sh disk-part.sh enable-net.sh list-config.sh list-components.sh \ - list-mirrors.sh list-rsync-backups.sh list-tzones.sh query-langs.sh \ - send-logs.sh setup-ssh-keys.sh sys-mem.sh test-live.sh test-netup.sh \ - update-part-list.sh xkeyboard-layouts.sh xkeyboard-models.sh \ - xkeyboard-variants.sh + disk-list.sh disk-part.sh enable-net.sh get-packages.sh list-config.sh \ + list-components.sh list-mirrors.sh list-packages.sh list-rsync-backups.sh \ + list-tzones.sh query-langs.sh send-logs.sh setup-ssh-keys.sh sys-mem.sh \ + test-live.sh test-netup.sh update-part-list.sh xkeyboard-layouts.sh \ + xkeyboard-models.sh xkeyboard-variants.sh FILESMODE= ${BINMODE} FILESDIR=${SHAREDIR}/pc-sysinstall/backend-query NO_OBJ= diff --git a/usr.sbin/pc-sysinstall/backend-query/get-packages.sh b/usr.sbin/pc-sysinstall/backend-query/get-packages.sh new file mode 100755 index 0000000..2c8eab2 --- /dev/null +++ b/usr.sbin/pc-sysinstall/backend-query/get-packages.sh @@ -0,0 +1,60 @@ +#!/bin/sh +#- +# Copyright (c) 2010 iXsystems, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# Script which lists the available packages for this release +########################################################################### + +. ${PROGDIR}/backend/functions.sh +. ${PROGDIR}/backend/functions-packages.sh + +DEFAULT_FTP_SERVER="ftp.freebsd.org" +FTP_SERVER="${1}" +ID=`id -u` + +if [ "${ID}" -ne "0" ] +then + echo "Error: must be root!" + exit 1 +fi + +if [ -z "${FTP_SERVER}" ] +then + FTP_SERVER="${DEFAULT_FTP_SERVER}" +fi + +if [ ! -f "${PKGDIR}/INDEX" ] +then + get_package_index "${FTP_SERVER}" +fi + +if [ -f "${PKGDIR}/INDEX" ] +then + echo "${PKGDIR}/INDEX" + exit 0 +fi + +exit 1 diff --git a/usr.sbin/pc-sysinstall/backend-query/list-config.sh b/usr.sbin/pc-sysinstall/backend-query/list-config.sh index d230814..b7edda2 100755 --- a/usr.sbin/pc-sysinstall/backend-query/list-config.sh +++ b/usr.sbin/pc-sysinstall/backend-query/list-config.sh @@ -1,6 +1,6 @@ #!/bin/sh #- -# Copyright (c) 2010 iX Systems, Inc. All rights reserved. +# Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh b/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh index 6fdeb00..0fe209d 100755 --- a/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh +++ b/usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh @@ -1,6 +1,6 @@ #!/bin/sh #- -# Copyright (c) 2010 iX Systems, Inc. All rights reserved. +# Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/usr.sbin/pc-sysinstall/backend-query/list-packages.sh b/usr.sbin/pc-sysinstall/backend-query/list-packages.sh new file mode 100755 index 0000000..02d3e9a --- /dev/null +++ b/usr.sbin/pc-sysinstall/backend-query/list-packages.sh @@ -0,0 +1,74 @@ +#!/bin/sh +#- +# Copyright (c) 2010 iXsystems, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# Script which lists the available packages for this release +########################################################################### + +. ${PROGDIR}/backend/functions.sh +. ${PROGDIR}/backend/functions-packages.sh + +PACKAGE_CATEGORY="${1}" +PACKAGE_NAME="${2}" +NARGS=0 + +if [ ! -f "${PKGDIR}/INDEX" ] +then + echo "Error: please fetch package index with get-packages!" + exit 1 +fi + +if [ ! -f "${PKGDIR}/INDEX.parsed" ] +then + parse_package_index +fi + +if [ -n "${PACKAGE_CATEGORY}" ] +then + NARGS=$((NARGS+1)) +fi + +if [ -n "${PACKAGE_NAME}" ] +then + NARGS=$((NARGS+1)) +fi + +echo "Available Packages:" +if [ "${NARGS}" -eq "0" ] +then + show_packages + +elif [ "${NARGS}" -eq "1" ] +then + show_packages_by_category "${PACKAGE_CATEGORY}" + +elif [ "${NARGS}" -eq "2" ] +then + show_package_by_name "${PACKAGE_CATEGORY}" "${PACKAGE_NAME}" + +else + show_packages +fi diff --git a/usr.sbin/pc-sysinstall/backend/Makefile b/usr.sbin/pc-sysinstall/backend/Makefile index f211664..9207726 100644 --- a/usr.sbin/pc-sysinstall/backend/Makefile +++ b/usr.sbin/pc-sysinstall/backend/Makefile @@ -4,8 +4,9 @@ FILES= functions-bsdlabel.sh functions-cleanup.sh functions-disk.sh \ functions-extractimage.sh functions-ftp.sh functions-installcomponents.sh \ functions-localize.sh functions-mountdisk.sh \ functions-mountoptical.sh functions-networking.sh \ - functions-newfs.sh functions-parse.sh functions-runcommands.sh \ - functions-unmount.sh functions-upgrade.sh functions-users.sh \ + functions-newfs.sh functions-packages.sh functions-parse.sh \ + functions-runcommands.sh functions-unmount.sh \ + functions-upgrade.sh functions-users.sh \ functions.sh parseconfig.sh startautoinstall.sh FILESMODE= ${BINMODE} FILESDIR=${SHAREDIR}/pc-sysinstall/backend diff --git a/usr.sbin/pc-sysinstall/backend/functions-ftp.sh b/usr.sbin/pc-sysinstall/backend/functions-ftp.sh index eda8014..cd48538 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-ftp.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-ftp.sh @@ -1,6 +1,6 @@ #!/bin/sh #- -# Copyright (c) 2010 iX Systems, Inc. All rights reserved. +# Copyright (c) 2010 iXsystems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/usr.sbin/pc-sysinstall/backend/functions-packages.sh b/usr.sbin/pc-sysinstall/backend/functions-packages.sh new file mode 100755 index 0000000..345b649 --- /dev/null +++ b/usr.sbin/pc-sysinstall/backend/functions-packages.sh @@ -0,0 +1,148 @@ +#!/bin/sh +#- +# Copyright (c) 2010 iXsystems, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +# Functions which runs commands on the system + +. ${BACKEND}/functions.sh +. ${BACKEND}/functions-parse.sh +. ${BACKEND}/functions-ftp.sh + + +get_package_index() +{ + FTP_SERVER="${1}" + FTP_DIR="ftp://${FTP_SERVER}/pub/FreeBSD/releases/${FBSD_ARCH}/${FBSD_BRANCH}/packages" + INDEX_FILE="INDEX" + USE_BZIP2=0 + + if [ -f "/usr/bin/bzip2" ] + then + INDEX_FILE="${INDEX_FILE}.bz2" + USE_BZIP2=1 + fi + + ftp "${FTP_DIR}/${INDEX_FILE}" + if [ -f "${INDEX_FILE}" ] + then + if [ "${USE_BZIP2}" -eq "1" ] + then + bzip2 -d "${INDEX_FILE}" + INDEX_FILE="${INDEX_FILE%.bz2}" + fi + + mv "${INDEX_FILE}" "${PKGDIR}" + fi +} + +parse_package_index() +{ + INDEX_FILE="${PKGDIR}/INDEX" + + exec 3<&0 + exec 0<"${INDEX_FILE}" + + while read -r line + do + CATEGORY="" + PACKAGE="" + DESC="" + i=0 + + SAVE_IFS="${IFS}" + IFS="|" + + for part in ${line} + do + if [ "${i}" -eq "1" ] + then + PACKAGE=`basename "${part}"` + + elif [ "${i}" -eq "3" ] + then + DESC="${part}" + + elif [ "${i}" -eq "6" ] + then + CATEGORY=`echo "${part}" | cut -f1 -d' '` + fi + + i=$((i+1)) + done + + echo "${CATEGORY}|${PACKAGE}|${DESC}" >> "${INDEX_FILE}.parsed" + IFS="${SAVE_IFS}" + done + + exec 0<&3 +} + +show_package_file() +{ + PKGFILE="${1}" + + exec 3<&0 + exec 0<"${PKGFILE}" + + while read -r line + do + CATEGORY=`echo "${line}" | cut -f1 -d'|'` + PACKAGE=`echo "${line}" | cut -f2 -d'|'` + DESC=`echo "${line}" | cut -f3 -d'|'` + + echo "${CATEGORY}/${PACKAGE}:${DESC}" + done + + exec 0<&3 +} + +show_packages_by_category() +{ + CATEGORY="${1}" + INDEX_FILE="${PKGDIR}/INDEX.parsed" + TMPFILE="/tmp/.pkg.cat" + + grep "^${CATEGORY}|" "${INDEX_FILE}" > "${TMPFILE}" + show_package_file "${TMPFILE}" + rm "${TMPFILE}" +} + +show_package_by_name() +{ + CATEGORY="${1}" + PACKAGE="${2}" + INDEX_FILE="${PKGDIR}/INDEX.parsed" + TMPFILE="/tmp/.pkg.cat.pak" + + grep "^${CATEGORY}|${PACKAGE}" "${INDEX_FILE}" > "${TMPFILE}" + show_package_file "${TMPFILE}" + rm "${TMPFILE}" +} + +show_packages() +{ + show_package_file "${PKGDIR}/INDEX.parsed" +} diff --git a/usr.sbin/pc-sysinstall/doc/help-index b/usr.sbin/pc-sysinstall/doc/help-index index bb6cff1..d9e52b5 100644 --- a/usr.sbin/pc-sysinstall/doc/help-index +++ b/usr.sbin/pc-sysinstall/doc/help-index @@ -11,49 +11,55 @@ Help Commands System Query Commands disk-list - Provides a listing of the disk drives detected on this system + Provides a listing of the disk drives detected on this system disk-part - Queries the specified disk and returns information about its partitions + Queries the specified disk and returns information about its partitions disk-info - Returns information about the disks size, cyls, heads, and sectors + Returns information about the disks size, cyls, heads, and sectors detect-laptop - Tests to see if this system is a laptop or desktop + Tests to see if this system is a laptop or desktop detect-emulation - Tests to see if this system is actually running in an emulator such as VirtualBox + Tests to see if this system is actually running in an emulator such as VirtualBox detect-nics - Returns a listing of the detected network cards on this system + Returns a listing of the detected network cards on this system list-config Returns a listing of the pc-sysinstall configuration list-components - Returns a listing of the available components which can be installed + Returns a listing of the available components which can be installed list-mirrors - Returns a listing of the available FTP mirrors + Returns a listing of the available FTP mirrors + + list-packages + Returns a listing of the available packages list-rsync-backups - Returns a listing of available rsync-backups on the target server in the life-preserver/ dir + Returns a listing of available rsync-backups on the target server in the life-preserver/ dir list-tzones - Returns a listing of available timezones + Returns a listing of available timezones query-langs Return a list of languages that the installer supports + get-packages + Retrieves the list of packages from an FTP mirror + sys-mem - Return the size of installed system RAM in MegaBytes + Return the size of installed system RAM in MegaBytes test-netup - Test if an internet connection is available + Test if an internet connection is available update-part-list - Return a list of PC-BSD & FreeBSD installs on this system for updates + Return a list of PC-BSD & FreeBSD installs on this system for updates xkeyboard-layouts Return a list of keyboard layouts that xorg supports diff --git a/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh b/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh index 4860893..a26e304 100755 --- a/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh +++ b/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh @@ -43,6 +43,10 @@ export PROGDIR COMPDIR="${PROGDIR}/components" export COMPDIR +# Set this to the packages location +PKGDIR="${PROGDIR}/conf" +export PKGDIR + # End of user-editable configuration ##################################################################### @@ -156,6 +160,10 @@ case $1 in list-mirrors) ${QUERYDIR}/list-mirrors.sh "${2}" ;; + # Function which lists available packages + list-packages) ${QUERYDIR}/list-packages.sh "${2}" "${3}" + ;; + # Function which lists available backups on a rsync/ssh server list-rsync-backups) ${QUERYDIR}/list-rsync-backups.sh "${2}" "${3}" "${4}" ;; @@ -172,6 +180,10 @@ case $1 in send-logs) ${QUERYDIR}/send-logs.sh ${2} ;; + # Function to get package index + get-packages) ${QUERYDIR}/get-packages.sh "${2}" + ;; + # Function which allows setting up of SSH keys setup-ssh-keys) ${QUERYDIR}/setup-ssh-keys.sh "${2}" "${3}" "${4}" ;; @@ -209,4 +221,4 @@ case $1 in esac # Exit with success if we made it to the end -exit 0 +exit $? -- cgit v1.1