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

releng/10.0
Last change on this file since e7484af was e7484af, checked in by Kris Moore <kris@…>, 6 months ago

Backport pbi fixes to pc-updatemanager

  • Property mode set to 100755
File size: 26.9 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# Default pcbsd.conf file
37PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
38
39# Patchset Data
40PATCHSERVER="`cat ${UPDATECONF} | grep '^UPDATESERVER:' | cut -d ' ' -f 2`"
41PATCHSET="`cat ${UPDATECONF} | grep '^PATCHSET:' | cut -d ' ' -f 2`"
42PATCHFILE="${PATCHSET}.upd"
43PATCHURL="${PATCHSERVER}/${PATCHFILE}"
44PATCHTMPDIR=`mktemp -d /tmp/.sysupdateXXXXXX`
45PATCHTMPFILE="${PATCHTMPDIR}/sysupdate-${SYSVER}.upd"
46
47MUSTAGEDIR="${DOWNLOADDIR}/update-stagedir"
48
49# Enable ftp passive mode for file transfers
50FTP_PASSIVE_MODE="YES" ; export FTP_PASSIVE_MODE
51
52if [ ! -d "${DOWNLOADDIR}" ]; then mkdir -p ${DOWNLOADDIR}; fi
53
54
55# Trigger File for Tray Application
56TRIGGERFILE="/tmp/.sysupdatetraytrigger"
57
58DBDIR="/var/db/pc-updatemanager"
59INSDIR="${DBDIR}/installed"
60IGNDIR="${DBDIR}/ignored"
61
62
63######################################################################
64# Done with config values
65######################################################################
66
67show_usage() {
68        echo "$0 - Usage
69----
70  branches              - List available system branches
71  chbranch <tag>        - Change to new system branch
72  check                 - Check for system updates
73  install <tag>,<tag2>  - Install system updates
74  pkgcheck              - Check for updates to packages
75  pkgupdate             - Install packages updates
76"       
77
78        exit 1
79}
80
81get_update_file() {
82
83  # Now fetch the update file
84  get_file "${PATCHURL}" "${PATCHTMPFILE}" 1 >/dev/null 2>/dev/null
85  if [ $? -ne 0 ] ; then
86     rm ${PATCHTMPFILE} 2>/dev/null
87     is_net_up
88     if [ $? -eq 0 ] ; then
89       echo "No updates available for $SYSVER!" ; exit 0
90     else
91       exit_err "Could not contact update server!"
92     fi
93  fi
94
95  # Now fetch the update file signature
96  get_file "${PATCHURL}.sha1" "${PATCHTMPFILE}.sha1" 1 >/dev/null 2>/dev/null
97  if [ $? -ne 0 ] ; then
98     rm ${PATCHTMPFILE}.sha1 2>/dev/null
99     is_net_up
100     if [ $? -eq 0 ] ; then
101       echo "No updates available for $SYSVER!" ; exit 0
102     else
103       exit_err "Could not contact update server!"
104     fi
105  fi
106
107  # Lets verify the signature of the file
108  openssl dgst -sha1 -verify ${SKEY} \
109        -signature ${PATCHTMPFILE}.sha1 \
110        ${PATCHTMPFILE} >/dev/null 2>/dev/null
111  if [ $? -ne 0 ] ; then
112     rm ${PATCHTMPFILE} 2>/dev/null
113     rm ${PATCHTMPFILE}.sha1 2>/dev/null
114     exit_err "Update file failed verification..."
115  fi
116
117  # Done with the signature we can discard
118  rm ${PATCHTMPFILE}.sha1
119
120}
121
122do_branch() {
123  up="$1"
124
125  # Setup our variable to catch if we have a bad branch
126  BRANCHFOUND="0" 
127
128  while read line
129  do
130     echo $line | grep -q "^BRANCHES:"
131     if [ $? -eq 0 ] ; then
132        for i in `echo $line | cut -d ':' -f 2 | sed 's|,| |g'`
133        do
134          if [ "$i" != "$up" ] ; then continue ;fi
135          if [ "`uname -r | cut -d '-' -f 1-2`" = "$up" ] ; then
136             echo "You are already on this branch!"
137             BRANCHFOUND="1"
138             continue;
139          fi
140          start_major_fbsd_update "fbsd-$up"
141          BRANCHFOUND="1"
142          break
143        done
144     fi
145  done < ${PATCHTMPFILE}
146
147  # If no patches
148  if [ "${BRANCHFOUND}" = "0" ]; then 
149     # No available updates
150     echo "Unknown branch ${1}"
151  fi
152
153  rm ${PATCHTMPFILE}
154
155};
156
157list_branches() {
158  # Setup our variable, we have no branches so far
159  BRANCHFOUND="0" 
160
161  while read line
162  do
163     echo $line | grep -q "^BRANCHES:"
164     if [ $? -eq 0 ] ; then
165        echo "Available branches:"
166        echo "* = Current Branch"
167        echo "----------------------------------"
168        echo $line | cut -d ':' -f 2 | sed 's|,|\
169|g' | while read branch
170        do
171                if [ "`uname -r | cut -d '-' -f 1-2`" = "$branch" ] ; then
172                        echo "$branch *"
173                else
174                        echo "$branch"
175                fi
176        done
177        echo ""
178        echo "To change branches run: ${0} chbranch <branch>"
179        BRANCHFOUND="1"
180        continue
181     fi
182  done < ${PATCHTMPFILE}
183
184  # If no patches
185  if [ "${BRANCHFOUND}" = "0" ]; then 
186     # No available updates
187     echo "No branches currently available!"
188  fi
189
190  rm ${PATCHTMPFILE}
191
192};
193
194do_check() {
195  # Setup our variable, we have no patches so far
196  PATCHFOUND="0" 
197
198  while read line
199  do
200     echo $line | grep -q "^MU:"
201     if [ $? -eq 0 ] ; then
202        parse_mu_update_line "$line"
203        continue
204     fi
205     echo $line | grep -q "^SA:"
206     if [ $? -eq 0 ] ; then
207        parse_sa_update_line "$line"
208        continue
209     fi
210  done < ${PATCHTMPFILE}
211
212  # If no patches
213  if [ "${PATCHFOUND}" = "0" ]; then 
214     # No available updates
215     echo "Your system is up to date!"
216  fi
217
218  rm ${PATCHTMPFILE}
219
220};
221
222parse_mu_update_line()
223{
224   local line="$1"
225
226   # Check if this is a major update we can install
227   local sysUpOVer=`echo $line | cut -d ':' -f 2`
228   local sysUpNVer=`echo $line | cut -d ':' -f 3`
229
230   # Is this an update for our version?
231   if [ "$SYSVER" != "$sysUpOVer" ] ; then return; fi
232
233   if [ $PATCHFOUND -eq 0 ] ; then
234      echo ""
235      echo "The following updates are available:"
236      echo "------------------------------------"
237   fi
238   echo "NAME: System Update to ${sysUpNVer}" 
239   echo "TYPE: SYSUPDATE" 
240   echo "TAG: fbsd-${sysUpNVer}"
241   echo "VERSION: ${sysUpNVer}" 
242   echo ""
243   echo "To install: \"pc-updatemanager install fbsd-${sysUpNVer}\""
244   echo ""
245   echo ""
246
247   PATCHFOUND="`expr ${PATCHFOUND} + 1`" 
248}
249
250parse_sa_update_line()
251{
252   local line="$1"
253
254   # Check if this is an update we can install
255   local saVer=`echo $line | cut -d ':' -f 2`
256   local saArch=`echo $line | cut -d ':' -f 3`
257   local saType=`echo $line | cut -d ':' -f 4`
258   local saIdent="`echo $line | cut -d ':' -f 5`"
259
260   # For this version?
261   if [ "$SYSVER" != "$saVer" ] ; then return ; fi
262
263   # For this system arch?
264   if [ "$ARCH" != "$saArch" -a "$saArch" != "noarch" ] ; then return ; fi
265
266   # For this system type?
267   if [ "$SYSTYPE" != "$saType" -a "$saType" != "both" ] ; then return ; fi
268
269   # Already installed?
270   if [ -e "${INSDIR}/${SYSVER}/$saIdent" ] ; then return ; fi
271
272   if [ $PATCHFOUND -eq 0 ] ; then
273      echo ""
274      echo "The following updates are available:"
275      echo "------------------------------------"
276   fi
277   local saDesc="`echo $line | cut -d ':' -f 6`"
278   local saSize=`echo $line | cut -d ':' -f 8`
279   local saDetail="http://trac.pcbsd.org`echo $line | cut -d ':' -f 10`"
280   local saDate="`echo $line | cut -d ':' -f 11`"
281
282   echo "NAME: ${saDesc}" 
283   echo "TYPE: PATCH" 
284   echo "TAG: ${saIdent}"
285   echo "DETAILS: ${saDetail}"
286   echo "DATE: ${saDate}"
287   echo "SIZE: ${saSize}Mb" 
288   echo " "
289   echo "To install: \"pc-updatemanager install ${saIdent}\""
290   echo " "
291
292   PATCHFOUND="`expr ${PATCHFOUND} + 1`" 
293}
294
295start_pcbsd_patch() {
296  local up="$1"
297  local saIdent=""
298  local saVer=""
299  local saArch=""
300  local saPlat=""
301  local saUrl=""
302  local saDesc=""
303  local saCsum=""
304  local patchLine=""
305  if [ -e "${INSDIR}/${SYSVER}/${up}" ]; then
306     rm ${PATCHTMPFILE}
307     exit_err "Patch $up already installed!"
308  fi
309
310  while read line
311  do
312    echo $line | grep -q "^SA:"
313    if [ $? -ne 0 ] ; then continue; fi
314    saIdent="`echo $line | cut -d ':' -f 5`"
315    # Look for the right stand-alone update
316    if [ "$saIdent" != "$up" ] ; then continue ; fi
317    saVer=`echo $line | cut -d ':' -f 2`
318    saArch=`echo $line | cut -d ':' -f 3`
319    saType=`echo $line | cut -d ':' -f 4`
320    # Does this update apply to this system arch?
321    if [ "$saArch" != "$ARCH" -a "$saArch" != "noarch" ] ; then
322       rm ${PATCHTMPFILE}
323       exit_err "Patch $up is not for this system arch type!"
324    fi
325    # For this version?
326    if [ "$saVer" != "$SYSVER" ] ; then
327       rm ${PATCHTMPFILE}
328       exit_err "Patch $up is not for this system version!"
329    fi
330
331    # For this system type?
332    if [ "$SYSTYPE" != "$saType" -a "$saType" != "both" ] ; then
333       rm ${PATCHTMPFILE}
334       exit_err "Patch $up is not for this system type!"
335    fi
336
337    # Got here? We have a patch ready to go
338    patchLine="$line"
339    break
340  done < ${PATCHTMPFILE}
341
342  # Did we find the patch?
343  if [ -z "$patchLine" ] ; then
344     rm ${PATCHTMPFILE}
345     exit_err "Patch $up not found!"
346  fi
347
348  # Get the patch details
349  saVer=`echo $patchLine | cut -d ':' -f 2`
350  saArch=`echo $patchLine | cut -d ':' -f 3`
351  saPlat=`echo $patchLine | cut -d ':' -f 4`
352  saIdent="`echo $patchLine | cut -d ':' -f 5`"
353  saDesc="`echo $patchLine | cut -d ':' -f 6`"
354  saUrl="`echo $patchLine | cut -d ':' -f 7`"
355  saCsum="`echo $patchLine | cut -d ':' -f 9`"
356  local FILENAME="`basename $saUrl`"
357
358  # Start downloading the patch
359  touch ${TRIGGERFILE}
360  echo "DOWNLOADING: ${saIdent}"
361  echo "DOWNLOADING: ${saIdent}" >${TRIGGERFILE}
362
363  # Get the file
364  get_file_from_mirrors "/${saUrl}" "${DOWNLOADDIR}/${FILENAME}" "update"
365  if [ $? -ne 0 ] ; then
366     rm ${PATCHTMPFILE}
367     echo "FAILED: ${saIdent}" >${TRIGGERFILE}
368     exit_err "Failed to download: ${saIdent}"
369  fi
370
371  # Check the sha256 checksum
372  if [ "$saCsum" != "`sha256 -q ${DOWNLOADDIR}/${FILENAME} 2>/dev/null`" ]
373  then
374     # Download MD5 doesn't match! Delete the file
375     rm ${PATCHTMPFILE}
376     rm ${DOWNLOADDIR}/${FILENAME}
377     echo "FAILED: ${saIdent}" >${TRIGGERFILE}
378     exit_err "Failed to download: ${saIdent}"
379  else
380     echo "DOWNLOADFINISHED: ${saIdent}"
381     echo "DOWNLOADFINISHED: ${saIdent}" >${TRIGGERFILE}
382  fi
383
384  echo "INSTALLING: ${saIdent}" >${TRIGGERFILE}
385  sleep 1
386
387  PATCHTMPDIR="`mktemp -d ${DOWNLOADDIR}/patchInstallXXXXX`"
388  rc_halt "tar xvJf ${DOWNLOADDIR}/${FILENAME} -C ${PATCHTMPDIR}" 2>/dev/null
389  PATCHDIR="$PATCHTMPDIR" ; export PATCHDIR
390  cd ${PATCHTMPDIR}
391  sh update.sh
392  if [ $? -eq 0 ]; then
393     touch "${INSDIR}/${SYSVER}/${saIdent}"
394     echo "INSTALLFINISHED: ${saIdent}"
395     echo "INSTALLFINISHED: ${saIdent}" >${TRIGGERFILE}
396  else
397     rm ${PATCHTMPFILE}
398     rm -rf ${PATCHTMPDIR}
399     rm ${DOWNLOADDIR}/${FILENAME}
400     echo "INSTALLFAILED: ${saIdent}" >${TRIGGERFILE}
401     exit_err "INSTALLFAILED: ${saIdent}"
402  fi
403
404  rc_halt "rm -rf ${PATCHTMPDIR}"
405  rc_halt "rm ${DOWNLOADDIR}/${FILENAME}"
406}
407
408rollback_update()
409{
410  cp /tmp/pcbsd.conf.preUpdate.$$ /usr/local/etc/pkg/repos/pcbsd.conf
411}
412
413# After installing the kernel and rebooting, this gets run
414finish_major_fbsd_update() {
415
416  PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
417  export PATH
418
419  # Set some status variables
420  PKGSTATUS=0
421  USERPKGSTATUS=0
422  PBISTATUS=0
423  FREEBSDSTATUS=0
424  GRUBSTATUS=0
425  METASTATUS=0
426
427  # Clear any old summary files
428  rm /root/.failed-pkgs 2>/dev/null
429  rm /root/.failed-meta 2>/dev/null
430  rm /root/.failed-pbi 2>/dev/null
431  rm /root/.failed-freebsd 2>/dev/null
432  rm /root/.failed-grub 2>/dev/null
433
434  # Is this a desktop or server?
435  if [ -e "/usr/local/bin/pc-softwaremanager" ] ; then
436     SYSTYPE="desktop"
437  else
438     SYSTYPE="server"
439  fi
440
441  # Remove all PBIs
442  clear
443  echo "Removing PBIs..."
444  while read line
445  do
446    pbi=`echo $line | cut -d ' ' -f 1`
447    user=`echo $line | cut -d ' ' -f 2`
448
449    echo "Removing: ${pbi}"
450    if [ "$user" != "root" ] ; then
451      su $user -c "pbi_icon del-desktop $pbi"
452      su $user -c "pbi_icon del-menu $pbi"
453      su $user -c "pbi_icon del-mime $pbi"
454      su $user -c "pbi_icon del-pathlnk $pbi"
455      su $user -c "pbi_delete $pbi"
456      result=$?
457    else
458      pbi_icon del-desktop $pbi
459      pbi_icon del-menu $pbi
460      pbi_icon del-mime $pbi
461      pbi_icon del-pathlnk $pbi
462      pbi_delete $pbi >/dev/null 2>/dev/null
463      result=$?
464    fi
465    if [ $result -ne 0 ] ; then
466       echo "Warning: Failed to remove: $pbi"
467       sleep 5
468    fi
469  done < /root/pcbsd-pbi-before-update
470  echo "Done!"
471
472  # Start the package cleanup process
473  clear
474  echo "Removing packages...This may take a while...\c"
475  pkg delete -afy
476  if [ $? -ne 0 ] ; then
477     echo "Warning: Failed to remove all packages"
478     sleep 5
479  fi
480  echo "Done!"
481
482  # Start the freebsd-update process
483  clear
484  echo "Installing FreeBSD updates... Please wait..."
485  freebsd-update --non-interactive install | tee /root/.failed-freebsd
486  if [ $? -ne 0 ] ; then
487     echo "Warning: Failed running freebsd-update install!"
488     echo "Press ENTER to continue"
489     FREEBSDSTATUS=1
490     read tmp
491  fi
492  clear
493
494  # Remove this, causes all kinds of havok during the update
495  if [ -e "/etc/pkg/FreeBSD.conf" ] ; then
496    mv /etc/pkg/FreeBSD.conf /etc/pkg/FreeBSD.conf.dist
497  fi
498
499  clear
500  echo "Starting networking..."
501  echo ""
502  # Enable networking
503  /etc/rc.d/devfs restart
504  /etc/rc.d/netif restart
505  /etc/rc.d/devd start
506  /etc/rc.d/wpa_supplicant start
507  /etc/rc.d/dhclient start
508  sleep 8
509  clear
510
511  # This is super-lame, we can't just remove all packages *except* pkgng, so we have to re-bootstrap
512  # Lets extract the new pkgng we fetched earlier
513  echo "Boot-Strapping PKGNG..."
514  if [ ! -d "/usr/local/etc/pkg/fingerprints/pcbsd/revoked" ] ; then
515     mkdir "/usr/local/etc/pkg/fingerprints/pcbsd/revoked"
516  fi
517  cd /
518  tar xvpf /usr/local/tmp/pkg.txz /usr/local/sbin/pkg-static >/dev/null 2>/dev/null
519  /usr/local/sbin/pkg-static install -y ports-mgmt/pkg
520  if [ $? -ne 0 ] ; then
521     echo "Warning: Failed to re-install PKGNG..."
522     echo "Press ENTER to continue"
523     read tmp
524  fi
525
526  # Lets update the pkgng repo
527  pkg-static update -f
528
529  # Now lets begin re-installing packages
530  if [ "$SYSTYPE" = "desktop" ] ; then
531    echo "Installing desktop packages..."
532    pkg-static install -y pcbsd-base
533    if [ $? -ne 0 ] ; then
534       PKGSTATUS=1
535       echo "pcbsd-base" >> /root/.failed-pkgs
536       echo "Warning: Failed to install pcbsd-base!"
537       echo "You will need to manually install this package to re-enable the PC-BSD desktop"
538       echo "Press ENTER to continue"
539       read tmp
540    fi
541    pc-extractoverlay desktop
542  else
543    echo "Installing server packages..."
544    pkg-static install -y trueos-base
545    if [ $? -ne 0 ] ; then
546       PKGSTATUS=1
547       echo "trueos-base" >> /root/.failed-pkgs
548       echo "Warning: Failed to install trueos-base!"
549       echo "You will need to manually install this package for the TrueOS utils."
550       echo "Press ENTER to continue"
551       read tmp
552    fi
553    pc-extractoverlay server
554  fi
555
556  # Start pbid, so that by the time meta-packages are done, we have a full index
557  rm /var/db/pbi/index/*
558  /usr/local/etc/rc.d/pbid start >/dev/null 2>/dev/null
559
560  clear
561
562  clear
563  echo "Re-Installing meta-packages"
564  while read newmeta
565  do
566    pc-metapkgmanager add $newmeta
567    if [ $? -ne 0 ] ; then
568       METASTATUS=1
569       echo "$newmeta" >> /root/.failed-meta
570       echo "Warning: Failed to re-install meta-package: $newmeta"
571       echo "Press ENTER to continue"
572       read tmp
573    fi
574  done < /root/pcbsd-meta-before-update
575
576  # Now lets try re-installing any user-installed packages
577  clear
578  echo "Re-Installing user-installed packages"
579  while read userpkg
580  do
581    # Make sure package isn't already installed
582    pkg-static info -e ${userpkg}
583    if [ $? -eq 0 ] ; then continue ; fi
584
585    # Nope, lets try to load it now
586    pkg-static install -y ${userpkg}
587    if [ $? -ne 0 ] ; then
588       USERPKGSTATUS=1
589       echo "${userpkg}" >> /root/.failed-user-pkgs
590    fi
591  done < /root/pcbsd-userpkgs-before-update
592
593  # Now lets re-load any PBI files
594  clear
595  echo "Re-Installing PBIs"
596  while read line
597  do
598    newpbi=`echo $line | cut -d ' ' -f 1`
599    user=`echo $line | cut -d ' ' -f 2`
600    shortpbi="`echo $newpbi | rev | cut -d '-' -f 3- | rev`"
601
602    # Re-install the PBI as user or root depending on how it was installed
603    if [ "$user" != "root" ] ; then
604      su $user -c "pbi_add -r $shortpbi"
605      result=$?
606    else
607      pbi_add -r $shortpbi
608      result=$?
609    fi
610    if [ $result -ne 0 ] ; then
611       PBISTATUS=1
612       echo "$shortpbi" >> /root/.failed-pbi
613       echo "Warning: Failed to re-install PBI: $shortpbi"
614       echo "Press ENTER to continue"
615       read tmp
616    else
617       # Re-add menu / desktop stuff
618       if [ "$user" != "root" ] ; then
619         su $user -c "pbi_icon add-pathlnk $shortpbi"
620         su $user -c "pbi_icon add-desktop $shortpbi"
621         su $user -c "pbi_icon add-menu $shortpbi"
622         su $user -c "pbi_icon add-mime $shortpbi"
623       else
624         pbi_icon add-pathlnk $shortpbi
625         pbi_icon add-desktop $shortpbi
626         pbi_icon add-menu $shortpbi
627         pbi_icon add-mime $shortpbi
628       fi
629    fi
630  done < /root/pcbsd-pbi-before-update
631
632  # Last but not least, lets make sure to re-stamp GRUB in case any loader.conf.pcbsd modules changed
633  grub-mkconfig -o /boot/grub/grub.cfg | tee /root/.failed-grub
634  if [ $? -ne 0 ] ; then
635     GRUBSTATUS=1
636     echo "Warning: Failed running 'grub-mkconfig -o /boot/grub/grub.cfg'"
637     echo "Press ENTER to continue"
638     read tmp
639  fi
640
641
642  # Now lets show a summary
643  clear
644
645  echo "PC-BSD `uname -r` Upgrade Summary - (`date`)" > /root/pcbsd-update-summary
646  echo "-----------------------------------------------------" >> /root/pcbsd-update-summary
647
648  if [ $FREEBSDSTATUS -eq 0 ] ; then
649    echo "FreeBSD: The base-system updated successfully!" >> /root/pcbsd-update-summary
650  else
651    echo "FreeBSD: The base-system failed to install:" >> /root/pcbsd-update-summary
652    cat /root/.failed-freebsd >> /root/pcbsd-update-summary
653  fi
654
655  echo "" >> /root/pcbsd-update-summary
656
657  if [ $PKGSTATUS -eq 0 ] ; then
658    echo "PKG: All packages updated successfully!" >> /root/pcbsd-update-summary
659  else
660    echo "PKG: The following packages failed to install:" >> /root/pcbsd-update-summary
661    cat /root/.failed-pkgs >> /root/pcbsd-update-summary
662  fi
663
664  echo "" >> /root/pcbsd-update-summary
665
666  if [ $USERPKGSTATUS -eq 0 ] ; then
667    echo "USERPKG: All packages updated successfully!" >> /root/pcbsd-update-summary
668  else
669    echo "USERPKG: The following user-packages failed to install:" >> /root/pcbsd-update-summary
670    cat /root/.failed-user-pkgs >> /root/pcbsd-update-summary
671  fi
672
673  echo "" >> /root/pcbsd-update-summary
674
675  if [ $METASTATUS -eq 0 ] ; then
676    echo "META: All meta-packages updated successfully!" >> /root/pcbsd-update-summary
677  else
678    echo "META: The following meta-packages failed to install:" >> /root/pcbsd-update-summary
679    cat /root/.failed-meta >> /root/pcbsd-update-summary
680  fi
681
682  echo "" >> /root/pcbsd-update-summary
683
684  if [ $PBISTATUS -eq 0 ] ; then
685    echo "PBI: All PBIs updated successfully!" >> /root/pcbsd-update-summary
686  else
687    echo "PBI: The following PBIs failed to install:" >> /root/pcbsd-update-summary
688    cat /root/.failed-pbi >> /root/pcbsd-update-summary
689  fi
690
691  echo "" >> /root/pcbsd-update-summary
692
693  if [ $GRUBSTATUS -eq 0 ] ; then
694    echo "GRUB: The GRUB boot-loader menus re-built successfully!" >> /root/pcbsd-update-summary
695  else
696    echo "GRUB: The GRUB boot-loader menus failed to rebuild:" >> /root/pcbsd-update-summary
697    cat /root/.failed-grub >> /root/pcbsd-update-summary
698  fi
699
700  echo "" >> /root/pcbsd-update-summary
701  echo "Old system information: " >> /root/pcbsd-update-summary
702  echo "/root/pcbsd-pkg-before-update" >> /root/pcbsd-update-summary
703  echo "/root/pcbsd-pbi-before-update" >> /root/pcbsd-update-summary
704  echo "/root/pcbsd-meta-before-update" >> /root/pcbsd-update-summary
705
706  echo "" >> /root/pcbsd-update-summary
707
708  echo "This summary location: /root/pcbsd-update-summary" >> /root/pcbsd-update-summary
709
710  # Clear any old summary files
711  rm /root/.failed-pkgs 2>/dev/null
712  rm /root/.failed-user-pkgs 2>/dev/null
713  rm /root/.failed-meta 2>/dev/null
714  rm /root/.failed-pbi 2>/dev/null
715  rm /root/.failed-grub 2>/dev/null
716  rm /root/.failed-freebsd 2>/dev/null
717
718  more /root/pcbsd-update-summary
719
720  echo "Press ENTER to reboot"
721  read tmp
722
723  exit 0
724}
725
726# Simple recursive loop to go through and get a list of all package deps for a top level package
727get_dep_origins()
728{
729  grep -q "^$1\$" "${2}.checked" 2>/dev/null
730  if [ $? -eq 0 ] ; then return; fi
731  echo "$1" >> ${2}.checked
732
733  local i
734  for i in `pkg query '%do' ${1}`
735  do
736     echo "$i" >> ${2}
737     get_dep_origins "$i" "$2"
738  done
739}
740
741start_major_fbsd_update() {
742  local rel=`echo $1 | sed 's|fbsd-||g'`
743
744  # Save the repo file
745  cp /usr/local/etc/pkg/repos/pcbsd.conf /tmp/pcbsd.conf.preUpdate.$$
746
747  # Set the new pcbsd.conf file to the new repo
748  local arch=`uname -m`
749  echo "pcbsd: {
750        url: "http://pkg.cdn.pcbsd.org/$rel/$arch",
751        signature_type: "fingerprints",
752        fingerprints: "/usr/local/etc/pkg/fingerprints/pcbsd",
753        enabled: true
754       }" > /usr/local/etc/pkg/repos/pcbsd.conf
755
756  # Lets backup old pkgng
757  oPkg=`pkg info pkg | head -n 1 | awk '{print $1}'`
758  pkg create -o /usr/local/tmp/ ${oPkg}
759  if [ -e "/usr/local/tmp/oldPkg.txz" ] ; then rm /usr/local/tmp/oldPkg.txz; fi
760  mv /usr/local/tmp/${oPkg}.txz /usr/local/tmp/oldPkg.txz
761
762  # Lets download the new pkgng for this release
763  if [ -e "/usr/local/tmp/pkg.txz" ] ; then rm /usr/local/tmp/pkg.txz; fi
764  get_file_from_mirrors "/packages/$rel/$arch/Latest/pkg.txz" "/usr/local/tmp/pkg.txz" "pkg"
765  if [ $? -ne 0 ] ; then
766     rollback_update
767     exit_err "Failed downloading pkgng update..."
768  fi
769
770  # Now lets build some lists of what is present on this system now
771  pkg info > /root/pcbsd-pkg-before-update
772  pbi_info > /root/pcbsd-pbi-before-update.tmp
773  pc-metapkgmanager list-installed > /root/pcbsd-meta-before-update
774
775  # Figure out which user had installed which PBIs and save this list
776  while read line
777  do
778     insBy=`pbi_info -v $line | grep "InstalledBy:" | cut -d ' ' -f 2`
779     if [ -z "$insBy" ] ; then
780        echo "Unable to get UserName for installed PBI: $line"
781        continue
782     fi
783     echo "$line $insBy" >> /root/pcbsd-pbi-before-update
784  done < /root/pcbsd-pbi-before-update.tmp
785  touch /root/pcbsd-pbi-before-update
786  rm /root/pcbsd-pbi-before-update.tmp
787
788  # Figure out a list of user-installed packages to try and re-install on the updated system
789  echo "Building a list of user-installed packages... Please wait..."
790  local mPkgFile="/tmp/.mPkgDList.$$"
791  local mOriginFile="/tmp/.mPkgOList.$$"
792  rm $mPkgFile 2>/dev/null
793  echo "ports-mgmt/pkg" >> ${mPkgFile}
794  if [ -e "/usr/local/bin/pc-softwaremanager" ] ; then
795     echo "pcbsd-base" >> ${mPkgFile}
796  else
797     echo "trueos-base" >> ${mPkgFile}
798  fi
799  while read mpkg
800  do
801     pc-metapkgmanager pkgdeps $mpkg >/dev/null 2>/dev/null
802     if [ $? -ne 0 ] ; then continue ; fi
803     pc-metapkgmanager pkgdeps $mpkg >> $mPkgFile
804  done < /root/pcbsd-meta-before-update
805
806  # Now sort out the list of depends for our meta-pkgs
807  while read mpkg
808  do
809     #echo "Finding package dependencies of ${mpkg}.."
810     pkg query '%o' $mpkg >> ${mOriginFile}
811     get_dep_origins "$mpkg" "$mOriginFile"
812  done < ${mPkgFile}
813  rm ${mPkgFile}
814
815  echo "Building list of user-installed packages..."
816  # Sort the origins file
817  cat ${mOriginFile} | sort | uniq > ${mOriginFile}.new
818  mv ${mOriginFile}.new ${mOriginFile}
819
820  # Build a list of *all* package origins
821  pkg query -a '%o' | sort > ${mOriginFile}.system
822
823  # Save a list of packages that the user installed from elsewhere than our meta-packages
824  diff ${mOriginFile} ${mOriginFile}.system | grep '>' | awk '{print $2}' > /root/pcbsd-userpkgs-before-update
825  rm ${mOriginFile}.system
826  rm ${mOriginFile}
827
828  # Download update files from freebsd-update
829  freebsd-update --non-interactive -r "$rel" upgrade
830  if [ $? -ne 0 ] ; then
831     rollback_update
832     exit_err "Failed running \"freebsd-update -r $rel upgrade\"..."
833  fi
834
835  # Touch our marker that we will need to reboot before doing other updates
836  touch /tmp/.fbsdup-reboot
837
838  # Now install freebsd-update files
839  freebsd-update --non-interactive install
840  if [ $? -ne 0 ] ; then
841     rollback_update
842     exit_err "Failed running \"freebsd-update install\"..."
843  fi
844
845  # Remove backup repo file
846  rm /tmp/pcbsd.conf.preUpdate.$$
847
848  echo "Major update finished!" 
849  echo "Please reboot the system for changes to take effect." 
850  exit 0
851}
852
853do_install() {
854        # Make sure we are root and have specified updates to install
855        if [ `id -u` != "0" ] ; then exit_err "Must be run as root!" ; fi
856        if [ -z "$1" ] ; then exit_err "No updates specified to install!"; fi
857
858        # Begin to update the selected items
859        for up in `echo $1 | sed 's|,| |g'`
860        do
861          # If this is a major update, start it up!
862          echo $up | grep -q "^fbsd-" 
863          if [ $? -eq 0 ] ; then
864            start_major_fbsd_update "$up"
865            exit 0
866          elif [ "$up" == "pkg-updates" ] ; then
867            # Check if this is a pkg-update request or regular patch
868            start_pkg_updates
869            continue
870          else
871            # Doing regular pcbsd patch
872            start_pcbsd_patch "${up}"
873            continue
874          fi
875
876        done 
877
878        # All Finished!
879        rm ${PATCHTMPFILE}
880        exit 0
881}
882
883is_net_up() {
884        ping -c 1 www.pcbsd.org >/dev/null 2>/dev/null
885        return $?
886}
887
888checkup_pkgs() {
889
890  # Update the repo DB
891  rc_halt "pkg-static update"
892
893  pkg-static upgrade -n >/tmp/.pkgData.$$
894  if [ $? -ne 0 ] ; then
895     echo "Error checking for package updates..."
896     exit 1
897  fi
898
899  # Check fr updates now
900  grep -q "Upgrading" /tmp/.pkgData.$$
901  if [ $? -ne 0 ] ; then
902     echo "All packages are up to date!"
903     rm /tmp/.pkgData.$$
904     return 0
905  fi
906
907  # Display the pkg update data
908  cat /tmp/.pkgData.$$
909  rm /tmp/.pkgData.$$
910  echo ""
911  echo "To start the upgrade run \"${0} pkgupdate\""
912  return 0
913}
914
915update_pkgs()
916{
917  if [ -n "$1" -a "$1" != "-f" ] ; then
918     exit_err "Invalid option $1 passed"
919  fi
920
921  # Update the DB first
922  pkg-static update -f
923
924  # Look for conflicts
925  check_pkg_conflicts "upgrade -FUy $1"
926  if [ $? -ne 0 ] ; then
927     exit 1
928  fi
929
930  # Start the package update!
931  pkg-static upgrade -U -y ${1}
932  result=$?
933
934  # Lets now re-extract our overlay data to grab any adjusted port files
935  pc-extractoverlay ports >/dev/null 2>/dev/null
936
937  # Now re-extract overlay files to ensure we do file fixing / massaging
938  if [ "$SYSTYPE" = "PCBSD" ]; then
939    pc-extractoverlay desktop
940  fi
941  if [ "$SYSTYPE" = "TRUEOS" ]; then
942    pc-extractoverlay server
943  fi
944
945  if [ $result -ne 0 ] ; then
946     echo "Failed updating..."
947  fi
948  exit $result
949}
950
951# Check if we have an update folder for the version we are on
952if [ ! -d "${AVAILDIR}/${SYSVER}" ] ; then mkdir -p ${AVAILDIR}/${SYSVER} ; fi
953
954if [ "`id -u`" = "0" ] ; then
955  # Make the installed directory for this version
956  if [ ! -d "${INSDIR}/${SYSVER}" ] ; then mkdir -p ${INSDIR}/${SYSVER} ; fi
957
958  # Make the ignore directory for this version
959  if [ ! -d "${IGNDIR}/${SYSVER}" ] ; then mkdir -p ${IGNDIR}/${SYSVER} ; fi
960fi
961
962case $1 in
963           check) get_update_file
964                  do_check ;;
965        branches) get_update_file
966                  list_branches ;;
967        chbranch) get_update_file
968                  do_branch "${2}" ;;
969        pkgcheck) checkup_pkgs ;;
970       pkgupdate) update_pkgs "$2" ;;
971finish-major-update) finish_major_fbsd_update ;;
972         install) get_update_file
973                  do_install "${2}" ;;
974        *) show_usage ;;
975esac
976
977exit 0
Note: See TracBrowser for help on using the repository browser.