From d26d8ba30eaee1da4f99bbbd979e7ec9c80b7820 Mon Sep 17 00:00:00 2001 From: eadler Date: Sun, 5 Aug 2012 21:13:21 +0000 Subject: [PATCH] Add interactive option to override portsnap's automagical detection of a terminal. Submitted by: Hannes h2+fbsdports@fsfe.org Approved by: cperciva MFC after: 1 week --- usr.sbin/portsnap/portsnap/portsnap.8 | 8 +++++++- usr.sbin/portsnap/portsnap/portsnap.sh | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/usr.sbin/portsnap/portsnap/portsnap.8 b/usr.sbin/portsnap/portsnap/portsnap.8 index 0d9c2612a1e2..f0b362803d85 100644 --- a/usr.sbin/portsnap/portsnap/portsnap.8 +++ b/usr.sbin/portsnap/portsnap/portsnap.8 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 15, 2008 +.Dd August 5, 2012 .Dt PORTSNAP 8 .Os FreeBSD .Sh NAME @@ -110,6 +110,12 @@ command only, operate only on parts of the ports tree starting with .Ar sysutils/port would extract sysutils/portsman, sysutils/portsnap, sysutils/portupgrade, etc.) +.It Fl Fl interactive +override auto-detection of calling process. +Only use this when calling portsnap from an +.Sy interactive, non-terminal application. +(Cron jobs are particularly bad since they cause +load spikes on the Portsnap mirrors.) .El .Sh COMMANDS The diff --git a/usr.sbin/portsnap/portsnap/portsnap.sh b/usr.sbin/portsnap/portsnap/portsnap.sh index 033bb55fe074..80718203a8e1 100644 --- a/usr.sbin/portsnap/portsnap/portsnap.sh +++ b/usr.sbin/portsnap/portsnap/portsnap.sh @@ -48,6 +48,9 @@ Options: (default: /usr/ports/) -s server -- Server from which to fetch updates. (default: portsnap.FreeBSD.org) + --interactive -- interactive: override auto-detection of calling process + (use this when calling portsnap from an interactive, non- + terminal application AND NEVER ELSE). path -- Extract only parts of the tree starting with the given string. (extract command only) Commands: @@ -84,6 +87,7 @@ init_params() { SERVERNAME="" REFUSE="" LOCALDESC="" + INTERACTIVE="" } # Parse the command line @@ -103,6 +107,9 @@ parse_cmdline() { XARGST="-t" DDSTATS=".." ;; + --interactive) + INTERACTIVE="YES" + ;; -f) if [ $# -eq 1 ]; then usage; fi if [ ! -z "${CONFFILE}" ]; then usage; fi @@ -228,6 +235,13 @@ default_params() { eval ${X}=${__} fi done + if [ -z "${INTERACTIVE}" ]; then + if [ -t 0 ]; then + INTERACTIVE="YES" + else + INTERACTIVE="NO" + fi + fi } # Perform sanity checks and set some final parameters @@ -1023,10 +1037,10 @@ get_params() { # Fetch command. Make sure that we're being called # interactively, then run fetch_check_params and fetch_run cmd_fetch() { - if [ ! -t 0 ]; then + if [ "${INTERACTIVE}" != "YES" ]; then echo -n "`basename $0` fetch should not " echo "be run non-interactively." - echo "Run `basename $0` cron instead." + echo "Run `basename $0` cron instead" exit 1 fi fetch_check_params @@ -1069,7 +1083,7 @@ cmd_update() { # whether stdin is a terminal; then run 'update' or # 'extract' depending on whether ${PORTSDIR} exists. cmd_alfred() { - if [ -t 0 ]; then + if [ "${INTERACTIVE}" = "YES" ]; then cmd_fetch else cmd_cron