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 |
|
---|
7 | . /etc/rc.subr
|
---|
8 |
|
---|
9 | ask_question() {
|
---|
10 | # Will return 1 if yes, return 0 if no
|
---|
11 | QUESTION=$1
|
---|
12 | DEFAULT=$2
|
---|
13 | echo -n "$QUESTION? [$DEFAULT]: "; read INPUT
|
---|
14 | INPUT=${INPUT:-"${DEFAULT}"}
|
---|
15 | checkyesno INPUT || return 1 && return 0
|
---|
16 |
|
---|
17 | }
|
---|
18 |
|
---|
19 | if [ `id -u` -ne 0 ]; then
|
---|
20 | echo "Sorry root only" 1>&2
|
---|
21 | exit 128
|
---|
22 | fi
|
---|
23 |
|
---|
24 | DIRNAME=`dirname $0`
|
---|
25 | BATCH=${BATCH-""}
|
---|
26 |
|
---|
27 | # Get list of rc.d marked for updates
|
---|
28 | RC_FILES=`$DIRNAME/port-list.sh`
|
---|
29 |
|
---|
30 | # Update port tree
|
---|
31 | echo "# Updating portstree ..."
|
---|
32 | portsnap update > /dev/null
|
---|
33 |
|
---|
34 | # Update ports listing
|
---|
35 | echo "# Checking ports which needs updating ..."
|
---|
36 | NEWPORTS=`pkg_version -qL=`
|
---|
37 |
|
---|
38 | if [ -z "$NEWPORTS" ]; then
|
---|
39 | echo "# System up2date"
|
---|
40 | exit 0
|
---|
41 | fi
|
---|
42 |
|
---|
43 | #
|
---|
44 | # Update ports
|
---|
45 | if [ -z "$BATCH" ]; then
|
---|
46 | # Make sure we have read the (new) UPDATING announcements
|
---|
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}'`
|
---|
51 |
|
---|
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
|
---|
65 | echo $NEWPORTS
|
---|
66 | ask_question "Do you like to upgrade the affected ports" "no" || exit 1
|
---|
67 |
|
---|
68 | #
|
---|
69 | # Stop daemons
|
---|
70 | if [ -n "$RC_FILES" ]; then
|
---|
71 | echo $RC_FILES
|
---|
72 | ask_question "Do you like to stop your deamons" "yes" && {
|
---|
73 | for RC_FILE in $RC_FILES; do
|
---|
74 | $RC_FILE stop
|
---|
75 | done
|
---|
76 | }
|
---|
77 | fi
|
---|
78 | fi
|
---|
79 | portupgrade -r -mBATCH=yes -a $NEWPORTS
|
---|
80 |
|
---|
81 | #
|
---|
82 | # Restart daemons
|
---|
83 | if [ -n "$RC_FILES" ]; then
|
---|
84 | echo $RC_FILES
|
---|
85 | ask_question "Do you like to restart your deamons" "yes" && {
|
---|
86 | for RC_FILE in $RC_FILES; do
|
---|
87 | $RC_FILE restart
|
---|
88 | done
|
---|
89 | }
|
---|
90 | fi
|
---|