source: src-sh/pc-updatemanager/pc-updatemanager

Last change on this file was 22bfc1e, checked in by Kris Moore <kris@…>, 2 days ago

Add the initial support for PC-BSD to use multiple PKGNG repos

This will do the following:

It will allow us to maintain a single "full" package repo, for every XX.0-RELEASE
for the lifecycle of the entire 10.X, 11.X series, etc.

For specific XX.1 or XX.2 releases, or -STABLE, we will only
need to have our builders create a small set of packages specific
to that kernel / world. I.E drivers / kmod files, etc.

The main packages can still be pulled from the .0-RELEASE repo, since
they should be ABI compat

  • Property mode set to 100755
File size: 36.4 KB
Line 
1#!/bin/sh
2# Script which performs updating services
3############################################################################
4
5# Source our functions
6. /usr/local/share/pcbsd/scripts/functions.sh
7
8# Set the program location
9PROGDIR="/usr/local/share/pcbsd/pc-updatemanager" ; export PROGDIR
10
11# Start by sourcing /etc/profile
12# This grabs any HTTP_ / FTP_ PROXY variables
13. /etc/profile
14
15PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
16export PCBSD_ETCCONF
17
18# Set the pub openssl key
19SKEY="${PROGDIR}/conf/security.key" ; export SKEY
20
21# Directory to store downloaded updates
22DOWNLOADDIR="/usr/local/tmp"
23
24# Get the system version we are checking for updates to
25SYSVER="`uname -r | cut -d '-' -f 1-2`" ; export SYSVER
26
27# Get the system type
28SYSTYPE="`/usr/local/bin/pbreg get /PC-BSD/SysType`" ; export SYSTYPE
29
30# Set the config location
31UPDATECONF="${PROGDIR}/conf/sysupdate.conf"
32
33# Set the system arch type
34ARCH=`uname -m`
35
36# Patchset Data
37PATCHSERVER="`cat ${UPDATECONF} | grep '^UPDATESERVER:' | cut -d ' ' -f 2`"
38PATCHSET="`cat ${UPDATECONF} | grep '^PATCHSET:' | cut -d ' ' -f 2`"
39PATCHFILE="${PATCHSET}.upd"
40PATCHURL="${PATCHSERVER}/${PATCHFILE}"
41PATCHTMPDIR=`mktemp -d /tmp/.sysupdateXXXXXX`
42PATCHTMPFILE="${PATCHTMPDIR}/sysupdate-${SYSVER}.upd"
43
44MUSTAGEDIR="${DOWNLOADDIR}/update-stagedir"
45
46# Enable ftp passive mode for file transfers
47FTP_PASSIVE_MODE="YES" ; export FTP_PASSIVE_MODE
48
49if [ ! -d "${DOWNLOADDIR}" ]; then mkdir -p ${DOWNLOADDIR}; fi
50
51
52# Trigger File for Tray Application
53TRIGGERFILE="/tmp/.sysupdatetraytrigger"
54
55DBDIR="/var/db/pc-updatemanager"
56INSDIR="${DBDIR}/installed"
57IGNDIR="${DBDIR}/ignored"
58
59# PKG_CMD to use
60PKG_CMD="/usr/sbin/pkg"
61
62# Make sure we don't keep these from system environment
63unset INJAIL PKG_FLAG
64
65ISOTMP="/usr/local/tmp/pcbsd-update.iso"
66
67######################################################################
68# Done with config values
69######################################################################
70
71# Get the PACKAGE_SET to use for this pkgng repo
72PACKAGE_SET="PRODUCTION"
73_pkgChk="`sed -n 's/PACKAGE_SET: //p' ${PCBSD_ETCCONF} 2>/dev/null | awk '{print $1}'`"
74if [ -n "${_pkgChk}" ] ; then PACKAGE_SET="$_pkgChk" ; fi
75
76# Check the PACKAGE_SET variable
77case $PACKAGE_SET in
78   PRODUCTION|EDGE) ;;
79  CUSTOM) # Using a custom package set?
80          # Lets check that we have a URL provided
81          _urlChk="`sed -n 's/^PACKAGE_URL: //p' ${PCBSD_ETCCONF} 2>/dev/null | awk '{print $1}'`"
82          if [ -z "${_urlChk}" ] ; then
83             echo "Warning: PACKAGE_SET is CUSTOM, but no PACKAGE_URL set!"
84             echo "Reverting back to PRODUCTION repo..."
85             sleep 3
86             CUSTOM_URL=""
87             PACKAGE_SET="PRODUCTION"
88          else
89             CUSTOM_URL="$_urlChk"
90          fi
91          _urlChk="`sed -n 's/^CURSYS_PACKAGE_URL: //p' ${PCBSD_ETCCONF} 2>/dev/null | awk '{print $1}'`"
92          if [ -z "${_urlChk}" ] ; then
93             CUSTOM_CURSYS_URL=""
94          else
95             CUSTOM_CURSYS_URL="$_urlChk"
96          fi
97          ;;
98       *) echo "Warning: Invalid PACKAGE_SET!" 
99          PACKAGE_SET="PRODUCTION" ;;
100esac
101
102
103
104# Files we always want to upgrade in /etc
105ETCCLOBBER="mail/sendmail.cf mail/freebsd.cf"
106
107show_usage() {
108        echo "pc-updatemanager: Usage
109----
110  branches              - List available system branches
111  chbranch <tag>        - Change to new system branch
112  check                 - Check for system updates
113  install <tag>,<tag2>  - Install system updates
114  pkgcheck              - Check for updates to packages
115  pkgupdate             - Install packages updates
116  syncconf              - Update PC-BSD pkgng configuration
117  confcheck             - Check PC-BSD pkgng configuration
118  -j <jail>             - Operate on the jail specified
119"       
120
121        exit 1
122}
123
124setup_pkgng_conf() {
125
126  # See if we need to adjust pcbsd.conf repo file
127  if [ ! -e "/usr/local/etc/pkg/repos/pcbsd.conf.dist" ];then
128     echo "WARNING: Missing /usr/local/etc/pkg/repos/pcbsd.conf.dist"
129     status="1"
130     return 1
131  fi
132
133  # Remove old pkg conf
134  if [ -e "/usr/local/etc/pkg/repos/pcbsd.conf" ] ; then
135    rm /usr/local/etc/pkg/repos/pcbsd.conf
136  fi
137
138  ARCH=`uname -m`
139  FBSDVER=`uname -r | cut -d '-' -f 1-2`
140  MAJORVER="`uname -r | cut -d '-' -f 1 |  cut -d '.' -f 1`.0-RELEASE"
141
142  # If using the EDGE package set, set the right path
143  case $PACKAGE_SET in
144       EDGE) FBSDVER="$FBSDVER/edge"
145             MAJORVER="$MAJORVER/edge"
146             ;;
147          *) ;;
148  esac
149
150  # We are now going to create pcbsd.conf and local-pcbsd.conf
151  # The first is set to the systems uname path
152  # The second is set to the XX.0-RELEASE path
153  #
154  # This is done so that on 10.1 or 10.0-STABLE or other non .0-RELEASEs
155  # our package builders only need to build packages that specifically need
156  # to be compiled on that kernel / release.
157  # I.E nvidia-drivers, -kmod packages, etc.
158  # The other packages which should be ABI compatiable can be pulled from
159  # the main XX.0-RELEASE repository
160
161  # Now create standard pcbsd.conf file
162  if [ "$PACKAGE_SET" = "CUSTOM" -a -n "$CUSTOM_URL" ] ; then
163     cat << EOF >/usr/local/etc/pkg/repos/pcbsd.conf
164pcbsd-major: {
165               url: "$CUSTOM_URL",
166               signature_type: "fingerprints",
167               fingerprints: "/usr/local/etc/pkg/fingerprints/pcbsd",
168               enabled: true
169              }
170EOF
171  else
172     # Using PC-BSD CDN
173     cat /usr/local/etc/pkg/repos/pcbsd.conf.dist \
174        | sed "s|pcbsd: |pcbsd-major: |g" \
175        | sed "s|VERSION|$MAJORVER|g" \
176        | sed "s|ARCH|$ARCH|g" > /usr/local/etc/pkg/repos/pcbsd.conf
177  fi
178
179  if [ -e "/usr/local/etc/pkg/repos/local-pcbsd.conf" ] ; then
180     rm /usr/local/etc/pkg/repos/local-pcbsd.conf
181  fi
182
183  # If the release and local versions are the same, we can skip creating this file for now
184  if [ "$FBSDVER" = "$MAJORVER" ] ; then return 0; fi
185  if [ "$PACKAGE_SET" = "CUSTOM" -a "$CUSTOM_URL" = "$CUSTOM_CURSYS_URL" ] ; then return 0; fi
186
187  # Create the local-pcbsd.conf file
188  if [ "$PACKAGE_SET" = "CUSTOM" -a -n "$CUSTOM_CURSYS_URL" ] ; then
189     cat << EOF >/usr/local/etc/pkg/repos/local-pcbsd.conf
190pcbsd-sysrel: {
191               url: "$CUSTOM_CURSYS_URL",
192               signature_type: "fingerprints",
193               fingerprints: "/usr/local/etc/pkg/fingerprints/pcbsd",
194               enabled: true
195              }
196EOF
197  else
198     # Using PC-BSD CDN
199     cat /usr/local/etc/pkg/repos/pcbsd.conf.dist \
200        | sed "s|pcbsd: |pcbsd-sysrel: |g" \
201        | sed "s|VERSION|$FBSDVER|g" \
202        | sed "s|ARCH|$ARCH|g" > /usr/local/etc/pkg/repos/local-pcbsd.conf
203  fi
204
205}
206
207get_update_file() {
208
209  # Now fetch the update file
210  get_file "${PATCHURL}" "${PATCHTMPFILE}" 1 >/dev/null 2>/dev/null
211  if [ $? -ne 0 ] ; then
212     rm ${PATCHTMPFILE} 2>/dev/null
213     is_net_up
214     if [ $? -eq 0 ] ; then
215       echo "No updates available for $SYSVER!" ; exit 0
216     else
217       exit_err "Could not contact update server!"
218     fi
219  fi
220
221  # Now fetch the update file signature
222  get_file "${PATCHURL}.sha1" "${PATCHTMPFILE}.sha1" 1 >/dev/null 2>/dev/null
223  if [ $? -ne 0 ] ; then
224     rm ${PATCHTMPFILE}.sha1 2>/dev/null
225     is_net_up
226     if [ $? -eq 0 ] ; then
227       echo "No updates available for $SYSVER!" ; exit 0
228     else
229       exit_err "Could not contact update server!"
230     fi
231  fi
232
233  # Lets verify the signature of the file
234  openssl dgst -sha1 -verify ${SKEY} \
235        -signature ${PATCHTMPFILE}.sha1 \
236        ${PATCHTMPFILE} >/dev/null 2>/dev/null
237  if [ $? -ne 0 ] ; then
238     rm ${PATCHTMPFILE} 2>/dev/null
239     rm ${PATCHTMPFILE}.sha1 2>/dev/null
240     exit_err "Update file failed verification..."
241  fi
242
243  # Done with the signature we can discard
244  rm ${PATCHTMPFILE}.sha1
245
246}
247
248do_branch() {
249  up="$1"
250
251  # Setup our variable to catch if we have a bad branch
252  BRANCHFOUND="0" 
253
254  while read line
255  do
256     echo $line | grep -q "^BRANCHES:"
257     if [ $? -eq 0 ] ; then
258        for i in `echo $line | cut -d ':' -f 2 | sed 's|,| |g'`
259        do
260          if [ "$i" != "$up" ] ; then continue ;fi
261          if [ "`uname -r | cut -d '-' -f 1-2`" = "$up" ] ; then
262             echo "You are already on this branch!"
263             BRANCHFOUND="1"
264             continue;
265          fi
266          start_major_fbsd_update "fbsd-$up"
267          BRANCHFOUND="1"
268          break
269        done
270     fi
271  done < ${PATCHTMPFILE}
272
273  # If no patches
274  if [ "${BRANCHFOUND}" = "0" ]; then 
275     # No available updates
276     echo "Unknown branch ${1}"
277  fi
278
279  rm ${PATCHTMPFILE}
280
281};
282
283list_branches() {
284  # Setup our variable, we have no branches so far
285  BRANCHFOUND="0" 
286
287  while read line
288  do
289     echo $line | grep -q "^BRANCHES:"
290     if [ $? -eq 0 ] ; then
291        echo "Available branches:"
292        echo "* = Current Branch"
293        echo "----------------------------------"
294        echo $line | cut -d ':' -f 2 | sed 's|,|\
295|g' | while read branch
296        do
297                if [ "`uname -r | cut -d '-' -f 1-2`" = "$branch" ] ; then
298                        echo "$branch *"
299                else
300                        echo "$branch"
301                fi
302        done
303        echo ""
304        echo "To change branches run: ${0} chbranch <branch>"
305        BRANCHFOUND="1"
306        continue
307     fi
308  done < ${PATCHTMPFILE}
309
310  # If no patches
311  if [ "${BRANCHFOUND}" = "0" ]; then 
312     # No available updates
313     echo "No branches currently available!"
314  fi
315
316  rm ${PATCHTMPFILE}
317
318};
319
320do_fbsdcheck() {
321  # Setup our variable, we have no patches so far
322  PATCHFOUND="0" 
323  echo "Checking for FreeBSD updates..."
324  pc-fbsdupdatecheck | grep -q "will be updated"
325  if [ $? -eq 0 ] ; then
326     PATCHFOUND="1"
327  fi
328
329  if [ "${PATCHFOUND}" = "1" ]; then
330    echo "The following updates are available:"
331    echo "------------------------------------"
332    echo "NAME: FreeBSD system update"
333    echo "TYPE: System Update"
334    echo " "
335    echo "Install: \"freebsd-update fetch && freebsd-update install\""
336    echo " "
337
338    if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
339      pc-systemflag SYSUPDATE UPDATE #set the system flag that system updates are available
340    fi
341  fi
342}
343
344do_check() {
345
346  while read line
347  do
348     echo $line | grep -q "^MU:"
349     if [ $? -eq 0 ] ; then
350        parse_mu_update_line "$line"
351        continue
352     fi
353     echo $line | grep -q "^SA:"
354     if [ $? -eq 0 ] ; then
355        parse_sa_update_line "$line"
356        continue
357     fi
358  done < ${PATCHTMPFILE}
359
360  # If no patches
361  if [ "${PATCHFOUND}" = "0" ]; then 
362     # No available updates
363     echo "Your system is up to date!"
364     if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
365       pc-systemflag SYSUPDATE SUCCESS #set the system flag that system is up to date
366     fi
367  else
368    if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
369      pc-systemflag SYSUPDATE UPDATE #set the system flag that system updates are available
370    fi
371  fi
372
373  rm ${PATCHTMPFILE}
374
375};
376
377parse_mu_update_line()
378{
379   local line="$1"
380
381   # Check if this is a major update we can install
382   local sysUpOVer=`echo $line | cut -d ':' -f 2`
383   local sysUpNVer=`echo $line | cut -d ':' -f 3`
384
385   # Is this an update for our version?
386   if [ "$SYSVER" != "$sysUpOVer" ] ; then return; fi
387
388   if [ $PATCHFOUND -eq 0 ] ; then
389      echo ""
390      echo "The following updates are available:"
391      echo "------------------------------------"
392   fi
393   echo "NAME: System Update to ${sysUpNVer}" 
394   echo "TYPE: SYSUPDATE" 
395   echo "TAG: fbsd-${sysUpNVer}"
396   echo "VERSION: ${sysUpNVer}" 
397   echo ""
398   echo "To install: \"pc-updatemanager install fbsd-${sysUpNVer}\""
399   echo ""
400   echo ""
401
402   PATCHFOUND="`expr ${PATCHFOUND} + 1`" 
403}
404
405parse_sa_update_line()
406{
407   local line="$1"
408
409   # Check if this is an update we can install
410   local saVer=`echo $line | cut -d ':' -f 2`
411   local saArch=`echo $line | cut -d ':' -f 3`
412   local saType=`echo $line | cut -d ':' -f 4`
413   local saIdent="`echo $line | cut -d ':' -f 5`"
414
415   # For this version?
416   if [ "$SYSVER" != "$saVer" ] ; then return ; fi
417
418   # For this system arch?
419   if [ "$ARCH" != "$saArch" -a "$saArch" != "noarch" ] ; then return ; fi
420
421   # For this system type?
422   if [ "$SYSTYPE" != "$saType" -a "$saType" != "both" ] ; then return ; fi
423
424   # Already installed?
425   if [ -e "${INSDIR}/${SYSVER}/$saIdent" ] ; then return ; fi
426
427   if [ $PATCHFOUND -eq 0 ] ; then
428      echo ""
429      echo "The following updates are available:"
430      echo "------------------------------------"
431   fi
432   local saDesc="`echo $line | cut -d ':' -f 6`"
433   local saSize=`echo $line | cut -d ':' -f 8`
434   local saDetail="http://trac.pcbsd.org`echo $line | cut -d ':' -f 10`"
435   local saDate="`echo $line | cut -d ':' -f 11`"
436
437   echo "NAME: ${saDesc}" 
438   echo "TYPE: PATCH" 
439   echo "TAG: ${saIdent}"
440   echo "DETAILS: ${saDetail}"
441   echo "DATE: ${saDate}"
442   echo "SIZE: ${saSize}Mb" 
443   echo " "
444   echo "To install: \"pc-updatemanager install ${saIdent}\""
445   echo " "
446
447   PATCHFOUND="`expr ${PATCHFOUND} + 1`" 
448}
449
450start_pcbsd_patch() {
451  local up="$1"
452  local saIdent=""
453  local saVer=""
454  local saArch=""
455  local saPlat=""
456  local saUrl=""
457  local saDesc=""
458  local saCsum=""
459  local patchLine=""
460  if [ -e "${INSDIR}/${SYSVER}/${up}" ]; then
461     rm ${PATCHTMPFILE}
462     exit_err "Patch $up already installed!"
463  fi
464
465  while read line
466  do
467    echo $line | grep -q "^SA:"
468    if [ $? -ne 0 ] ; then continue; fi
469    saIdent="`echo $line | cut -d ':' -f 5`"
470    # Look for the right stand-alone update
471    if [ "$saIdent" != "$up" ] ; then continue ; fi
472    saVer=`echo $line | cut -d ':' -f 2`
473    saArch=`echo $line | cut -d ':' -f 3`
474    saType=`echo $line | cut -d ':' -f 4`
475    # Does this update apply to this system arch?
476    if [ "$saArch" != "$ARCH" -a "$saArch" != "noarch" ] ; then
477       rm ${PATCHTMPFILE}
478       exit_err "Patch $up is not for this system arch type!"
479    fi
480    # For this version?
481    if [ "$saVer" != "$SYSVER" ] ; then
482       rm ${PATCHTMPFILE}
483       exit_err "Patch $up is not for this system version!"
484    fi
485
486    # For this system type?
487    if [ "$SYSTYPE" != "$saType" -a "$saType" != "both" ] ; then
488       rm ${PATCHTMPFILE}
489       exit_err "Patch $up is not for this system type!"
490    fi
491
492    # Got here? We have a patch ready to go
493    patchLine="$line"
494    break
495  done < ${PATCHTMPFILE}
496
497  # Did we find the patch?
498  if [ -z "$patchLine" ] ; then
499     rm ${PATCHTMPFILE}
500     exit_err "Patch $up not found!"
501  fi
502
503  # Get the patch details
504  saVer=`echo $patchLine | cut -d ':' -f 2`
505  saArch=`echo $patchLine | cut -d ':' -f 3`
506  saPlat=`echo $patchLine | cut -d ':' -f 4`
507  saIdent="`echo $patchLine | cut -d ':' -f 5`"
508  saDesc="`echo $patchLine | cut -d ':' -f 6`"
509  saUrl="`echo $patchLine | cut -d ':' -f 7`"
510  saCsum="`echo $patchLine | cut -d ':' -f 9`"
511  local FILENAME="`basename $saUrl`"
512
513  # Start downloading the patch
514  touch ${TRIGGERFILE}
515  echo "DOWNLOADING: ${saIdent}"
516  echo "DOWNLOADING: ${saIdent}" >${TRIGGERFILE}
517
518  # Get the file
519  get_file_from_mirrors "/${saUrl}" "${DOWNLOADDIR}/${FILENAME}" "update"
520  if [ $? -ne 0 ] ; then
521     rm ${PATCHTMPFILE}
522     echo "FAILED: ${saIdent}" >${TRIGGERFILE}
523     exit_err "Failed to download: ${saIdent}"
524  fi
525
526  # Check the sha256 checksum
527  if [ "$saCsum" != "`sha256 -q ${DOWNLOADDIR}/${FILENAME} 2>/dev/null`" ]
528  then
529     # Download MD5 doesn't match! Delete the file
530     rm ${PATCHTMPFILE}
531     rm ${DOWNLOADDIR}/${FILENAME}
532     echo "FAILED: ${saIdent}" >${TRIGGERFILE}
533     exit_err "Failed to download: ${saIdent}"
534  else
535     echo "DOWNLOADFINISHED: ${saIdent}"
536     echo "DOWNLOADFINISHED: ${saIdent}" >${TRIGGERFILE}
537  fi
538
539  echo "INSTALLING: ${saIdent}" >${TRIGGERFILE}
540  sleep 1
541
542  # Lets auto-create a new boot-environment before updating
543  create_auto_beadm
544
545  PATCHTMPDIR="`mktemp -d ${DOWNLOADDIR}/patchInstallXXXXX`"
546  rc_halt "tar xvJf ${DOWNLOADDIR}/${FILENAME} -C ${PATCHTMPDIR}" 2>/dev/null
547  PATCHDIR="$PATCHTMPDIR" ; export PATCHDIR
548  cd ${PATCHTMPDIR}
549  sh update.sh
550  if [ $? -eq 0 ]; then
551     touch "${INSDIR}/${SYSVER}/${saIdent}"
552     echo "INSTALLFINISHED: ${saIdent}"
553     echo "INSTALLFINISHED: ${saIdent}" >${TRIGGERFILE}
554  else
555     rm ${PATCHTMPFILE}
556     rm -rf ${PATCHTMPDIR}
557     rm ${DOWNLOADDIR}/${FILENAME}
558     echo "INSTALLFAILED: ${saIdent}" >${TRIGGERFILE}
559     exit_err "INSTALLFAILED: ${saIdent}"
560  fi
561
562  rc_halt "rm -rf ${PATCHTMPDIR}"
563  rc_halt "rm ${DOWNLOADDIR}/${FILENAME}"
564}
565
566rollback_update()
567{
568}
569
570# After installing the kernel and rebooting, this gets run
571finish_major_fbsd_update() {
572
573  PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
574  export PATH
575
576  # Set some status variables
577  PKGSTATUS=0
578  USERPKGSTATUS=0
579  PBISTATUS=0
580  FREEBSDSTATUS=0
581  GRUBSTATUS=0
582  METASTATUS=0
583
584  # Clear any old summary files
585  rm /root/.failed-pkgs 2>/dev/null
586  rm /root/.failed-freebsd 2>/dev/null
587  rm /root/.failed-grub 2>/dev/null
588
589  # Is this a desktop or server?
590  if [ -e "/usr/local/bin/pc-softwaremanager" ] ; then
591     SYSTYPE="desktop"
592  else
593     SYSTYPE="server"
594  fi
595
596  # Lets Mount the image image now
597  clear
598  MD=`mdconfig -a -t vnode -f ${ISOTMP}` ; export MD
599  if [ ! -d "/mnt/iso-update" ] ; then mkdir -p "/mnt/iso-update"; fi
600  mount -t cd9660 /dev/$MD /mnt/iso-update
601  if [ $? -ne 0 ] ; then
602     # This should never happen, but just in case the user removed the ISO
603     # file or something causes mdconfig / mount to fail, lets roll back
604     rm /var/.freebsd-update-finish
605     rm -rf /boot/kernel
606     mv /boot/kernel.preUpgrade /boot/kernel
607
608     echo "ERROR: Could not mount ${ISOTMP}... Did the file get removed?"
609     echo "The update will now be canceled. Please try again later."
610     echo "Press ENTER to continue"
611     read tmp
612     reboot
613     exit 1
614  fi
615
616  # Start the package cleanup process
617  clear
618  echo "Removing packages...This may take a while..."
619  ${PKG_CMD} delete -afy
620  if [ $? -ne 0 ] ; then
621     echo "Warning: Failed to remove all packages"
622     sleep 5
623  fi
624  echo "Done!"
625
626
627  # Setup temp logfile
628  if [ -e "/root/.failed-freebsd" ] ; then rm /root/.failed-freebsd; fi
629  clear
630
631  # We need to be sure and removal the immutable flags
632  echo "Preparing filesystem..."
633  chflags -R noschg /
634
635  distFiles="base doc games lib32"
636  for i in $distFiles
637  do
638    echo -e "Updating world: $i...\c"
639    tar -xvp -f /mnt/iso-update/dist/${i}.txz --exclude ./proc --exclude ./etc/ -C / >> /tmp/.extract.$$ 2>> /tmp/.extract.$$
640    if [ $? -ne 0 ] ; then
641       FREEBSDSTATUS=1
642       echo -e "Warning!"
643       cat /tmp/.extract.$$ >> /root/.failed-freebsd
644       sleep 5
645    else
646       echo -e "Done"
647    fi
648  done
649  rm /tmp/.extract.$$
650
651  # Now time to do all the etcmerge stuff
652  TMPETC="/root/etc-update"
653  if [ -d "$TMPETC" ] ; then rm -rf $TMPETC ; fi
654  mkdir -p $TMPETC
655
656  tar -xvp -f /mnt/iso-update/dist/base.txz -C ${TMPETC} ./etc >/dev/null 2>/dev/null
657  mv ${TMPETC}/etc ${TMPETC}/etc-new
658
659  # Can nuke these two, will be re-generated during etcmerge
660  rm ${TMPETC}/etc-new/spwd.db
661  rm ${TMPETC}/etc-new/pwd.db
662
663  echo "Merging /etc..."
664  /sbin/etcmerge -d ${TMPETC} init  >> /root/.failed-freebsd 2>> /root/.failed-freebsd
665  cd $TMPETC
666
667  # Lets copy the files we always want to clobber
668  for i in ${ETCCLOBBER}
669  do
670     # If this file existed on system, save copy of old version
671     if [ -e "/etc/$i" ] ; then
672        cp /etc/${i} etc-merged/${i}.preUpgrade
673     fi
674     # Overwrite the new version
675     if [ -e "etc-merged/${i}" ] ; then
676        cp etc-new/${i} etc-merged/${i}
677     fi
678  done
679
680  # Lets resolve the conflicts found, use the *new* strings by default
681  # Copy the old file to /etc/<file>.preUpgrade
682  for i in $(cat *.conflicts 2> /dev/null); do
683     if [ ! -e "etc-merged/${i}" ] ; then continue ; fi
684     if egrep -q '^(<<<<<<< |=======$|>>>>>>> )' etc-merged/$i; then
685        cp /etc/${i} etc-merged/${i}.preUpgrade
686
687        # Lets parse out the old, bring in new changes
688        rem=0
689        while read line
690        do
691          echo "$line" | egrep -q '^<<<<<<< '
692          if [ $? -eq 0 ] ; then rem=1 ; continue ; fi
693
694          echo "$line" | egrep -q '^=======$'
695          if [ $? -eq 0 ] ; then rem=0 ; continue ; fi
696
697          echo "$line" | egrep -q '^>>>>>>> '
698          if [ $? -eq 0 ] ; then rem=0 ; continue ; fi
699
700          if [ $rem -eq 0 ] ; then echo "$line" >> etc-merged/${i}.new ; fi
701        done < etc-merged/${i}
702
703        # Copy the fixed file
704        cp -p etc-merged/${i}.new etc-merged/${i}
705        rm etc-merged/${i}.new
706     fi
707  done
708
709  # Now install the merged /etc/ stuff
710  cd $TMPETC
711  /sbin/etcmerge -d ${TMPETC} install >> /root/.failed-freebsd 2>>/root/.failed-freebsd
712  if [ $? -ne 0 ] ; then
713     FREEBSDSTATUS=1
714     echo "Warning: Failed etcmerge install..."
715     sleep 5
716  fi
717
718  # Save the etc-new directory as the old one now
719  rm -rf /var/db/etc
720  cp -r etc-new /var/db/etc
721
722  # Cleanup
723  rm -rf ${TMPETC}
724  rm /sbin/etcmerge
725
726  clear
727
728  # Remove this, causes all kinds of havok during the update
729  if [ -e "/etc/pkg/FreeBSD.conf" ] ; then
730    mv /etc/pkg/FreeBSD.conf /etc/pkg/FreeBSD.conf.dist
731  fi
732
733  clear
734  echo "Starting networking..."
735  echo ""
736  # Enable networking
737  /etc/rc.d/devfs restart
738  /etc/rc.d/netif restart
739  /etc/rc.d/devd start
740  /etc/rc.d/wpa_supplicant start
741  /etc/rc.d/dhclient start
742  sleep 8
743  clear
744
745  # This is super-lame, we can't just remove all packages *except* pkgng, so we have to re-bootstrap
746  # Lets extract the new pkgng we fetched earlier
747  echo "Boot-Strapping PKGNG..."
748  if [ ! -d "/usr/local/etc/pkg/fingerprints/pcbsd/revoked" ] ; then
749     mkdir "/usr/local/etc/pkg/fingerprints/pcbsd/revoked"
750  fi
751  cd /mnt/iso-update/dist/packages/All
752  pkgFile=`ls pkg-[1-9]*`
753  tar xvpf $pkgFile -C / /usr/local/sbin/pkg-static >/dev/null 2>/dev/null
754  /usr/local/sbin/pkg-static add -f $pkgFile
755  if [ $? -ne 0 ] ; then
756     echo "Warning: Failed to re-install PKGNG..."
757     echo "Press ENTER to continue"
758     read tmp
759  fi
760
761
762  # Lets create our fake pcbsd.conf file
763  echo "pcbsd: {
764  url: \"file:///mnt/iso-update/dist/packages\",
765  enabled: true
766}" >  /usr/local/etc/pkg/repos/pcbsd.conf
767
768  # Now update pkgng
769  ${PKG_CMD} update -f
770  if [ $? -ne 0 ] ; then
771     echo "Failed updating pkgng repo..."
772     sleep 5
773  fi
774
775  # Now lets begin re-installing packages
776  if [ "$SYSTYPE" = "desktop" ] ; then
777    echo "Installing desktop packages..."
778    ${PKG_CMD} install -y misc/pcbsd-base
779    if [ $? -ne 0 ] ; then
780       PKGSTATUS=1
781       echo "pcbsd-base" >> /root/.failed-pkgs
782       echo "Warning: Failed to install pcbsd-base!"
783       echo "You will need to manually install this package to re-enable the PC-BSD desktop"
784       echo "Press ENTER to continue"
785       read tmp
786    fi
787    pc-extractoverlay desktop
788  else
789    echo "Installing server packages..."
790    ${PKG_STATIC} install -y misc/trueos-base
791    if [ $? -ne 0 ] ; then
792       PKGSTATUS=1
793       echo "trueos-base" >> /root/.failed-pkgs
794       echo "Warning: Failed to install trueos-base!"
795       echo "You will need to manually install this package for the TrueOS utils."
796       echo "Press ENTER to continue"
797       read tmp
798    fi
799    pc-extractoverlay server
800  fi
801
802  # Now lets try re-installing any user-installed packages
803  clear
804  echo "Re-Installing packages"
805  while read userpkg
806  do
807    # Make sure package isn't already installed
808    ${PKG_CMD} info -e ${userpkg}
809    if [ $? -eq 0 ] ; then continue ; fi
810
811    # Nope, lets try to load it now
812    ${PKG_CMD} install -y ${userpkg}
813    if [ $? -ne 0 ] ; then
814       USERPKGSTATUS=1
815       echo "${userpkg}" >> /root/.failed-user-pkgs
816    fi
817  done < /root/pcbsd-pkg-before-update
818
819  cd /
820
821  # Now lets do the overlay extraction (This cleans up the fake pcbsd.conf)
822  pc-extractoverlay ports
823
824  # Last but not least, lets make sure to re-stamp GRUB in case any loader.conf.pcbsd modules changed
825  grub-mkconfig -o /boot/grub/grub.cfg | tee /root/.failed-grub
826  if [ $? -ne 0 ] ; then
827     GRUBSTATUS=1
828     echo "Warning: Failed running 'grub-mkconfig -o /boot/grub/grub.cfg'"
829     echo "Press ENTER to continue"
830     read tmp
831  fi
832
833
834  # Now lets show a summary
835  clear
836
837  echo "PC-BSD `uname -r` Upgrade Summary - (`date`)" > /root/pcbsd-update-summary
838  echo "-----------------------------------------------------" >> /root/pcbsd-update-summary
839
840  if [ $FREEBSDSTATUS -eq 0 ] ; then
841    echo "FreeBSD: The base-system updated successfully!" >> /root/pcbsd-update-summary
842  else
843    echo "FreeBSD: The base-system failed to install:" >> /root/pcbsd-update-summary
844    cat /root/.failed-freebsd >> /root/pcbsd-update-summary
845  fi
846
847  if [ $PKGSTATUS -eq 0 ] ; then
848    echo "    PKG: All packages updated successfully!" >> /root/pcbsd-update-summary
849  else
850    echo "    PKG: The following packages failed to install:" >> /root/pcbsd-update-summary
851    cat /root/.failed-pkgs >> /root/pcbsd-update-summary
852  fi
853
854  if [ $USERPKGSTATUS -eq 0 ] ; then
855    echo "USERPKG: All packages updated successfully!" >> /root/pcbsd-update-summary
856  else
857    echo "USERPKG: The following user-packages failed to install:" >> /root/pcbsd-update-summary
858    cat /root/.failed-user-pkgs >> /root/pcbsd-update-summary
859  fi
860
861  if [ $GRUBSTATUS -eq 0 ] ; then
862    echo "   GRUB: The GRUB boot-loader menus re-built successfully!" >> /root/pcbsd-update-summary
863  else
864    echo "   GRUB: The GRUB boot-loader menus failed to rebuild:" >> /root/pcbsd-update-summary
865    cat /root/.failed-grub >> /root/pcbsd-update-summary
866  fi
867
868  echo "" >> /root/pcbsd-update-summary
869  echo "Old system information: " >> /root/pcbsd-update-summary
870  echo "/root/pcbsd-pkg-before-update" >> /root/pcbsd-update-summary
871
872  echo "" >> /root/pcbsd-update-summary
873
874  echo "This summary location: /root/pcbsd-update-summary" >> /root/pcbsd-update-summary
875
876  # Clear any old summary files
877  rm /root/.failed-pkgs 2>/dev/null
878  rm /root/.failed-user-pkgs 2>/dev/null
879  rm /root/.failed-grub 2>/dev/null
880  rm /root/.failed-freebsd 2>/dev/null
881
882  more /root/pcbsd-update-summary
883
884  # Cleanup time
885  cd /
886  umount /mnt/iso-update 2>/dev/null
887  mdconfig -d -u $MD 2>/dev/null
888  rm ${ISOTMP} 2>/dev/null
889
890  echo "Press ENTER to reboot"
891  read tmp
892
893  exit 0
894}
895
896# Simple recursive loop to go through and get a list of all package deps for a top level package
897get_dep_origins()
898{
899  grep -q "^$1\$" "${2}.checked" 2>/dev/null
900  if [ $? -eq 0 ] ; then return; fi
901  echo "$1" >> ${2}.checked
902
903  local i
904  for i in `${PKG_CMD} query '%do' ${1}`
905  do
906     echo "$i" >> ${2}
907     get_dep_origins "$i" "$2"
908  done
909}
910
911start_major_fbsd_update() {
912  local rel=`echo $1 | sed 's|fbsd-||g'`
913
914  # Do the disk-space check
915  rZpool="`mount | grep 'on / ' | awk '{print $1}' | cut -d '/' -f 1`"
916  poolFree="`zpool list -H -o free $rZpool`"
917
918  # is space in GB?
919  echo "$poolFree" | grep -q "G"
920  if [ $? -eq 0 ] ; then
921     poolFree="`echo $poolFree | sed 's|G||g'`"
922     if [ $poolFree -lt 10 ] ; then
923        exit_err "Need at least 20GB of free space to continue"
924     fi
925  fi
926
927  # Is space in MB?
928  echo "$poolFree" | grep -q "M"
929  if [ $? -eq 0 ] ; then
930     poolFree="`echo $poolFree | sed 's|M||g'`"
931     if [ $poolFree -lt 10000 ] ; then
932        exit_err "Need at least 20GB of free space to continue"
933     fi
934  fi
935
936  # Grab the ISO file from the mirrors
937  get_file_from_mirrors "/$rel/$ARCH/latest.iso" "$ISOTMP" "iso"
938  get_file_from_mirrors "/$rel/$ARCH/latest.iso.md5" "${ISOTMP}.md5" "iso"
939
940  # Verify the ISO file is good for an update
941  verify_iso_data
942
943  # Lets auto-create a new boot-environment before updating
944  create_auto_beadm
945
946  # Build a list of *all* package origins
947  ${PKG_CMD} query -a '%o' | grep -v "misc/pcbsd-base" \
948        | grep -v "misc/trueos-base" | grep -v "ports-mgmt/pkg" \
949        | sort > /root/pcbsd-pkg-before-update
950
951  # Now install the updated kernel
952  if [ -d "/boot/kernel.preUpgrade" ] ; then
953     rm -rf /boot/kernel.preUpgrade
954  fi
955  mv /boot/kernel /boot/kernel.preUpgrade
956
957  echo "Updating kernel..."
958  tar xf /mnt/iso-update/dist/kernel.txz -C / 2>/dev/null >/dev/null
959  if [ $? -ne 0 ] ; then
960       rm -rf /boot/kernel
961       mv /boot/kernel.preUpgrade /boot/kernel
962       umount /mnt/iso-update
963       mdconfig -d -u $MD
964       rollback_update
965       exit_err "Kernel update failed! (Old kernel restored)"
966  fi
967
968  # Unmount / cleanup ISO
969  umount /mnt/iso-update
970  mdconfig -d -u $MD
971
972  # Touch our marker that we will need to reboot before doing other updates
973  touch /var/.freebsd-update-finish
974  touch /tmp/.fbsdup-reboot
975
976  echo "Major update staged!"
977  echo "Please reboot the system for the updater to continue."
978  exit 0
979}
980
981## Do a fetch of a pristine /etc directory for the three way etcmerge
982fetch_clean_etc()
983{
984  echo "Fetching pristine /etc for merging..."
985  baseTmp="/usr/local/tmp/base.txz.$$"
986  get_file_from_mirrors "/$SYSVER/$ARCH/dist/base.txz" "$baseTmp" "iso"
987  if [ $? -ne 0 ] ; then return 1 ; fi
988
989  rm -rf "/var/db/etc/"
990  echo "Extracting pristine /etc for merging..."
991  tar xvpf ${baseTmp} -C /var/db ./etc >/dev/null 2>/dev/null
992  local err=$?
993  rm ${baseTmp}
994  return $err
995}
996
997## Verify that ISO is suitable for upgrading with
998verify_iso_data()
999{
1000  if [ ! -e "${ISOTMP}" ] ; then
1001     rollback_update
1002     exit_err "ISO fails checksum..."
1003  fi
1004
1005  # Check that the MD5 matches
1006  echo "Checking ISO checksum..."
1007  if [ "`md5 -q $ISOTMP`" != "`cat ${ISOTMP}.md5`" ] ; then
1008     rollback_update
1009     exit_err "ISO fails checksum..."
1010  fi
1011
1012  # Now we need to "mount" the ISO, check its contents
1013  MD=`mdconfig -a -t vnode -f ${ISOTMP}` ; export MD
1014  if [ ! -d "/mnt/iso-update" ] ; then mkdir -p "/mnt/iso-update"; fi
1015  mount -t cd9660 /dev/$MD /mnt/iso-update
1016  if [ $? -ne 0 ] ; then
1017     mdconfig -d -u $MD
1018     rollback_update
1019     exit_err "ISO failed mount..."
1020  fi
1021
1022  # Now we are mounted, verify the dist files exist and can be read
1023  distFiles="base doc games kernel lib32"
1024  for i in $distFiles
1025  do
1026     if [ ! -e "/mnt/iso-update/dist/${i}.txz" ] ; then
1027       umount /mnt/iso-update
1028       mdconfig -d -u $MD
1029       rollback_update
1030       exit_err "ISO missing distfile: /dist/${i}.txz"
1031     fi
1032
1033     echo "Verifying distfile: ${i}.txz"
1034     tar tf "/mnt/iso-update/dist/${i}.txz" >/dev/null 2>/dev/null
1035     if [ $? -ne 0 ] ; then
1036       umount /mnt/iso-update
1037       mdconfig -d -u $MD
1038       rollback_update
1039       exit_err "ISO corrupt distfile: /dist/${i}.txz"
1040     fi
1041  done
1042
1043  # Lets fetch a pristine /etc for merging, don't trust an old one in /var/db
1044  fetch_clean_etc
1045  if [ $? -ne 0 ] ; then
1046     umount /mnt/iso-update
1047     mdconfig -d -u $MD
1048     rollback_update
1049     exit_err "Missing etcmerge directory: /var/db/etc"
1050  fi
1051
1052  # Make sure we have /sbin/etcmerge copied over
1053  cp ${PROGDIR}/etcmerge /sbin/etcmerge
1054  if [ $? -ne 0 ] ; then
1055       umount /mnt/iso-update
1056       mdconfig -d -u $MD
1057       rollback_update
1058       exit_err "Failed setting up etcmerge..."
1059  fi
1060  chmod 755 /sbin/etcmerge
1061}
1062
1063do_install() {
1064        # Make sure we are root and have specified updates to install
1065        if [ `id -u` != "0" ] ; then exit_err "Must be run as root!" ; fi
1066        if [ -z "$1" ] ; then exit_err "No updates specified to install!"; fi
1067
1068        if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1069          pc-systemflag SYSUPDATE UPDATING #set the flag that system is updating
1070        fi
1071        # Begin to update the selected items
1072        for up in `echo $1 | sed 's|,| |g'`
1073        do
1074          # If this is a major update, start it up!
1075          echo $up | grep -q "^fbsd-" 
1076          if [ $? -eq 0 ] ; then
1077            start_major_fbsd_update "$up"
1078            exit 0
1079          elif [ "$up" == "pkg-updates" ] ; then
1080            # Check if this is a pkg-update request or regular patch
1081            start_pkg_updates
1082            continue
1083          else
1084            # Doing regular pcbsd patch
1085            start_pcbsd_patch "${up}"
1086            continue
1087          fi
1088
1089        done
1090        if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1091          pc-systemflag SYSUPDATE SUCCESS #set the flag that system updates finished
1092        fi
1093        # All Finished!
1094        rm ${PATCHTMPFILE}
1095        exit 0
1096}
1097
1098is_net_up() {
1099        ping -c 1 www.pcbsd.org >/dev/null 2>/dev/null
1100        ret=$?
1101        if [ $ret -ne 0 ]; then
1102          if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1103            pc-systemflag NETRESTART ERROR #set the system flag that no internet available
1104          fi
1105        fi
1106        return $ret
1107}
1108
1109sync_pkgconf() {
1110
1111  # Update systems pkgng configuration
1112  setup_pkgng_conf
1113
1114  if [ -n "$INJAIL" ] ; then
1115    # Need to update pkgng config in the jail to match systems
1116    jDir="`jls | grep " $INJAIL " | awk '{print $4}'`"
1117    if [ ! -d "$jDir/usr/local/etc/pkg/repos" ] ; then
1118       mkdir -p ${jDir}/usr/local/etc/pkg/repos
1119    fi
1120    cp /usr/local/etc/pkg/repos/pcbsd.conf ${jDir}/usr/local/etc/pkg/repos/
1121  fi
1122}
1123
1124check_pkgconf() {
1125
1126  if [ -n "$INJAIL" ] ; then
1127    # Update systems pkgng configuration
1128    setup_pkgng_conf
1129
1130    # Need to update pkgng config in the jail to match systems
1131    jDir="`jls | grep " $INJAIL " | awk '{print $4}'`"
1132    diff /usr/local/etc/pkg/repos/pcbsd.conf ${jDir}/usr/local/etc/pkg/repos/pcbsd.conf >/dev/null 2>/dev/null
1133    if [ $? -eq 0 ] ; then
1134       echo "Config OK!"
1135       exit 0
1136    else
1137       exit_err "Config differs from systems"
1138    fi
1139  fi
1140
1141  # Update systems pkgng configuration
1142  setup_pkgng_conf
1143  exit $?
1144}
1145
1146checkup_pkgs() {
1147
1148  # Update the repo DB
1149  rc_halt "${PKG_CMD} update"
1150
1151  ${PKG_CMD} ${PKG_FLAG} upgrade -n >/tmp/.pkgData.$$
1152  if [ $? -ne 0 ] ; then
1153     echo "Error checking for package updates..."
1154     if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1155       pc-systemflag PKGUPDATE ERROR #set the system flag pkg check errored
1156     fi
1157     exit 1
1158  fi
1159
1160  # Check fr updates now
1161  grep -q "Your packages are up to date" /tmp/.pkgData.$$
1162  if [ $? -eq 0 ] ; then
1163     echo "All packages are up to date!"
1164     if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1165       pc-systemflag PKGUPDATE SUCCESS #set the system flag that packages are up to date
1166     fi
1167     rm /tmp/.pkgData.$$
1168     return 0
1169  fi
1170
1171  # Display the pkg update data
1172  cat /tmp/.pkgData.$$
1173  rm /tmp/.pkgData.$$
1174  echo ""
1175  echo "To start the upgrade run \"${0} ${PKG_FLAG} pkgupdate\""
1176  if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1177    pc-systemflag PKGUPDATE UPDATE #set the system flag that updates available
1178  fi
1179  return 0
1180}
1181
1182update_pkgs()
1183{
1184  if [ -n "$1" -a "$1" != "-f" ] ; then
1185     exit_err "Invalid option $1 passed"
1186  fi
1187  if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1188    pc-systemflag PKGUPDATE UPDATING #set the system flag that packages are updating
1189  fi
1190  # Don't use EVENT_PIPE for the update -f command
1191  if [ -n "$EVENT_PIPE" ] ; then
1192     oEP="$EVENT_PIPE" 
1193     unset EVENT_PIPE
1194  fi
1195
1196  # Update the DB first
1197  ${PKG_CMD} ${PKG_FLAG} update -f
1198
1199  # Enable EVENT_PIPE again
1200  if [ -n "$oEP" ] ; then
1201     EVENT_PIPE="$oEP"
1202     unset oEP
1203     export EVENT_PIPE
1204  fi
1205
1206  # Look for conflicts
1207  check_pkg_conflicts "upgrade -FUy $1" "$PKG_FLAG"
1208  if [ $? -ne 0 ] ; then
1209     exit 1
1210  fi
1211
1212  # Create a new boot-environment before doing the pkg update
1213  if [ -z "$INJAIL" ] ; then
1214     create_auto_beadm
1215  fi
1216
1217  # Done with EVENT_PIPE
1218  unset EVENT_PIPE
1219
1220  # Start the package update!
1221  ${PKG_CMD} ${PKG_FLAG} upgrade -U -y ${1}
1222  result=$?
1223
1224  if [ -z "$INJAIL" ] ; then
1225    # Lets now re-extract our overlay data to grab any adjusted port files
1226    pc-extractoverlay ports >/dev/null 2>/dev/null
1227    # Now re-extract overlay files to ensure we do file fixing / massaging
1228    if [ "$SYSTYPE" = "PCBSD" ]; then pc-extractoverlay desktop; fi
1229    if [ "$SYSTYPE" = "TRUEOS" ]; then pc-extractoverlay server; fi
1230
1231    # Lets restamp grub on all ZFS disks and update config
1232    update_grub_boot
1233  fi
1234
1235  if [ $result -ne 0 ] ; then
1236     echo "Failed updating..."
1237    if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1238      pc-systemflag PKGUPDATE UPDATE #set the system flag that updates available
1239    fi
1240  else
1241    if [ -e "/usr/local/bin/pc-systemflag" -a -z "$INJAIL" ]; then
1242      pc-systemflag PKGUPDATE SUCCESS #set the system flag that packages are up to date
1243    fi
1244  fi
1245 
1246  exit $result
1247}
1248
1249# Make sure this is a valid jail
1250set_jail_mode()
1251{
1252        # Check if this is a JID
1253        jls | grep -v "JID" | tr -s ' ' | sed 's,^[ \t]*,,' | grep -q "^$1 "
1254        if [ $? -eq 0 ] ; then
1255                INJAIL="$1"
1256                PKG_FLAG="-j $1"
1257                return
1258        fi
1259       
1260        # Is this a hostname?
1261        line=`jls | grep -v "JID" | tr -s ' ' | sed 's,^[ \t]*,,' | grep -w "$1" | head -n 1`
1262        if [ -n "$line" ] ; then
1263                INJAIL="`echo $line | awk '{print $1}'`"       
1264                PKG_FLAG="-j $INJAIL"
1265                return
1266        fi
1267
1268        exit_err "No such jail: $1"
1269}
1270
1271do_auto_be()
1272{
1273  # User requested a new autobe to be created
1274  create_auto_beadm
1275}
1276
1277if [ "`id -u`" = "0" ] ; then
1278  # Make the installed directory for this version
1279  if [ ! -d "${INSDIR}/${SYSVER}" ] ; then mkdir -p ${INSDIR}/${SYSVER} ; fi
1280
1281  # Make the ignore directory for this version
1282  if [ ! -d "${IGNDIR}/${SYSVER}" ] ; then mkdir -p ${IGNDIR}/${SYSVER} ; fi
1283fi
1284
1285if [ $# -eq 0 ] ; then
1286   show_usage
1287   exit 1
1288fi
1289
1290while [ $# -gt 0 ] ; do
1291
1292   case $1 in
1293          autobe) do_auto_be ;;
1294           check) if [ -n "$INJAIL" ] ; then
1295                     exit_err "Cannot run this inside a jail..."
1296                  fi
1297                  do_fbsdcheck
1298                  get_update_file
1299                  do_check ; break ;;
1300        branches) get_update_file
1301                  list_branches ; break ;;
1302        chbranch) get_update_file
1303                  do_branch "${2}" ; break ;;
1304        pkgcheck) checkup_pkgs ; break ;;
1305        syncconf) sync_pkgconf ; break ;;
1306       confcheck) check_pkgconf ; break ;;
1307       pkgupdate) update_pkgs "$2" ; break ;;
1308finish-major-update) finish_major_fbsd_update ; break ;;
1309         install) if [ -n "$INJAIL" ] ; then
1310                     exit_err "Cannot run this inside a jail..."
1311                  fi
1312                  get_update_file
1313                  do_install "${2}" ; break ;;
1314       -j) shift
1315           set_jail_mode "$1"
1316           ;;
1317        *) show_usage ;;
1318   esac
1319   shift
1320done
1321
1322exit 0
Note: See TracBrowser for help on using the repository browser.