-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
95 lines (86 loc) · 2.93 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Run with ./deploy.sh
# Params: subfolder, *project-name
# (starred params are optional)
# subfolder - Where the project should deploy (2018, tools, etc)
# NOTE: ^ this script will not create subfolders! They must already exist.
# project-name (optional) - What the project should be called (the repo name by default)
# Var to track our error state
e="success"
# Callout color for important info
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No color
# Spinner graphic for the upload delay
spinner(){
local pid=$!
local delay=0.15
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " (%c)" "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
if [ -z "$1" ]; then
echo -e "${RED}ERROR:${NC} No valid subfolder supplied!"
echo "Exiting deploy script with error..."
exit 1
fi
if [ -z "$2" ]; then
# If no name supplied, we can assume it's the repo name
path="${PWD##*/}"
else
# Use supplied name if there is one
path="$2"
fi
# Test if we can access the Projects folder
if [ -d "/Volumes/SFGextras/Projects/" ]; then
echo -e "${GREEN}SUCCESS:${NC} Accessed Projects folder."
# Test if we can access the specified subfolder
if [ -d "/Volumes/SFGextras/Projects/$1" ]; then
echo -e "${GREEN}SUCCESS:${NC} Accessed $1 folder."
# Prompt before we pull the trigger
echo -e "All systems go. You are going to deploy ${RED}${PWD##*/}${NC} to the live Projects server in subfolder ${RED}$1${NC} with name ${RED}$path${NC}."
read -p "Proceed (Y/n)? " -n 1 -r
echo "" # For spacing
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "User confirmed deployment. Starting..."
echo "Removing any existing query strings..."
replaceJS="s/\.js?.*?(?=(\"|\'))/\.js/g"
replaceCSS="s/\.css?.*?(?=(\"|\'))/\.css/g"
perl -pi -e $replaceJS build/*.html
perl -pi -e $replaceCSS build/*.html
echo "Appending cache-busting strings..."
random=`date +%s`
replaceJS="s/\.js/\.js?$random/g"
replaceCSS="s/\.css/\.css?$random/g"
perl -pi -e $replaceJS build/*.html
perl -pi -e $replaceCSS build/*.html
echo "Uploading files to server..."
cp -a build/. "/Volumes/SFGextras/Projects/$1/$path" &
spinner
echo "Change index.html to index.php on server"
startpath="/Volumes/SFGextras/Projects/$1/$path/index.html"
endpath="/Volumes/SFGextras/Projects/$1/$path/index.php"
mv $startpath $endpath
echo -e "${GREEN}DEPLOY COMPLETE.${NC} Exiting..."
else
echo "INFO: User cancelled deployment. Exiting..."
fi
else
# We couldn't access subfolder
echo -e "${RED}ERROR:${NC}: Subfolder $1 does not exist or cannot be accessed!"
e="error"
fi
else
# We couldn't access /Projects/
echo -e "${RED}ERROR:${NC}: Projects folder does not exist or cannot be accessed!"
e="error"
fi
if [ "$e" == "error" ]; then
echo "Exiting deploy script with error..."
fi