[PC-BSD Commits] r19053 - in pcbsd/current/src-sh/warden: bin scripts/backend

svn at pcbsd.org svn at pcbsd.org
Tue Sep 11 10:46:13 PDT 2012


Author: kris
Date: 2012-09-11 17:46:13 +0000 (Tue, 11 Sep 2012)
New Revision: 19053

Modified:
   pcbsd/current/src-sh/warden/bin/warden
   pcbsd/current/src-sh/warden/scripts/backend/functions.sh
Log:

Remove some functions from warden that are in libsh now



Modified: pcbsd/current/src-sh/warden/bin/warden
===================================================================
--- pcbsd/current/src-sh/warden/bin/warden	2012-09-11 17:46:03 UTC (rev 19052)
+++ pcbsd/current/src-sh/warden/bin/warden	2012-09-11 17:46:13 UTC (rev 19053)
@@ -12,8 +12,7 @@
 {
   UTEST="`whoami`"
   if [ "$UTEST" != "root" ] ; then
-     echo "ERROR: This command must be run as root!"
-     exit 155
+     exit_err "This command must be run as root!"
   fi
 }
 
@@ -524,48 +523,28 @@
 
 
     pkgs) IP="${2}"
-         if [ -z "${IP}" ]; then
-          echo "ERROR: No IP specified!"
-          exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]; then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
 
          ${PROGDIR}/scripts/backend/listpkgs.sh "${IP}" 
          ;;
 details) IP="${2}"
-         if [ -z "${IP}" ]; then
-          echo "ERROR: No IP specified!"
-          exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]; then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
 
          ${PROGDIR}/scripts/backend/details.sh "${IP}" 
          ;;
     set) require_root
 	 OPT="${2}" 
-         if [ "${OPT}" != "ip" ] ; then echo "Invalid option!" ; exit 1 ; fi
+         if [ "${OPT}" != "ip" ] ; then exit_err "Invalid option!"; fi
 	 IP="${3}"
          EXTRAIPS="${4}"
 
-         if [ -z "${IP}" ] ; then
-          echo "ERROR: No IP specified!"
-          exit 1
-         fi
+         if [ -z "${IP}" ] ; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ] ; then exit_err "No such jail!"; fi
 
-         if [ ! -e "${JDIR}/${IP}" ] ; then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
 	 set_warden_metadir
 
 	 IPS=`echo $EXTRAIPS | sed 's|,| |g'`
@@ -580,42 +559,25 @@
 	 IP="${2}"
          TYPE="${3}"
 
-         if [ -z "${IP}" ] ; then
-          echo "ERROR: No IP specified!"
-          exit 1
-         fi
+         if [ -z "${IP}" ] ; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ] ; then exit_err "No such jail!"; fi
 
-         if [ ! -e "${JDIR}/${IP}" ] ; then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+	 set_warden_metadir
+	 if [ -e "${JMETADIR}/linuxjail" ] ; then exit_err "Cannot change type on Linux jail!"; fi
 
-	 set_warden_metadir
-	 if [ -e "${JMETADIR}/linuxjail" ] ; then
-           echo "ERROR: Cannot change type on Linux jail!"
-           exit 1
-	 fi
 	 case $TYPE in
 	   portjail) mkportjail "${JDIR}/${IP}" ;;
 	   standard) rm ${JMETADIR}/xjail >/dev/null 2>/dev/null ;;
-	   *) echo "Invalid TYPE" ; exit 1 ;;
+	   *) exit_err "Invalid TYPE" ;;
          esac
          ;;
 
    auto) require_root
 	 IP="${2}"
 
-         if [ -z "${IP}" ]
-         then
-          echo "ERROR: No IP specified!"
-          exit 1
-         fi
+         if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
 
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
 
 
@@ -639,26 +601,13 @@
 	  # Time to startup the jail
           IP="${2}"
 
-          if [ -z "${IP}" ]
-          then
-           echo "ERROR: No IP specified!"
-           exit 1
-          fi
-
-          if [ ! -e "${JDIR}/${IP}" ]
-          then
-            echo "ERROR: No such jail!"
-            exit 1
-          fi 
+          if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+          if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi 
 	  set_warden_metadir
          
           # Check if this jail is already running
           ${PROGDIR}/scripts/backend/checkstatus.sh "${IP}"
-          if [ "$?" = "0" ]
-          then
-            echo "ERROR: This jail is already running!"
-            exit 1
-          fi
+          if [ "$?" = "0" ]; then exit_err "This jail is already running!"; fi
  
           ${PROGDIR}/scripts/backend/startjail.sh "${IP}" 
           ;;
@@ -666,17 +615,8 @@
           # Time to stop the jail
           IP="${2}"
 
-          if [ -z "${IP}" ]
-          then
-           echo "ERROR: No IP specified!"
-           exit 1
-          fi
-
-          if [ ! -e "${JDIR}/${IP}" ]
-          then
-            echo "ERROR: No such jail!"
-            exit 1
-          fi 
+          if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+          if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi 
 	  set_warden_metadir
          
           ${PROGDIR}/scripts/backend/stopjail.sh "${IP}" 
@@ -685,18 +625,9 @@
  checkup) # Log a user into chroot session
           IP="${2}"
 
-          if [ -z "${IP}" ]
-          then
-           echo "ERROR: No IP specified!"
-           exit 1
-          fi
+          if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+          if [ ! -e "${JDIR}/${IP}" -a "$IP" != "all" ]; then exit_err "No such jail!"; fi
 
-          if [ ! -e "${JDIR}/${IP}" -a "$IP" != "all" ]
-          then
-            echo "ERROR: No such jail!"
-            exit 1
-          fi
-
           ${PROGDIR}/scripts/backend/checkupdates.sh "${IP}"
           ;;
 
@@ -704,17 +635,8 @@
  chroot) # Log a user into chroot session
           IP="${2}"
 
-          if [ -z "${IP}" ]
-          then
-           echo "ERROR: No IP specified!"
-           exit 1
-          fi
-
-          if [ ! -e "${JDIR}/${IP}" ]
-          then
-            echo "ERROR: No such jail!"
-            exit 1
-          fi
+          if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+          if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	  set_warden_metadir
 
           ${PROGDIR}/scripts/backend/chrootjail.sh "${IP}" "${3}"
@@ -723,11 +645,7 @@
  import) require_root
 	 # The user wants to import a jail, lets do it!
          IFILE="$2"
-         if [ ! -e "$IFILE" ]
-         then
-           echo "ERROR: Invalid filename: ${IFILE}"
-           exit 1
-         fi
+         if [ ! -e "$IFILE" ]; then exit_err "Invalid filename: ${IFILE}"; fi
 
          IP="OFF"
          HOST="OFF"
@@ -741,18 +659,10 @@
 
               #Sanity check on the IP
               check_ip ${IP}
-              if [ "$?" != "0" ]
-              then
-                echo "ERROR: Invalid IP address!"
-                exit 1
-              fi
+              if [ "$?" != "0" ]; then exit_err "Invalid IP address!"; fi
 
               # Check if the directory already exists
-              if [ -e "${JDIR}/${IP}" ]
-              then
-                 echo "ERROR: A jail with this IP already exists!"
-                 exit 1
-              fi
+              if [ -e "${JDIR}/${IP}" ]; then exit_err "A jail with this IP already exists!"; fi
 
            fi
   
@@ -772,17 +682,8 @@
  export) require_root
          # The user wants to export a jail, lets do it!
          IP="$2"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
 
          # Check if the user wants to place the file in their own DIR
@@ -794,11 +695,7 @@
            then
               DIR="`echo ${i} | cut -d '=' -f 2`"
               # Check if the directory exists
-              if [ ! -d "${DIR}" ]
-              then
-                 echo "ERROR: No such directory ${DIR}!"
-                 exit 1
-              fi
+              if [ ! -d "${DIR}" ]; then exit_err "No such directory ${DIR}!"; fi
            fi
 
          done
@@ -810,51 +707,24 @@
 
  zfsmksnap) require_root
          IP="$2"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfsmksnap.sh "${IP}"
          ;;
 
  zfslistclone) require_root
          IP="$2"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfslistclone.sh "${IP}"
          ;;
 
  zfslistsnap) require_root
          IP="$2"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfslistsnap.sh "${IP}"
          ;;
@@ -862,34 +732,16 @@
  zfsclonesnap) require_root
          IP="$2"
          SNAP="$3"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfsclonesnap.sh "${IP}" "$SNAP"
          ;;
 
  zfscronsnap) require_root
          IP="$2"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfscronsnap.sh "${IP}" "$3" "$4" "$5"
          ;;
@@ -898,17 +750,8 @@
  zfsrevertsnap) require_root
          IP="$2"
          SNAP="$3"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
-
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfsrevertsnap.sh "${IP}" "$SNAP"
          ;;
@@ -916,17 +759,9 @@
  zfsrmclone) require_root
          IP="$2"
          CLONE="$3"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
 
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfsrmclone.sh "${IP}" "$CLONE"
          ;;
@@ -934,17 +769,9 @@
  zfsrmsnap) require_root
          IP="$2"
          SNAP="$3"
-         if [ -z "$IP" ]
-         then
-           echo "ERROR: No IP specified!"
-           exit 1
-         fi
+         if [ -z "$IP" ]; then exit_err "No IP specified!"; fi
 
-         if [ ! -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: No such jail!"
-           exit 1
-         fi
+         if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	 set_warden_metadir
          ${PROGDIR}/scripts/backend/zfsrmsnap.sh "${IP}" "$SNAP"
          ;;
@@ -953,19 +780,11 @@
          # The user wants to create a new jail, do error checking
          IP="$2"
          HOST="$3"
-         if [ -z "$IP" -o -z "$HOST" ]
-         then
-           echo "ERROR: No IP / Host specified!"
-           exit 1
-         fi
+         if [ -z "$IP" -o -z "$HOST" ]; then exit_err "No IP / Host specified!"; fi
 
          #Sanity check on the IP
          check_ip ${IP}
-         if [ "$?" != "0" ]
-         then
-           echo "ERROR: Invalid IP address!"
-           exit 1
-         fi
+         if [ "$?" != "0" ]; then exit_err "Invalid IP address!"; fi
 
          #Now check for the presence of the optional flags
          SRC="NO"
@@ -980,7 +799,7 @@
              --startauto) AUTO="YES" ;;
              --portjail) PORTJAIL="YES" ;;
              --linuxjail) LINUXJAIL="YES" ; shift
-			  if [ -z "$1" ] ; then echo "Error: No linux setup script specified!" ; exit 1 ; fi
+			  if [ -z "$1" ] ; then exit_err "No linux setup script specified!"; fi
 			  LINUX_JAIL_SCRIPT="$1" ; export LINUX_JAIL_SCRIPT
 			  ;;
            esac
@@ -988,11 +807,7 @@
          done
 
          # Check to ensure this jail does not already exist
-         if [ -e "${JDIR}/${IP}" ]
-         then
-           echo "ERROR: A jail with this IP already exists!"
-           exit 1
-         fi  
+         if [ -e "${JDIR}/${IP}" ]; then exit_err "A jail with this IP already exists!"; fi  
 
           # Passed all tests, create the jail now
           ${PROGDIR}/scripts/backend/createjail.sh "${IP}" "${HOST}" "${SRC}" "${PORTS}" "${AUTO}" "${PORTJAIL}" "${LINUXJAIL}"
@@ -1002,17 +817,8 @@
           # Time to delete a jail
           IP="${2}"
 
-          if [ -z "${IP}" ]
-          then
-           echo "ERROR: No IP specified!"
-           exit 1
-          fi
-
-          if [ ! -e "${JDIR}/${IP}" ]
-          then
-            echo "ERROR: No such jail!"
-            exit 1
-          fi
+          if [ -z "${IP}" ]; then exit_err "No IP specified!"; fi
+          if [ ! -e "${JDIR}/${IP}" ]; then exit_err "No such jail!"; fi
 	  set_warden_metadir
 
           if [ "$3" != "--confirm" ]
@@ -1020,11 +826,7 @@
             echo "Are you sure you want to delete ${IP}?"
             echo -e "Choice: (y/n)\c"
             read confirm
-            if [ "$confirm" != "y" ]
-            then
-              echo "Canceled!"
-              exit 1 
-            fi
+            if [ "$confirm" != "y" ]; then exit_err "Canceled!"; fi
           fi
 
           # Check if this jail is running
@@ -1035,10 +837,7 @@
 
           # Check if this jail is STILL running
           ${PROGDIR}/scripts/backend/checkstatus.sh "${IP}"
-          if [ "$?" = "0" ] ; then
-	     echo "Error: Jail still is running or has leftovers.."
-	     exit 1
-          fi
+          if [ "$?" = "0" ] ; then exit_err "Jail still is running or has leftovers.."; fi
 
           # Delete it now
           ${PROGDIR}/scripts/backend/deletejail.sh "${IP}"

Modified: pcbsd/current/src-sh/warden/scripts/backend/functions.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2012-09-11 17:46:03 UTC (rev 19052)
+++ pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2012-09-11 17:46:13 UTC (rev 19053)
@@ -42,79 +42,6 @@
 # Clone directory
 CDIR="${JDIR}/clones"
 
-# Function to ask the user to press Return to continue
-rtn()
-{
-  echo -e "Press ENTER to continue\c";
-  read garbage
-};
-
-# Function to check if an IP address passes a basic sanity test
-check_ip()
-{
-  ip="$1"
-  
-  # If this is a V6 address, skip validation for now
-  isV6 "${ip}"
-  if [ $? -eq 0 ] ; then return ; fi
-
-  # Check if we can cut this IP into the right segments 
-  SEG="`echo $ip | cut -d '.' -f 1 2>/dev/null`"
-  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
-  if [ "$?" != "0" ]
-  then
-     return 1
-  fi
-  if [ $SEG -gt 255 -o $SEG -lt 0 ]
-  then
-     return 1
-  fi
-  
-  # Second segment
-  SEG="`echo $ip | cut -d '.' -f 2 2>/dev/null`"
-  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
-  if [ "$?" != "0" ]
-  then
-     return 1
-  fi
-  if [ $SEG -gt 255 -o $SEG -lt 0 ]
-  then
-     return 1
-  fi
-
-  # Third segment
-  SEG="`echo $ip | cut -d '.' -f 3 2>/dev/null`"
-  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
-  if [ "$?" != "0" ]
-  then
-     return 1
-  fi
-  if [ $SEG -gt 255 -o $SEG -lt 0 ]
-  then
-     return 1
-  fi
-  
-  # Fourth segment
-  SEG="`echo $ip | cut -d '.' -f 4 2>/dev/null`"
-  echo $SEG | grep -E "^[0-9]+$" >/dev/null 2>/dev/null
-  if [ "$?" != "0" ]
-  then
-     return 1
-  fi
-  if [ $SEG -gt 255 -o $SEG -lt 0 ]
-  then
-     return 1
-  fi
-
-  return 0
-};
-
-### Print an error on STDERR and bail out
-printerror() {
-  echo >&2 "$*"
-  exit 1
-}
-
 ### Download the chroot
 downloadchroot() {
 
@@ -243,47 +170,6 @@
   touch ${JMETADIR}/xjail
 }
 
-isV6() {
-  echo ${1} | grep -q ":"
-  return $?
-}
-
-isDirZFS() {
-  local _chkDir="$1"
-  while :
-  do
-     # Is this dir a ZFS mount
-     mount | grep -w "on $_chkDir " | grep -qw "(zfs," && return 0
-
-     # Quit if not walking down
-     if [ "$2" = "1" ] ; then return 1 ; fi
-
-     if [ "$_chkDir" = "/" ] ; then break ; fi
-     _chkDir=`dirname $_chkDir`
-  done
-
-  return 1
-}
-
-
-getZFSTank() {
-  local _chkDir="$1"
-  while :
-  do
-     line=`mount | grep -w -e $_chkDir -e "(zfs,"`
-     mount | grep -qw -e $_chkDir -e "(zfs,"
-     if [ $? -eq 0 ] ; then 
-	echo $line | cut -d '/' -f -1 | awk '{print $1}'
-	return 0
-     fi
-
-     if [ "$_chkDir" = "/" ] ; then return 1 ; fi
-     _chkDir=`dirname $_chkDir`
-  done
-
-  return 1
-}
-
 mkZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
@@ -373,18 +259,6 @@
   echo "Snapshot cloned and mounted to: ${CDIR}/${3}-${2}"
 }
 
-# is_symlinked_mountpoint()
-#       Is a mount point, or any of its parent directories, a symlink?
-is_symlinked_mountpoint()
-{
-        local _dir
-        _dir=$1
-        [ -L "$_dir" ] && return 0
-        [ "$_dir" = "/" ] && return 1
-        is_symlinked_mountpoint `dirname $_dir`
-        return $?
-}
-
 set_warden_metadir()
 {
    JMETADIR="${JDIR}/.${IP}.meta"
@@ -400,9 +274,3 @@
    # Restart cron
    /etc/rc.d/cron restart >/dev/null 2>/dev/null
 }
-
-is_num()
-{
-        expr $1 + 1 2>/dev/null
-        return $?
-}



More information about the Commits mailing list