>Number:         148584
>Category:       bin
>Synopsis:       Modifications to pc-sysinstall to support packages
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 13 23:00:17 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     John Hixson
>Release:        9.0-CURRENT
>Organization:
iXsystems, Inc
>Environment:
FreeBSD thinkbsd 9.0-CURRENT FreeBSD 9.0-CURRENT #0: Tue Jul 13 09:31:39 PDT 
2010     j...@thinkbsd:/usr/src/sys/amd64/compile/THINKBSD  amd64
>Description:
Update pc-sysinstall to support grabbing packages INDEX via FTP as well as 
parsing and listing packages from INDEX file.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -urN usr.sbin/pc-sysinstall.orig/backend/Makefile 
usr.sbin/pc-sysinstall/backend/Makefile
--- usr.sbin/pc-sysinstall.orig/backend/Makefile        2010-06-27 
10:04:03.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/Makefile     2010-07-13 11:46:50.000000000 
-0700
@@ -4,8 +4,9 @@
        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 -urN usr.sbin/pc-sysinstall.orig/backend/functions-packages.sh 
usr.sbin/pc-sysinstall/backend/functions-packages.sh
--- usr.sbin/pc-sysinstall.orig/backend/functions-packages.sh   1969-12-31 
16:00:00.000000000 -0800
+++ usr.sbin/pc-sysinstall/backend/functions-packages.sh        2010-07-13 
15:45:53.000000000 -0700
@@ -0,0 +1,148 @@
+#!/bin/sh
+#-
+# Copyright (c) 2010 iX Systems, 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: src/usr.sbin/pc-sysinstall/backend/functions-ftp.sh,v 1.1 
2010/06/27 17:04:03 imp Exp $
+
+# 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 -urN usr.sbin/pc-sysinstall.orig/backend-query/Makefile 
usr.sbin/pc-sysinstall/backend-query/Makefile
--- usr.sbin/pc-sysinstall.orig/backend-query/Makefile  2010-07-13 
09:25:39.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend-query/Makefile       2010-07-13 
12:43:36.000000000 -0700
@@ -1,11 +1,11 @@
 # $FreeBSD: src/usr.sbin/pc-sysinstall/backend-query/Makefile,v 1.4 2010/07/06 
23:29:55 imp Exp $
 
 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 -urN usr.sbin/pc-sysinstall.orig/backend-query/get-packages.sh 
usr.sbin/pc-sysinstall/backend-query/get-packages.sh
--- usr.sbin/pc-sysinstall.orig/backend-query/get-packages.sh   1969-12-31 
16:00:00.000000000 -0800
+++ usr.sbin/pc-sysinstall/backend-query/get-packages.sh        2010-07-13 
13:57:28.000000000 -0700
@@ -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 -urN usr.sbin/pc-sysinstall.orig/backend-query/list-packages.sh 
usr.sbin/pc-sysinstall/backend-query/list-packages.sh
--- usr.sbin/pc-sysinstall.orig/backend-query/list-packages.sh  1969-12-31 
16:00:00.000000000 -0800
+++ usr.sbin/pc-sysinstall/backend-query/list-packages.sh       2010-07-13 
15:46:22.000000000 -0700
@@ -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 -urN usr.sbin/pc-sysinstall.orig/doc/help-index 
usr.sbin/pc-sysinstall/doc/help-index
--- usr.sbin/pc-sysinstall.orig/doc/help-index  2010-07-13 09:25:39.000000000 
-0700
+++ usr.sbin/pc-sysinstall/doc/help-index       2010-07-13 12:58:09.000000000 
-0700
@@ -11,49 +11,55 @@
 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 <disk>
-       Queries the specified disk and returns information about its partitions
+        Queries the specified disk and returns information about its partitions
     
     disk-info <disk>
-       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 <user> <host> <port>
-       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 -urN usr.sbin/pc-sysinstall.orig/pc-sysinstall/pc-sysinstall.sh 
usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
--- usr.sbin/pc-sysinstall.orig/pc-sysinstall/pc-sysinstall.sh  2010-07-13 
09:25:39.000000000 -0700
+++ usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh       2010-07-13 
15:41:21.000000000 -0700
@@ -43,6 +43,10 @@
 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 @@
   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 @@
   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 @@
 esac
 
 # Exit with success if we made it to the end
-exit 0
+exit $?


>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to