Changeset 193
- Timestamp:
- Oct 3, 2010, 11:50:23 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freebsd-mgnt/system-update.sh
r192 r193 6 6 7 7 . /etc/rc.subr 8 9 # Pointers to avoid confusion corresponts with logical boolean style values. 10 # WARNING do not conpare with exit codes! 11 FALSE=0 12 TRUE=1 8 13 9 14 ask_question() { … … 17 22 } 18 23 24 echo_list() { 25 PREFIX=$1 26 shift 27 for ENTRY in $*; do 28 echo "$PREFIX $ENTRY" 29 done 30 } 31 32 # 33 # SuperCow power only 19 34 if [ `id -u` -ne 0 ]; then 20 35 echo "Sorry root only" 1>&2 … … 22 37 fi 23 38 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 # 43 FORCE_PORTUPGRADE=${FORCE_PORTUPGRADE:-$FALSE} 44 FORCE_PORTMASTER=${FORCE_PORTMASTER:-$FALSE} 45 46 PORTUPGRADE_INSTALLED=$FALSE 47 PORTMASTER_INSTALLED=$FALSE 48 USE_PORTMGNT="none" 49 if [ -n "`whereis -qb portupgrade`" ]; then 50 PORTUPGRADE_INSTALLED=$TRUE 51 fi 52 if [ -n "`whereis -qb portmaster`" ]; then 53 PORTMASTER_INSTALLED=$TRUE 54 fi 55 56 if [ $FORCE_PORTMASTER -eq $TRUE ]; then 57 if [ $PORTMASTER_INSTALLED -eq $FALSE ]; then 58 echo "# ERROR: FORCE_PORTMASTER set but binary not found" 26 59 exit 1 27 fi 60 fi 61 USE_PORTMGNT="portmaster" 62 elif [ $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" 68 else 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 85 fi 86 87 88 89 28 90 29 91 DIRNAME=`dirname $0` … … 32 94 # Get list of rc.d marked for updates 33 95 RC_FILES=`$DIRNAME/port-list.sh` 96 RUNNING_DAEMONS="" 97 98 for RC_FILE in $RC_FILES; do 99 $RC_FILE onestatus | grep -q 'is running as' && { 100 RUNNING_DAEMONS="$RUNNING_DAEMONS $RC_FILE" 101 } 102 done 34 103 35 104 # Update port tree … … 39 108 # Update ports listing 40 109 echo "# Checking ports which needs updating ..." 41 NEWPORTS=`pkg_version -qL=` 110 NEWPORTS=`pkg_version -qol '<'` 111 112 # Check for potentional trouble. 113 # XXX: Weird -q does not strip at '!' check 114 BROKENPORTS=`pkg_version -qol '!' | awk '{print $1}'` 115 if [ -n "$BROKENPORTS" ]; then 116 echo "# WARNING comparion failed, fix by hand"; echo_list "# - " $BROKENPORTS 117 fi 42 118 43 119 if [ -z "$NEWPORTS" ]; then 44 echo "# System up2date" 120 echo "# No ports to update" 121 echo "# All done, goodbye" 45 122 exit 0 46 123 fi … … 68 145 69 146 # 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 72 150 73 151 # 74 152 # Stop daemons 153 DAEMONS_STOPPED=$FALSE 75 154 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 166 fi 167 echo "# Using update tool '$USE_PORTMGNT" 168 case $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 ;; 179 esac 180 181 # 182 # (Re)start daemons. Assume we only like to start the just stopped ones. 88 183 if [ -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 202 fi 203 204 echo "# All done, goodbye"
Note:
See TracChangeset
for help on using the changeset viewer.