source: src-sh/pc-updatemanager/pc-updatemanager @ 3ab1479

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 3ab1479 was 3ab1479, checked in by Kris Moore <kris@…>, 20 months ago

Remove depreciated -L and replace with -U

  • Property mode set to 100755
File size: 14.0 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`" ; export SYSVER
26
27# Get the system type
28SYSTYPE="`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  check                 - Check for system updates
71  install <tag>,<tag2>  - Install system updates
72  pkgcheck              - Check for updates to packages
73  pkgupdate             - Install packages updates
74"       
75
76        exit 1
77}
78
79# Run-command, don't halt if command exits with non-0
80rc_nohalt()
81{
82  CMD="$1"
83 
84  if [ -z "${CMD}" ] ; then
85    exit_err "Error: missing argument in rc_nohalt()"
86  fi
87
88  ${CMD}
89}
90
91# Run-command, halt if command exits with non-0
92rc_halt()
93{
94  CMD="$@"
95
96  if [ -z "${CMD}" ] ; then
97    exit_err "Error: missing argument in rc_halt()"
98  fi
99
100  ${CMD}
101  STATUS=$?
102  if [ ${STATUS} -ne 0 ] ; then
103    exit_err "Error ${STATUS}: ${CMD}"
104  fi
105}
106
107get_update_file() {
108
109  # Now fetch the update file
110  get_file "${PATCHURL}" "${PATCHTMPFILE}" 1 >/dev/null 2>/dev/null
111  if [ $? -ne 0 ] ; then
112     rm ${PATCHTMPFILE} 2>/dev/null
113     is_net_up
114     if [ $? -eq 0 ] ; then
115       echo "No updates available for $SYSVER!" ; exit 0
116     else
117       exit_err "Could not contact update server!"
118     fi
119  fi
120
121  # Now fetch the update file signature
122  get_file "${PATCHURL}.sha1" "${PATCHTMPFILE}.sha1" 1 >/dev/null 2>/dev/null
123  if [ $? -ne 0 ] ; then
124     rm ${PATCHTMPFILE}.sha1 2>/dev/null
125     is_net_up
126     if [ $? -eq 0 ] ; then
127       echo "No updates available for $SYSVER!" ; exit 0
128     else
129       exit_err "Could not contact update server!"
130     fi
131  fi
132
133  # Lets verify the signature of the file
134  openssl dgst -sha1 -verify ${SKEY} \
135        -signature ${PATCHTMPFILE}.sha1 \
136        ${PATCHTMPFILE} >/dev/null 2>/dev/null
137  if [ $? -ne 0 ] ; then
138     rm ${PATCHTMPFILE} 2>/dev/null
139     rm ${PATCHTMPFILE}.sha1 2>/dev/null
140     exit_err "Update file failed verification..."
141  fi
142
143  # Done with the signature we can discard
144  rm ${PATCHTMPFILE}.sha1
145
146}
147
148do_check() {
149  # Setup our variable, we have no patches so far
150  PATCHFOUND="0" 
151
152  while read line
153  do
154     echo $line | grep -q "^MU:"
155     if [ $? -eq 0 ] ; then
156        parse_mu_update_line "$line"
157        continue
158     fi
159     echo $line | grep -q "^SA:"
160     if [ $? -eq 0 ] ; then
161        parse_sa_update_line "$line"
162        continue
163     fi
164  done < ${PATCHTMPFILE}
165
166  # If no patches
167  if [ "${PATCHFOUND}" = "0" ]; then 
168     # No available updates
169     echo "Your system is up to date!"
170  fi
171
172  rm ${PATCHTMPFILE}
173
174};
175
176parse_mu_update_line()
177{
178   local line="$1"
179
180   # Check if this is a major update we can install
181   local sysUpOVer=`echo $line | cut -d ':' -f 2`
182   local sysUpNVer=`echo $line | cut -d ':' -f 3`
183
184   # Is this an update for our version?
185   if [ `uname -r` != "$sysUpOVer" ] ; then return; fi
186
187   if [ $PATCHFOUND -eq 0 ] ; then
188      echo ""
189      echo "The following updates are available:"
190      echo "------------------------------------"
191   fi
192   echo "NAME: FreeBSD System Update to ${sysUpNVer}" 
193   echo "TYPE: SYSUPDATE" 
194   echo "TAG: fbsd-${sysUpNVer}"
195   echo "VERSION: ${sysUpNVer}" 
196   echo ""
197   echo "To install: \"pc-updatemanager install fbsd-${sysUpNVer}\""
198   echo ""
199   echo ""
200
201   PATCHFOUND="`expr ${PATCHFOUND} + 1`" 
202}
203
204parse_sa_update_line()
205{
206   local line="$1"
207
208   # Check if this is an update we can install
209   local saVer=`echo $line | cut -d ':' -f 2`
210   local saArch=`echo $line | cut -d ':' -f 3`
211   local saType=`echo $line | cut -d ':' -f 4`
212   local saIdent="`echo $line | cut -d ':' -f 5`"
213
214   # For this version?
215   if [ "$SYSVER" != "$saVer" ] ; then return ; fi
216
217   # For this system arch?
218   if [ "$ARCH" != "$saArch" -a "$saArch" != "noarch" ] ; then return ; fi
219
220   # For this system type?
221   if [ "$SYSTYPE" != "$saType" -a "$saType" != "both" ] ; then return ; fi
222
223   # Already installed?
224   if [ -e "${INSDIR}/${SYSVER}/$saIdent" ] ; then return ; fi
225
226   if [ $PATCHFOUND -eq 0 ] ; then
227      echo ""
228      echo "The following updates are available:"
229      echo "------------------------------------"
230   fi
231   local saDesc="`echo $line | cut -d ':' -f 6`"
232   local saSize=`echo $line | cut -d ':' -f 8`
233   local saDetail="http://trac.pcbsd.org`echo $line | cut -d ':' -f 10`"
234   local saDate="`echo $line | cut -d ':' -f 11`"
235
236   echo "NAME: ${saDesc}" 
237   echo "TYPE: PATCH" 
238   echo "TAG: ${saIdent}"
239   echo "DETAILS: ${saDetail}"
240   echo "DATE: ${saDate}"
241   echo "SIZE: ${saSize}Mb" 
242   echo " "
243   echo "To install: \"pc-updatemanager install ${saIdent}\""
244   echo " "
245
246   PATCHFOUND="`expr ${PATCHFOUND} + 1`" 
247}
248
249start_pcbsd_patch() {
250  local up="$1"
251  local saIdent=""
252  local saVer=""
253  local saArch=""
254  local saPlat=""
255  local saUrl=""
256  local saDesc=""
257  local saCsum=""
258  local patchLine=""
259  if [ -e "${INSDIR}/${SYSVER}/${up}" ]; then
260     rm ${PATCHTMPFILE}
261     exit_err "Patch $up already installed!"
262  fi
263
264  while read line
265  do
266    echo $line | grep -q "^SA:"
267    if [ $? -ne 0 ] ; then continue; fi
268    saIdent="`echo $line | cut -d ':' -f 5`"
269    # Look for the right stand-alone update
270    if [ "$saIdent" != "$up" ] ; then continue ; fi
271    saVer=`echo $line | cut -d ':' -f 2`
272    saArch=`echo $line | cut -d ':' -f 3`
273    saType=`echo $line | cut -d ':' -f 4`
274    # Does this update apply to this system arch?
275    if [ "$saArch" != "$ARCH" -a "$saArch" != "noarch" ] ; then
276       rm ${PATCHTMPFILE}
277       exit_err "Patch $up is not for this system arch type!"
278    fi
279    # For this version?
280    if [ "$saVer" != "$SYSVER" ] ; then
281       rm ${PATCHTMPFILE}
282       exit_err "Patch $up is not for this system version!"
283    fi
284
285    # For this system type?
286    if [ "$SYSTYPE" != "$saType" -a "$saType" != "both" ] ; then
287       rm ${PATCHTMPFILE}
288       exit_err "Patch $up is not for this system type!"
289    fi
290
291    # Got here? We have a patch ready to go
292    patchLine="$line"
293    break
294  done < ${PATCHTMPFILE}
295
296  # Did we find the patch?
297  if [ -z "$patchLine" ] ; then
298     rm ${PATCHTMPFILE}
299     exit_err "Patch $up not found!"
300  fi
301
302  # Get the patch details
303  saVer=`echo $patchLine | cut -d ':' -f 2`
304  saArch=`echo $patchLine | cut -d ':' -f 3`
305  saPlat=`echo $patchLine | cut -d ':' -f 4`
306  saIdent="`echo $patchLine | cut -d ':' -f 5`"
307  saDesc="`echo $patchLine | cut -d ':' -f 6`"
308  saUrl="`echo $patchLine | cut -d ':' -f 7`"
309  saCsum="`echo $patchLine | cut -d ':' -f 9`"
310  local FILENAME="`basename $saUrl`"
311
312  # Start downloading the patch
313  touch ${TRIGGERFILE}
314  echo "DOWNLOADING: ${saIdent}"
315  echo "DOWNLOADING: ${saIdent}" >${TRIGGERFILE}
316
317  # Get the file
318  get_file_from_mirrors "/${saUrl}" "${DOWNLOADDIR}/${FILENAME}"
319  if [ $? -ne 0 ] ; then
320     rm ${PATCHTMPFILE}
321     echo "FAILED: ${saIdent}" >${TRIGGERFILE}
322     exit_err "Failed to download: ${saIdent}"
323  fi
324
325  # Check the sha256 checksum
326  if [ "$saCsum" != "`sha256 -q ${DOWNLOADDIR}/${FILENAME} 2>/dev/null`" ]
327  then
328     # Download MD5 doesn't match! Delete the file
329     rm ${PATCHTMPFILE}
330     rm ${DOWNLOADDIR}/${FILENAME}
331     echo "FAILED: ${saIdent}" >${TRIGGERFILE}
332     exit_err "Failed to download: ${saIdent}"
333  else
334     echo "DOWNLOADFINISHED: ${saIdent}"
335     echo "DOWNLOADFINISHED: ${saIdent}" >${TRIGGERFILE}
336  fi
337
338  echo "INSTALLING: ${saIdent}" >${TRIGGERFILE}
339  sleep 1
340
341  PATCHTMPDIR="`mktemp -d ${DOWNLOADDIR}/patchInstallXXXXX`"
342  rc_halt "tar xvJf ${DOWNLOADDIR}/${FILENAME} -C ${PATCHTMPDIR}" 2>/dev/null
343  PATCHDIR="$PATCHTMPDIR" ; export PATCHDIR
344  cd ${PATCHTMPDIR}
345  sh update.sh
346  if [ $? -eq 0 ]; then
347     touch "${INSDIR}/${SYSVER}/${saIdent}"
348     echo "INSTALLFINISHED: ${saIdent}"
349     echo "INSTALLFINISHED: ${saIdent}" >${TRIGGERFILE}
350  else
351     rm ${PATCHTMPFILE}
352     rm -rf ${PATCHTMPDIR}
353     rm ${DOWNLOADDIR}/${FILENAME}
354     echo "INSTALLFAILED: ${saIdent}" >${TRIGGERFILE}
355     exit_err "INSTALLFAILED: ${saIdent}"
356  fi
357
358  rc_halt "rm -rf ${PATCHTMPDIR}"
359  rc_halt "rm ${DOWNLOADDIR}/${FILENAME}"
360}
361
362start_major_fbsd_update() {
363  local rel=`echo $1 | sed 's|fbsd-||g'`
364
365  # Download update files from freebsd-update
366  freebsd-update --non-interactive -r "$rel" upgrade
367  if [ $? -ne 0 ] ; then
368     exit_err "Failed running \"freebsd-update -r $rel upgrade\"..."
369  fi
370
371  # Now install files
372  freebsd-update --non-interactive install
373  if [ $? -ne 0 ] ; then
374     exit_err "Failed running \"freebsd-update install\"..."
375  fi
376
377  # Now re-extract overlay files to ensure we do file fixing / massaging
378  if [ "$SYSTYPE" = "PCBSD" ]; then
379    pc-extractoverlay desktop
380  fi
381  if [ "$SYSTYPE" = "TRUEOS" ]; then
382    pc-extractoverlay server
383  fi
384
385  # Set the new pkg.conf file to the new repo
386  local arch=`uname -m`
387  echo "packagesite: http://getmirror.pcbsd.org/packages/$rel/$arch" >/usr/local/etc/pkg.conf
388  echo "HTTP_MIRROR: http" >>/usr/local/etc/pkg.conf
389  echo "PUBKEY: /usr/local/etc/pkg-pubkey.cert" >>/usr/local/etc/pkg.conf
390  echo "PKG_CACHEDIR: /usr/local/tmp" >>/usr/local/etc/pkg.conf
391
392  # Now its time to force a pkg-update of all packages to their new FreeBSD compiled versions
393  pc-updatemanager pkgupdate -f
394
395  # Now re-extract overlay files again to grab any new changes from a port we just updated
396  if [ "$SYSTYPE" = "PCBSD" ]; then
397    pc-extractoverlay desktop
398  fi
399  if [ "$SYSTYPE" = "TRUEOS" ]; then
400    pc-extractoverlay server
401  fi
402
403  echo "Major update finished!" 
404  echo "Please reboot the system for changes to take effect." 
405}
406
407do_install() {
408        # Make sure we are root and have specified updates to install
409        if [ `id -u` != "0" ] ; then exit_err "Must be run as root!" ; fi
410        if [ -z "$1" ] ; then exit_err "No updates specified to install!"; fi
411
412        # Begin to update the selected items
413        for up in `echo $1 | sed 's|,| |g'`
414        do
415          # If this is a major update, start it up!
416          echo $up | grep -q "^fbsd-" 
417          if [ $? -eq 0 ] ; then
418            start_major_fbsd_update "$up"
419            exit 0
420          elif [ "$up" == "pkg-updates" ] ; then
421            # Check if this is a pkg-update request or regular patch
422            start_pkg_updates
423            continue
424          else
425            echo $up | grep -q "^release-" 
426            if [ $? -eq 0 ] ; then
427              start_major_update "$up"
428              continue
429            fi 
430
431            # Doing regular pcbsd patch
432            start_pcbsd_patch "${up}"
433            continue
434          fi
435
436        done 
437
438        # All Finished!
439        rm ${PATCHTMPFILE}
440        exit 0
441}
442
443is_net_up() {
444        ping -c 1 www.pcbsd.org >/dev/null 2>/dev/null
445        return $?
446}
447
448checkup_pkgs() {
449
450  # Checkout the installed pkgs and compare to master list
451  rc_halt "pkg-static update"
452  pkg-static upgrade -n >/tmp/.pkgData.$$
453  grep -q "Upgrading" /tmp/.pkgData.$$
454  if [ $? -ne 0 ] ; then
455     echo "All packages are up to date!"
456     rm /tmp/.pkgData.$$
457     return 0
458  fi
459
460  # Display the pkg update data
461  cat /tmp/.pkgData.$$
462  rm /tmp/.pkgData.$$
463  echo ""
464  echo "To start the upgrade run \"${0} pkgupdate\""
465  return 0
466}
467
468update_pkgs()
469{
470  if [ -n "$1" -a "$1" != "-f" ] ; then
471     exit_err "Invalid option $1 passed"
472  fi
473
474  # Running from a GUI?
475  if [ -n "$PCFETCHGUI" ] ; then
476    # Setup EVENT_PIPE
477    EVENT_PIPE="/tmp/pkgpipe.$$"
478    export EVENT_PIPE
479    rc_halt "mkfifo $EVENT_PIPE"
480    echo "EVENT_PIPE: $EVENT_PIPE"
481
482    # Wait for QT to open the pipe file
483    sleep 5
484  fi
485
486  # Lets pre-download all the packages
487  download_cache_packages "pkg-static upgrade -U -n $1"
488
489  # Start the package update!
490  pkg-static upgrade -U -y ${1}
491  result=$?
492
493  # Lets now re-extract our overlay data to grab any adjusted port files
494  pc-extractoverlay ports >/dev/null 2>/dev/null
495
496  # Now re-extract overlay files to ensure we do file fixing / massaging
497  if [ "$SYSTYPE" = "PCBSD" ]; then
498    pc-extractoverlay desktop
499  fi
500  if [ "$SYSTYPE" = "TRUEOS" ]; then
501    pc-extractoverlay server
502  fi
503
504  # Cleanup EVENT_PIPE
505  if [ -n "$PCFETCHGUI" ] ; then
506    rm $EVENT_PIPE
507  fi
508
509  if [ $result -ne 0 ] ; then
510     echo "Failed updating..."
511  fi
512  exit $result
513}
514
515# Check if we have an update folder for the version we are on
516if [ ! -d "${AVAILDIR}/${SYSVER}" ] ; then mkdir -p ${AVAILDIR}/${SYSVER} ; fi
517
518if [ "`id -u`" = "0" ] ; then
519  # Make the installed directory for this version
520  if [ ! -d "${INSDIR}/${SYSVER}" ] ; then mkdir -p ${INSDIR}/${SYSVER} ; fi
521
522  # Make the ignore directory for this version
523  if [ ! -d "${IGNDIR}/${SYSVER}" ] ; then mkdir -p ${IGNDIR}/${SYSVER} ; fi
524fi
525
526case $1 in
527           check) get_mirror
528                  MIRRORURL="$VAL"
529                  get_update_file
530                  do_check ;;
531        pkgcheck) checkup_pkgs ;;
532       pkgupdate) update_pkgs "$2" ;;
533         install) get_mirror
534                  MIRRORURL="$VAL"
535                  get_update_file
536                  do_install "${2}" ;;
537        *) show_usage ;;
538esac
539
540exit 0
Note: See TracBrowser for help on using the repository browser.