Ignore:
Timestamp:
Sep 28, 2010, 12:18:01 PM (14 years ago)
Author:
Rick van der Zwet
Message:

Make the script KISS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freebsd-mgnt/system-update.sh

    r182 r185  
    66
    77. /etc/rc.subr
     8
     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
    818
    919if [ `id -u` -ne 0 ]; then
     
    1525BATCH=${BATCH-""}
    1626
    17 $DIRNAME/port-list.sh
     27# Get list of rc.d marked for updates
     28RC_FILES=`$DIRNAME/port-list.sh`
    1829
    1930# Update port tree
    20 echo "# Updating portstree .."
    21 portsnap update
     31echo "# Updating portstree ..."
     32portsnap update > /dev/null
    2233
    2334# Update ports listing
     
    3041fi
    3142
     43#
     44# Update ports
    3245if [ -z "$BATCH" ]; then
    3346  # Make sure we have read the (new) UPDATING announcements
    34   less /usr/ports/UPDATING
     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}'`
    3551
     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
    3665  echo $NEWPORTS
    37   # And agree to the terms of the game
    38   echo -n "Do you like to upgrade the affected ports [no]: "; read INPUT
     66  ask_question "Do you like to upgrade the affected ports" "no" || exit 1
    3967
    40   INPUT=${INPUT:-"no"}
    41   checkyesno INPUT || exit 1
    42   echo "Foo"
     68  #
     69  # Stop daemons
     70  echo $RC_FILES
     71  ask_question "Do you like to stop your deamons" "yes" || exit
     72  for RC_FILE in $RC_FILES; do
     73    $RC_FILE stop
     74  done
     75
    4376fi
     77portupgrade -r -mBATCH=yes -a $NEWPORTS
    4478
    45 portupgrade -r -mBATCH=yes -a $NEWPORTS
     79#
     80# Restart daemons
     81echo $RC_FILES
     82ask_question "Do you like to restart your deamons" "yes" || exit
     83for RC_FILE in $RC_FILES; do
     84  $RC_FILE restart
     85done
     86
Note: See TracChangeset for help on using the changeset viewer.