freebsd-update

From: Alexis Megas <megas_at_alum.rpi.edu>
Date: Tue, 05 Apr 2016 16:32:07 -0700
Hello.

Please consider a new clean command in the freebsd-update script. The modified manual and script are located at https://github.com/textbrowser/freebsd-update. Included are two diffs. Sorry for the long e-mail.

--- /usr/src/usr.sbin/freebsd-update/freebsd-update.8    2015-08-12 10:21:35.000000000 -0400
+++ ./freebsd-update.8    2016-04-02 15:16:47.780095000 -0400
_at__at_ -119,6 +119,12 _at__at_
 .Cm command
 can be any one of the following:
 .Bl -tag -width "rollback"
+.It Cm clean
+Remove the contents of
+.Ar workdir .
+(default:
+.Ar /var/db/freebsd-update/
+).
 .It Cm fetch
 Based on the currently installed world and the configuration
 options set, fetch all available binary updates.

--- /usr/src/usr.sbin/freebsd-update/freebsd-update.sh    2015-08-12 10:21:35.000000000 -0400
+++ ./freebsd-update.sh    2016-04-02 15:26:57.990003000 -0400
_at__at_ -53,6 +53,7 _at__at_
   --not-running-from-cron
                -- Run without a tty, for use by automated tools
 Commands:
+  clean        -- Clean workdir
   fetch        -- Fetch updates from server
   cron         -- Sleep rand(3600) seconds, fetch updates, and send an
                   email if updates were found
_at__at_ -474,7 +475,7 _at__at_
             ;;
 
         # Commands
-        cron | fetch | upgrade | install | rollback | IDS)
+        clean | cron | fetch | upgrade | install | rollback | IDS)
             COMMANDS="${COMMANDS} $1"
             ;;
 
_at__at_ -559,6 +560,25 _at__at_
     mergeconfig
 }
 
+# Perform sanity checks in preparation of cleaning workdir.
+clean_check_params () {
+    # Check that we are root.  All sorts of things won't work otherwise.
+    if [ `id -u` != 0 ]; then
+        echo "You must be root to run this."
+        exit 1
+    fi
+
+    # Check that we have a working directory.
+    _WORKDIR_bad="Directory does not exist or is not writable: "
+    if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
+        echo -n "`basename $0`: "
+        echo -n "${_WORKDIR_bad}"
+        echo ${WORKDIR}
+        exit 1
+    fi
+    cd ${WORKDIR} || exit 1
+}
+
 # Set utility output filtering options, based on ${VERBOSELEVEL}
 fetch_setup_verboselevel () {
     case ${VERBOSELEVEL} in
_at__at_ -2047,6 +2067,11 _at__at_
     echo ${NOWTIME} > lasteolwarn
 }
 
+# Clean workdir.
+clean_run() {
+        rm -fr *
+}
+
 # Do the actual work involved in "fetch" / "cron".
 fetch_run () {
     workdir_init || return 1
_at__at_ -3225,6 +3250,12 _at__at_
     default_params
 }
 
+# Clean command. Allow non-interactive use.
+cmd_clean () {
+        clean_check_params
+    clean_run || exit 1
+}
+
 # Fetch command.  Make sure that we're being called
 # interactively, then run fetch_check_params and fetch_run
 cmd_fetch () {
Received on Tue Apr 05 2016 - 21:32:20 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:03 UTC