All pastes #950299 Raw Edit

Untitled

public text v1 · immutable
·published 2008-03-20 14:03 UTC
rendered paste body
#!/bin/bash


echo ""
echo ""
echo "************************************"
echo "* UPLOAD SCRIPT © YOUDS MEDIA 2008 *"
echo "************************************"
echo "Utilises the rsync command on both sides of the transfer"
echo ""


if [[ $1 == '' || $2 == '' || $3 == '' ||  $4 == '' ]]
  then
echo "Usage:"
echo "  upload (put|get) [-absolute] local remote [domain]"
echo ""
echo "Options:"
echo "  -h          Display this message"
echo "  -absolute   Use absolute paths for local and remote"
echo ""
echo "nb: when there is neither options passed the folder structure the script was written for is used"
echo ""

echo ""
echo "Example 1:"
echo "  upload put youds default youds.com"
echo ""
echo "This would upload the contains of folder: ~/Applications/xampp/htdocs/youds/ to /home/default/youds.com/user/htdocs"
echo ""

echo ""
echo "Example 2:"
echo "  upload get -absolute '~/Documents/YOUDS/Web Design/UDS' /home/default/youds.com/user/htdocs"
echo ""
echo "NOTE: NO TRAILING SLASH - Including the trailing slash would cause the htdocs folder to be transferred (because it's get is passed)"
echo ""
echo "This would transfer the contents of the folders to and from the designated location, because -absolute was passed."
  exit 1
fi

if [[ $1 != 'put' && $1 != 'get' ]]
  then
    echo "First argument must be put or get"
    echo ""
    exit 1
fi

if [[ $1 == 'put' ]]
  then
  if [[ $2 == '-absolute' ]]
    then
      absolute=TRUE
      local=$3
      remote=$4   
      echo $absolute
      echo $local/
      echo $remote/ 
      /Applications/xampp/xamppfiles/bin/php-5.2.5 /scripts/cleanFiles.php $local/
      chmod -R 755 $local/
      chown -R apache $local/
      rsync -avz $local/ youds.com:$remote/ 
      /Applications/xampp/xamppfiles/bin/php-5.2.5 /scripts/Files.php $local/
      exit 1
  fi
 
  if [[ $3 == '' || $4 == '' ]] 
    then 
      echo "Not enough parameters passed"
      echo "Did you pass group and domain?"
      exit 1
  fi
 
  if [ -d /users/craigfairhurst/Sites/$2/ ]  
    then
      absolute=FALSE
      local=/users/craigfairhurst/Sites/$2/
      remote=/home/$3/$4/user/htdocs/
      /Applications/xampp/xamppfiles/bin/php-5.2.5 /scripts/cleanFiles.php $local
      chmod -R 755 $local
      rsync -avz $local youds.com:$remote
      /Applications/xampp/xamppfiles/bin/php-5.2.5 /scripts/Files.php $local
      exit 1
  fi
  echo "Local directory not valid:"
  echo $local
  echo ""
  exit 1
fi

if [[ $1 == 'get' ]]
  then
  if [[ $2 == '-absolute' ]]
    then
      absolute=TRUE
      local=$3
      remote=$4
      echo $absolute
      echo $local/
      echo $remote/
      rsync -avz youds.com:$remote/ $local/
      exit 1
  fi

  if [[ $3 == '' || $4 == '' ]]
    then
      echo "Not enough parameters passed"
      echo "Did you pass group and domain?"
      exit 1
  fi

  if [ -d /users/craigfairhurst/Sites/$2/ ] 
    then
      absolute=FALSE
      local=/users/craigfairhurst/Sites/$2/
      remote=/home/$3/$4/user/htdocs/
      rsync -avz youds.com:$remote $local
      exit 1
  fi
  echo "Local directory not valid"
  echo $local
  echo ""
  exit 1
fi