Ignore:
Timestamp:
04/15/13 13:06:48 (17 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.1-release, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
8901c47
Parents:
4d2a365
Message:

Merge changes from John Hixson and FreeNAS work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-sh/warden/scripts/backend/functions.sh

    r60738f3 r17235d6  
    3232WTMP="$(grep ^WTMP: /usr/local/etc/warden.conf | cut -d' ' -f2)" 
    3333export WTMP 
     34 
     35# FreeBSD release 
     36FREEBSD_RELEASE="$(grep ^FREEBSD_RELEASE: /usr/local/etc/warden.conf | cut -d' ' -f2)" 
     37if [ -z "${FREEBSD_RELEASE}" ] ; then 
     38  FREEBSD_RELEASE="$(uname -r)" 
     39fi 
     40export UNAME_r="${FREEBSD_RELEASE}" 
    3441 
    3542# Temp file for dialog responses 
     
    110117### Download the chroot 
    111118downloadchroot() { 
     119  local CHROOT="${1}" 
     120 
    112121  # XXX If this is PCBSD, pbreg get /PC-BSD/Version 
    113   SYSVER=`uname -r | cut -f1 -d'-'` 
    114   FBSD_TARBALL="fbsd-release.tbz" 
     122  SYSVER="$(echo "$(uname -r)" | cut -f1 -d'-')" 
     123  FBSD_TARBALL="fbsd-release.txz" 
    115124  FBSD_TARBALL_CKSUM="${FBSD_TARBALL}.md5" 
    116125 
     
    143152  isDirZFS "${JDIR}" 
    144153  if [ $? -eq 0 ] ; then 
    145     local zfsp=`getZFSRelativePath "${WORLDCHROOT}"` 
     154    local zfsp=`getZFSRelativePath "${CHROOT}"` 
    146155 
    147156    # Use ZFS base for cloning 
    148     echo "Creating ZFS ${WORLDCHROOT} dataset..." 
     157    echo "Creating ZFS ${CHROOT} dataset..." 
    149158    tank=`getZFSTank "${JDIR}"` 
    150     isDirZFS "${WORLDCHROOT}" "1" 
     159    isDirZFS "${CHROOT}" "1" 
    151160    if [ $? -ne 0 ] ; then 
    152161       zfs create -o mountpoint=/${tank}${zfsp} -p ${tank}${zfsp} 
     
    154163    fi 
    155164 
    156     tar xvpf ${FBSD_TARBALL} -C ${WORLDCHROOT} 2>/dev/null 
     165    tar xvpf ${FBSD_TARBALL} -C ${CHROOT} 2>/dev/null 
    157166    if [ $? -ne 0 ] ; then exit_err "Failed extracting ZFS chroot environment"; fi 
    158167 
     
    162171  else 
    163172    # Save the chroot tarball 
    164     mv ${FBSD_TARBALL} ${WORLDCHROOT} 
     173    mv ${FBSD_TARBALL} ${CHROOT} 
    165174  fi 
    166175  rm ${FBSD_TARBALL_CKSUM} 
     
    695704} 
    696705 
     706install_pc_extractoverlay() 
     707{ 
     708  if [ -z "${1}" ] ; then 
     709    return 1  
     710  fi  
     711 
     712  mkdir -p ${1}/usr/local/bin 
     713  mkdir -p ${1}/usr/local/share/pcbsd/conf 
     714  mkdir -p ${1}/usr/local/share/pcbsd/distfiles 
     715 
     716  cp /usr/local/bin/pc-extractoverlay ${1}/usr/local/bin/ 
     717  chmod 755 ${1}/usr/local/bin/pc-extractoverlay 
     718 
     719  cp /usr/local/share/pcbsd/conf/server-excludes \ 
     720    ${1}/usr/local/share/pcbsd/conf 
     721  cp /usr/local/share/pcbsd/distfiles/server-overlay.txz \ 
     722    ${1}/usr/local/share/pcbsd/distfiles 
     723 
     724  return 0 
     725} 
     726 
     727make_bootstrap_pkgng_file_standard() 
     728{ 
     729  local jaildir="${1}" 
     730  local outfile="${2}" 
     731 
     732  local release="$(uname -r)" 
     733  local arch="$(uname -m)" 
     734 
     735  get_mirror 
     736  local mirror="${VAL}" 
     737 
     738cat<<__EOF__>"${outfile}" 
     739#!/bin/sh 
     740tar xvf pkg.txz --exclude +MANIFEST --exclude +MTREE_DIRS 2>/dev/null 
     741pkg add pkg.txz 
     742rm pkg.txz 
     743 
     744echo "packagesite: ${mirror}/packages/${release}/${arch}" >/usr/local/etc/pkg.conf 
     745echo "HTTP_MIRROR: http" >>/usr/local/etc/pkg.conf 
     746echo "PUBKEY: /usr/local/etc/pkg-pubkey.cert" >>/usr/local/etc/pkg.conf 
     747echo "PKG_CACHEDIR: /usr/local/tmp" >>/usr/local/etc/pkg.conf 
     748pkg install -y pcbsd-utils 
     749exit $? 
     750__EOF__ 
     751} 
     752 
     753make_bootstrap_pkgng_file_pluginjail() 
     754{ 
     755 
     756  local jaildir="${1}" 
     757  local outfile="${2}" 
     758 
     759  local release="$(uname -r)" 
     760  local arch="$(uname -m)" 
     761 
     762  get_mirror 
     763  local mirror="${VAL}" 
     764 
     765  cp /usr/local/share/warden/pluginjail-packages "${jaildir}/pluginjail-packages" 
     766 
     767cat<<__EOF__>"${outfile}" 
     768#!/bin/sh 
     769tar xvf pkg.txz --exclude +MANIFEST --exclude +MTREE_DIRS 2>/dev/null 
     770pkg add pkg.txz 
     771rm pkg.txz 
     772 
     773mount -t devfs devfs /dev 
     774 
     775echo "packagesite: ${mirror}/packages/${release}/${arch}" >/usr/local/etc/pkg.conf 
     776echo "HTTP_MIRROR: http" >>/usr/local/etc/pkg.conf 
     777echo "PUBKEY: /usr/local/etc/pkg-pubkey.cert" >>/usr/local/etc/pkg.conf 
     778echo "PKG_CACHEDIR: /usr/local/tmp" >>/usr/local/etc/pkg.conf 
     779pkg install -y pcbsd-utils 
     780__EOF__ 
     781 
     782echo ' 
     783i=0 
     784count=`wc -l /pluginjail-packages| awk "{ print $1 }"` 
     785for p in `cat /pluginjail-packages` 
     786do 
     787  pkg install -y ${p} 
     788  : $(( i += 1 )) 
     789done 
     790 
     791umount devfs 
     792exit $? 
     793' >> "${outfile}" 
     794} 
     795 
     796 
    697797bootstrap_pkgng() 
    698798{ 
    699   cd ${1}  
    700   SYSVER="$(uname -r)" 
     799  local jaildir="${1}" 
     800  local jailtype="${2}" 
     801  if [ -z "${jailtype}" ] ; then 
     802    jailtype="standard" 
     803  fi 
     804  local release="$(uname -r)" 
     805  local arch="$(uname -m)" 
     806 
     807  local ffunc="make_bootstrap_pkgng_file_standard" 
     808  if [ "${jailtype}" = "pluginjail" ] ; then 
     809    ffunc="make_bootstrap_pkgng_file_pluginjail" 
     810  fi 
     811 
     812  cd ${jaildir}  
    701813  echo "Boot-strapping pkgng" 
    702   mkdir -p ${1}/usr/local/etc 
    703   cp /usr/local/etc/pkg-pubkey.cert ${1}/usr/local/etc/ 
    704   if [ $? -ne 0 ] ; then 
    705      echo "Failed copying /usr/local/etc/pkg-pubkey.cert" 
    706   fi 
    707  
    708   echo '#!/bin/sh 
    709   tar xvf pkg.txz --exclude +MANIFEST --exclude +MTREE_DIRS 2>/dev/null 
    710   pkg add pkg.txz 
    711   rm pkg.txz 
    712   ARCH=$(uname -m) 
    713   REL=$(uname -r) 
    714   echo "packagesite: http://ftp.pcbsd.org/pub/mirror/packages/$REL/$ARCH" >/usr/local/etc/pkg.conf 
    715   echo "PUBKEY: /usr/local/etc/pkg-pubkey.cert" >>/usr/local/etc/pkg.conf 
    716   echo "PKG_CACHEDIR: /usr/local/tmp" >>/usr/local/etc/pkg.conf 
    717   pkg install -y pcbsd-utils 
    718   exit $? 
    719 ' > ${1}/bootstrap-pkgng 
    720   chmod 755 ${1}/bootstrap-pkgng 
     814 
     815  mkdir -p ${jaildir}/usr/local/etc 
     816  pubcert="/usr/local/etc/pkg-pubkey.cert" 
     817 
     818  cp "${pubcert}" ${jaildir}/usr/local/etc 
     819  install_pc_extractoverlay "${jaildir}" 
     820 
     821  ${ffunc} "${jaildir}" "${jaildir}/bootstrap-pkgng" 
     822  chmod 755 "${jaildir}/bootstrap-pkgng" 
    721823 
    722824  if [ -e "pkg.txz" ] ; then rm pkg.txz ; fi 
    723   get_file_from_mirrors "/packages/${SYSVER}/${ARCH}/Latest/pkg.txz" "pkg.txz" 
     825  get_file_from_mirrors "/packages/${release}/${arch}/Latest/pkg.txz" "pkg.txz" 
    724826  if [ $? -eq 0 ] ; then 
    725     chroot ${1} /bootstrap-pkgng 
     827    chroot ${jaildir} /bootstrap-pkgng 
    726828    if [ $? -eq 0 ] ; then 
    727       rm ${1}/bootstrap-pkgng 
    728       chroot ${1} pc-extractoverlay server --sysinit 
     829      rm -f "${jaildir}/bootstrap-pkgng" 
     830      rm -f "${jaildir}/pluginjail-packages" 
     831      chroot ${jaildir} pc-extractoverlay server --sysinit 
    729832      return 0 
    730833    fi 
    731834  fi 
     835 
    732836  echo "Failed boot-strapping PKGNG, most likely cause is internet connection failure." 
    733   rm ${1}/bootstrap-pkgng 
     837  rm -f "${jaildir}/bootstrap-pkgng" 
     838  rm -f "${jaildir}/pluginjail-packages" 
    734839  return 1 
    735840} 
     
    746851 
    747852   ${jexec} ifconfig "${iface}" | grep -qw inet 2>/dev/null 
     853   return $? 
     854} 
     855 
     856ipv4_address_configured() 
     857{ 
     858   local iface="${1}" 
     859   local addr="${2}" 
     860   local jid="${3}" 
     861   local jexec=  
     862 
     863   addr="$(echo ${addr}|cut -f1 -d'/')" 
     864 
     865   if [ -n "${jid}" ] ; then 
     866      jexec="jexec ${jid}" 
     867   fi 
     868 
     869   ${jexec} ifconfig "${iface}" | \ 
     870      grep -w inet | \ 
     871      awk '{ print $2 }' | \ 
     872      grep -Ew "^${addr}" >/dev/null 2>&1 
     873   return $? 
    748874} 
    749875 
     
    759885 
    760886   ${jexec} ifconfig "${iface}" | grep -qw inet6 2>/dev/null 
    761 } 
     887   return $? 
     888} 
     889 
     890ipv6_address_configured() 
     891{ 
     892   local iface="${1}" 
     893   local addr="${2}" 
     894   local jid="${3}" 
     895   local jexec=  
     896 
     897   addr="$(echo ${addr}|cut -f1 -d'/')" 
     898 
     899   if [ -n "${jid}" ] ; then 
     900      jexec="jexec ${jid}" 
     901   fi 
     902 
     903   ${jexec} ifconfig "${iface}" | \ 
     904      grep -w inet6 | \ 
     905      awk '{ print $2 }' | \ 
     906      grep -Ew "^${addr}" >/dev/null 2>&1 
     907   return $? 
     908} 
     909 
     910get_ipfw_nat_instance() 
     911{ 
     912   local iface="${1}" 
     913   local res=1 
     914 
     915   if [ -z "${iface}" ] ; then 
     916      local instance="`ipfw list|egrep '[0-9]+ nat'|awk '{ print $3 }'|tail -1`" 
     917      if [ -z "${instance}" ] ; then 
     918         instance="100" 
     919      else                 
     920         : $(( instance += 100 ))  
     921      fi 
     922      echo "${instance}" 
     923      return 0 
     924   fi 
     925 
     926   for ni in `ipfw list|egrep '[0-9]+ nat'|awk '{ print $3 }'` 
     927   do 
     928      ipfw nat "${ni}" show config|egrep -qw "${iface}" 
     929      if [ "$?" = "0" ] ; then 
     930         echo "${ni}" 
     931         res=0 
     932         break 
     933      fi 
     934   done 
     935 
     936   return ${res} 
     937} 
     938 
     939get_ipfw_nat_priority() 
     940{ 
     941   local iface="${1}" 
     942   local res=1 
     943 
     944   if [ -z "${iface}" ] ; then 
     945      local priority="`ipfw list|egrep '[0-9]+ nat'|awk '{ print $1 }'|tail -1`" 
     946      if [ -z "${priority}" ] ; then 
     947         priority=2000 
     948      fi 
     949      printf "%05d\n" "${priority}" 
     950      return 0 
     951   fi 
     952 
     953   local IFS=' 
     954' 
     955   for rule in `ipfw list|egrep '[0-9]+ nat'` 
     956   do 
     957      local priority="`echo "${rule}"|awk '{ print $1 }'`" 
     958      local ni="`echo "${rule}"|awk '{ print $3 }'`" 
     959 
     960      ipfw nat "${ni}" show config|egrep -qw "${iface}" 
     961      if [ "$?" = "0" ] ; then 
     962         echo "${priority}" 
     963         res=0 
     964         break 
     965      fi 
     966   done 
     967 
     968   return ${res} 
     969} 
     970 
Note: See TracChangeset for help on using the changeset viewer.