source: freebsd-mgnt/system-update.sh@ 190

Last change on this file since 190 was 190, checked in by Rick van der Zwet, 14 years ago

Only ask if deamon needs to be stopped/started

  • Property svn:executable set to *
File size: 2.0 KB
RevLine 
[84]1#!/bin/sh
2# FreeBSD system upgade script
3#
4# Licence: BSDLike - http://rickvanderzwet.nl/LICENSE
5# Rick van der Zwet <info@rickvanderzwet.nl>
6
[182]7. /etc/rc.subr
8
[185]9ask_question() {
10 QUESTION=$1
11 DEFAULT=$2
12 echo -n "$QUESTION? [$DEFAULT]: "; read INPUT
13 INPUT=${INPUT:-"${DEFAULT}"}
14 checkyesno INPUT || return 1 && return 0
15
16}
17
18
[84]19if [ `id -u` -ne 0 ]; then
20 echo "Sorry root only" 1>&2
21 exit 128
22fi
23
[119]24DIRNAME=`dirname $0`
[182]25BATCH=${BATCH-""}
[84]26
[185]27# Get list of rc.d marked for updates
28RC_FILES=`$DIRNAME/port-list.sh`
[119]29
[84]30# Update port tree
[185]31echo "# Updating portstree ..."
32portsnap update > /dev/null
[84]33
[182]34# Update ports listing
35echo "# Checking ports which needs updating ..."
[84]36NEWPORTS=`pkg_version -qL=`
[182]37
38if [ -z "$NEWPORTS" ]; then
39 echo "# System up2date"
40 exit 0
41fi
42
[185]43#
44# Update ports
[182]45if [ -z "$BATCH" ]; then
46 # Make sure we have read the (new) UPDATING announcements
[185]47 # Use ls to display the last motification time of the directories in
48 # /var/db/pkg and assume that is the last time the user read the
49 # UPDATING file
50 LAST_UPDATED=`ls -rtlD '%Y%m%d' /var/db/pkg/ | awk 'END{print $6}'`
[182]51
[185]52 # Find new entries
53 TMPFILE=`mktemp -t $(basename $0).XXX`
54 awk -F: -v last=$LAST_UPDATED '{if (match($0,"^[0-9]+:$") && $1 < last) {exit}; print $0}' /usr/ports/UPDATING > $TMPFILE
55
56 echo "# Show new /usr/ports/UPDATING entries (starting from $LAST_UPDATED) ..."
57 if [`cat $TMPFILE | wc -l` -eq 7 ]; then
58 echo "## No new entries found"
59 else
60 cat $TMPFILE
61 fi
62 rm $TMPFILE
63
64 # agree to the terms of the game
[182]65 echo $NEWPORTS
[185]66 ask_question "Do you like to upgrade the affected ports" "no" || exit 1
[182]67
[185]68 #
69 # Stop daemons
[190]70 if [ -n "$RC_FILES" ]; then
71 echo $RC_FILES
72 ask_question "Do you like to stop your deamons" "yes" || exit
73 for RC_FILE in $RC_FILES; do
74 $RC_FILE stop
75 done
76 fi
[182]77fi
[185]78portupgrade -r -mBATCH=yes -a $NEWPORTS
[182]79
[185]80#
81# Restart daemons
[190]82if [ -n "$RC_FILES" ]; then
83 echo $RC_FILES
84 ask_question "Do you like to restart your deamons" "yes" || exit
85 for RC_FILE in $RC_FILES; do
86 $RC_FILE restart
87 done
88fi
Note: See TracBrowser for help on using the repository browser.