Changeset 193 for freebsd-mgnt


Ignore:
Timestamp:
Oct 3, 2010, 11:50:23 AM (14 years ago)
Author:
Rick van der Zwet
Message:
  • Support both portmaster and portupgrade.
  • Only manage daemons which are running.
  • If not stopped, ask user to restart.
  • Pretty formatting of lists
File:
1 edited

Legend:

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

    r192 r193  
    66
    77. /etc/rc.subr
     8
     9# Pointers to avoid confusion corresponts with logical boolean style values.
     10# WARNING do not conpare with exit codes!
     11FALSE=0
     12TRUE=1
    813
    914ask_question() {
     
    1722}
    1823
     24echo_list() {
     25  PREFIX=$1
     26  shift
     27  for ENTRY in $*; do
     28    echo "$PREFIX $ENTRY"
     29  done
     30}
     31
     32#
     33# SuperCow power only
    1934if [ `id -u` -ne 0 ]; then
    2035    echo "Sorry root only" 1>&2
     
    2237fi
    2338
    24 if [ -z "`whereis -qb portupgrade`" ]; then
    25     echo "ERROR: ports-mgnt/portupgrade not found!"
     39
     40#
     41# Check which ports-mgnt tool to use to upgrade outdated ports
     42#
     43FORCE_PORTUPGRADE=${FORCE_PORTUPGRADE:-$FALSE}
     44FORCE_PORTMASTER=${FORCE_PORTMASTER:-$FALSE}
     45
     46PORTUPGRADE_INSTALLED=$FALSE
     47PORTMASTER_INSTALLED=$FALSE
     48USE_PORTMGNT="none"
     49if [ -n "`whereis -qb portupgrade`" ]; then
     50  PORTUPGRADE_INSTALLED=$TRUE
     51fi
     52if [ -n "`whereis -qb portmaster`" ]; then
     53  PORTMASTER_INSTALLED=$TRUE
     54fi
     55
     56if [ $FORCE_PORTMASTER -eq $TRUE ]; then
     57  if  [ $PORTMASTER_INSTALLED -eq $FALSE ]; then
     58    echo "# ERROR: FORCE_PORTMASTER set but binary not found"
    2659    exit 1
    27 fi
     60  fi
     61  USE_PORTMGNT="portmaster"
     62elif [ $FORCE_PORTUPGRADE -eq $TRUE ]; then
     63  if [ $PORTUPGRADE_INSTALLED -eq $FALSE ]; then
     64    echo "# ERROR: FORCE_PORTUPGRADE set but binary not found"
     65    exit 1
     66  fi
     67  USE_PORTMGNT="portupgrade"
     68else
     69  if [ $PORTUPGRADE_INSTALLED -eq $TRUE ]; then
     70    if [ $PORTMASTER_INSTALLED -eq $TRUE ]; then
     71      echo "# ERROR: both portmaster and portupgrade are installed"
     72      echo "# Pick your favorite by setting either FORCE_PORTMASTER=1 or FORCE_PORTUPGRADE=1"
     73      exit 1
     74    fi
     75    USE_PORTMGNT="portupgrade"
     76  else
     77    if [ $PORTMASTER_INSTALLED -eq $FALSE ]; then
     78      echo "# WARNING: ports-mgnt/portupgrade not found!"
     79      echo "# WARNING: ports-mgnt/portmaster not found!"
     80      echo "# ERROR  : Not port upgrade tool installed"
     81      exit 1
     82    fi
     83    USE_PORTMGNT="portmaster"
     84  fi
     85fi
     86
     87
     88 
     89
    2890
    2991DIRNAME=`dirname $0`
     
    3294# Get list of rc.d marked for updates
    3395RC_FILES=`$DIRNAME/port-list.sh`
     96RUNNING_DAEMONS=""
     97
     98for RC_FILE in $RC_FILES; do
     99  $RC_FILE onestatus | grep -q 'is running as' && {
     100    RUNNING_DAEMONS="$RUNNING_DAEMONS $RC_FILE"
     101  }
     102done
    34103
    35104# Update port tree
     
    39108# Update ports listing
    40109echo "# Checking ports which needs updating ..."
    41 NEWPORTS=`pkg_version -qL=`
     110NEWPORTS=`pkg_version -qol '<'`
     111
     112# Check for potentional trouble.
     113# XXX: Weird -q does not strip at '!' check
     114BROKENPORTS=`pkg_version -qol '!' | awk '{print $1}'`
     115if [ -n "$BROKENPORTS" ]; then
     116  echo "# WARNING comparion failed, fix by hand"; echo_list "# - " $BROKENPORTS
     117fi
    42118
    43119if [ -z "$NEWPORTS" ]; then
    44   echo "# System up2date"
     120  echo "# No ports to update"
     121  echo "# All done, goodbye"
    45122  exit 0
    46123fi
     
    68145 
    69146  # agree to the terms of the game
    70   echo $NEWPORTS
    71   ask_question "Do you like to upgrade the affected ports" "no" || exit 1
     147  echo "# Ports pending update:"
     148  echo_list "# - " $NEWPORTS
     149  ask_question "# Do you like to upgrade the affected ports" "no" || exit 1
    72150
    73151  #
    74152  # Stop daemons
     153  DAEMONS_STOPPED=$FALSE
    75154  if [ -n "$RC_FILES" ]; then
    76     echo $RC_FILES
    77     ask_question "Do you like to stop your deamons" "yes" && {
    78       for RC_FILE in $RC_FILES; do
    79         $RC_FILE stop
    80       done
    81     }
    82   fi
    83 fi
    84 portupgrade -r -mBATCH=yes -a $NEWPORTS
    85 
    86 #
    87 # Restart daemons
     155    echo "# Affected daemons:"; echo_list "# - " $RC_FILES
     156    if [ -n "$RUNNING_DAEMONS" ]; then
     157      echo "# Running  daemons:"; echo_list "# - " $RUNNING_DAEMONS
     158      ask_question "# Do you like to stop running daemons" "yes" && {
     159        for RC_FILE in $RUNNING_DAEMONS; do
     160          $RC_FILE stop
     161        done;
     162        DAEMONS_STOPPED=$TRUE
     163      }
     164    fi
     165  fi
     166fi
     167echo "# Using update tool '$USE_PORTMGNT"
     168case $USE_PORTMGNT in
     169  portupgrade)
     170    portupgrade -r -mBATCH=yes -a $NEWPORTS
     171    ;;
     172  portmaster)
     173    portmaster -d --no-confirm --no-term-title --no-index-fetch -mBATCH=yes -a $NEWPORTS
     174    ;;
     175  *)
     176    echo "# ERROR: Failed to find a port management tool"
     177    exit 1
     178    ;;
     179esac
     180
     181#
     182# (Re)start daemons. Assume we only like to start the just stopped ones.
    88183if [ -n "$RC_FILES" ]; then
    89   echo $RC_FILES
    90   ask_question "Do you like to restart your deamons" "yes" && {
    91     for RC_FILE in $RC_FILES; do
    92       $RC_FILE restart
    93     done
    94   }
    95 fi
     184  echo "# Affected daemons:"; echo_list "# - " $RC_FILES
     185  if [ -n "$RUNNING_DAEMONS" ]; then
     186    if [ $DAEMONS_STOPPED -eq $TRUE ]; then
     187      echo "# Enabled daemons: "; echo_list "# - " $RUNNING_DAEMONS
     188      ask_question "# Do you like to start your daemons" "yes" && {
     189        for RC_FILE in $RUNNING_DAEMONS; do
     190          $RC_FILE start
     191        done
     192      }
     193    else
     194      echo "# Running daemons: "; echo_list "# - " $RUNNING_DAEMONS
     195      ask_question "# Do you like to restart your daemons" "yes" && {
     196        for RC_FILE in $RUNNING_DAEMONS; do
     197          $RC_FILE restart
     198        done
     199      }
     200    fi
     201  fi
     202fi
     203
     204echo "# All done, goodbye"
Note: See TracChangeset for help on using the changeset viewer.