1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Unattended FreeBSD Ports upgrade cycle, please note that starting and stopping
|
---|
4 | # of services is taken care of in the pkgtools.conf
|
---|
5 | #
|
---|
6 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
7 | #
|
---|
8 | PATH=$PATH:/usr/local/sbin:/usr/local/bin
|
---|
9 | WC=`cd $(dirname $0); pwd -P`
|
---|
10 |
|
---|
11 | if [ `id -u` -ne 0 ]; then
|
---|
12 | echo "Root only!" 1>&2
|
---|
13 | exit 1
|
---|
14 | fi
|
---|
15 |
|
---|
16 | # Make sure we always using the latest version
|
---|
17 | svn up --non-interactive `dirname $0` | grep '^[A-Z] ' && {
|
---|
18 | sh $0
|
---|
19 | exit 0
|
---|
20 | }
|
---|
21 |
|
---|
22 | portmaster --version 1>/dev/null 2>/dev/null || make -C /usr/ports/ports-mgmt/portmaster BATCH=yes install clean
|
---|
23 |
|
---|
24 | # Fetch the latest details and provide listing of packages to be updated
|
---|
25 | portsnap fetch update || exit 1
|
---|
26 |
|
---|
27 | echo "# Find out which packages to update"
|
---|
28 | update_list=`pkg_version -o -L= | xargs -n1 pkg_info -qO`
|
---|
29 |
|
---|
30 | if [ -z "$update_list" ]; then
|
---|
31 | echo "Everything is up2date"
|
---|
32 | exit 0
|
---|
33 | fi
|
---|
34 |
|
---|
35 | echo "# Find the rc.d/* entries affected"
|
---|
36 | for pkg in $update_list; do
|
---|
37 | rc_d="$rc_d `pkg_info -qL $pkg $(pkg_info -qR $pkg) | grep -F '/rc.d/'`"
|
---|
38 | done
|
---|
39 | rc_d="`echo $rc_d | xargs -n1 | sort -u`"
|
---|
40 |
|
---|
41 | echo "# Going to update the following packages:"
|
---|
42 | echo $update_list | xargs -n1 echo "# - "
|
---|
43 | echo "# The following daemons will not be available:"
|
---|
44 | for rc in $rc_d; do
|
---|
45 | echo "# - $rc (`$rc status 2>&1 | grep -v -e '^Usage:' -e 'directive' -e '^Cannot'`)"
|
---|
46 | done
|
---|
47 | echo -n "# Do you like to update the packages: (y|n) [y]: "; read INPUT
|
---|
48 | case $INPUT in
|
---|
49 | ''|y) ;;
|
---|
50 | [yY][eE][sS]) ;;
|
---|
51 | *)
|
---|
52 | echo "Canceled by user!"; exit 1
|
---|
53 | ;;
|
---|
54 | esac
|
---|
55 |
|
---|
56 | # Stop the daemons affected
|
---|
57 | for rc in $rc_d; do
|
---|
58 | $rc stop
|
---|
59 | done
|
---|
60 |
|
---|
61 | # Install via portmaster
|
---|
62 | portmaster --no-confirm -yadG
|
---|
63 |
|
---|
64 | # Just to be sure try to start all port daemons again (this will make sure the
|
---|
65 | # already updated ones are also started nicely again).
|
---|
66 | for rc in `rcorder /usr/local/etc/rc.d/* 2>/dev/null`; do
|
---|
67 | $rc restart
|
---|
68 | done
|
---|