Last active
December 14, 2016 18:20
-
-
Save vmattos/d2f4372b5f16e8a3dd5d04ef2ee054f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Deploys project to WebDAV-compliant server | |
# Uses a package.json for semantic versioning | |
# Requires: curl, jq | |
# Required env vars: | |
# WEBDAV_REMOTE: remote url of WebDAV-compliant server. Protocol and path included | |
# WEBDAV_PROJECT: project name | |
# WEBDAV_USER: basic auth/digest user name | |
# WEBDAV_PASS: basic auth/digest password | |
PRD_REGEXP=[0-9]+\.[0-9]+\.[0-9]+$ | |
VERSION=$(cat ./package.json | jq .version | sed s/\"//g) | |
URL=$WEBDAV_REMOTE/$WEBDAV_PROJECT/$VERSION | |
# Creates version directory | |
echo "Creating directory $URL" | |
curl -s -u $WEBDAV_USER:$WEBDAV_PASS --insecure -X MKCOL $URL 1>/dev/null | |
# Creates directory tree in the remote server | |
DIR_LIST=$(find build/ -type d -print) | |
for f in $DIR_LIST; do | |
DIR=$(echo $f | sed s/build//g) | |
REMOTE_DIR=$URL$DIR | |
echo "Creating directory $REMOTE_DIR..." | |
curl -s -u $WEBDAV_USER:$WEBDAV_PASS --insecure -X MKCOL $REMOTE_DIR 1>/dev/null | |
done | |
# Uploads files to remote server | |
FILES_LIST=$(find build/ -type f -print) | |
for f in $FILES_LIST; do | |
FILE=$(echo $f | sed s/build//g) | |
REMOTE_FILE=$URL$FILE | |
echo "Uploading file $f..." | |
curl -s -u $WEBDAV_USER:$WEBDAV_PASS --insecure -T $f $REMOTE_FILE 1>/dev/null & | |
done | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
echo "Finishing. Please wait..." | |
echo "This may take a while" | |
wait | |
echo -e "${GREEN}Done!${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment