Skip to content

Instantly share code, notes, and snippets.

@bfosterscripps
Created July 14, 2015 19:36
Show Gist options
  • Save bfosterscripps/705200240d5402ac9fe6 to your computer and use it in GitHub Desktop.
Save bfosterscripps/705200240d5402ac9fe6 to your computer and use it in GitHub Desktop.
Bash script to upload files to CQ java content repository
#!/bin/bash
# use by passing path to the file you wish to upload as first parameter,
# and passing JCR path (including filename and extension) as second parameter
function pause() {
rc=$?
if [[ $rc != 0 ]]; then
read -p "Press [Enter] to continue, there are errors above."
fi
}
function requestPass() {
username="162084"
#get password from user
echo -n "Enter password for $username. >"
read -s answer
pass="$answer"
echo ""
}
function specifyEnvironment() {
#DEPENDENCIES: requestPass()
#check to see if input was provided
if [ $# -eq 0 ]; then
#echo "No arguments supplied."
#reset environment so you can install to different place than build
env=""
read -p "Please specify Environment, e.g. dev4, prod2, or local. > " answer
specifyEnvironment $answer
echo -n ""
else
echo "You passed $1 into this and number of args is $#"
env=$1
if [[ "$env" != "local" ]]; then
requestPass
testEnvHostname="author1.hgtv-$env.sni.hgtv.com:4502"
envHttpCode="$(curl -u $username:$pass -sL --head -w %{http_code} http://$testEnvHostname -o /dev/null)"
if [[ "$envHttpCode" = "200" ]]; then
hostname="$testEnvHostname"
else
echo "$testEnvHostname returns a code of $envHttpCode,"
read -p "Please specify Environment, e.g. dev4, prod2, or local. > " answer
specifyEnvironment $answer
fi
elif [[ "$env" =~ "local" ]]; then
echo "Environment is local: $env"
#local hostname
hostname="localhost:4502"
username="admin"
pass="admin"
fi
fi
}
function getPaths(){
if [[ $# -gt 0 ]]; then
# the first parameter passed is the path to the file on your disk
filePathLocal="$1"
if [[ $# -gt 1 ]]; then
# second parameter, if it exists, is path to where you want it to go
filePathJcr="$2"
fi
else
read -p "Enter path to file you wish to upload. > " filePathLocal
read -p "Enter path to where you wish the file to be uploaded. > " filePathJcr
fi
}
function uploadFile(){
filePathLocal=""
filePathJcr=""
getPaths $1 $2
specifyEnvironment
echo "Uploading $filePathLocal to http://$hostname$filePathJcr"
read -p "Is this correct? (Y/n) > " confirmation
if [[ "$confirmation" = "Y" ]]; then
curl -u $username:$pass -T $filePathLocal http://$hostname$filePathJcr
pause
echo "Success!"
else
echo "You aren't ready (you gave me $confirmation instead of Y)..."
uploadFile
fi
}
uploadFile $1 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment