-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.sh
159 lines (149 loc) · 3.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
USER="" # Your username
PASS="" # Your password
HOST="" # Your hostname (e.g. example.com)
LCD="." # Your local directory
RCD="/public_html/" # Your remote server directory (e.g. /var/www/example.com)
EXCLUDE="
--exclude web/images \
--exclude web/cpresources \
--exclude vendor \
--exclude storage \
--exclude node_modules \
--exclude deploy.sh \
--exclude .idea \
--exclude .git \
--exclude .env \
--exclude .DS_Store \
"
watch() {
echo watching folder "$1"
while true
do
files=$(find "$1" -type f -mtime -2s)
if [[ $files == "" ]] ; then
sleep 2
else
echo changed, "$files"
push
sleep 2
fi
done
}
function push(){
if [[ -n "$SSH" ]]; then
rsync -r --update $EXCLUDE -v -e "$SSHCONFIG" $LCD/$PUSH $USER@$HOST:$RCD/$PUSH
else
lftp -f "
open $HOST
user $USER '$PASS'
lcd $LCD
set ftp:ssl-allow no
mirror ${EXCLUDE//[$'\t\r\n\\']} --reverse --continue --parallel=2 $LCD/$PUSH $RCD/$PUSH
"
fi
}
function pull(){
if [[ -n "$SSH" ]]; then
rsync -r --update $EXCLUDE -v -e "$SSHCONFIG" $USER@$HOST:$RCD/$PULL $LCD/$PULL
else
lftp -f "
open $HOST
user $USER '$PASS'
lcd $LCD
set ftp:ssl-allow no
mirror ${EXCLUDE//[$'\t\r\n\\']} --only-newer --continue --parallel=2 $RCD/$PULL $LCD/$PULL
"
fi
}
PARAMS=""
while (( "$#" )); do
case "$1" in
-b|--build)
BUILD="true"
shift 1
;;
-w|--watch)
WATCH=$2
shift 2
;;
-u|--push)
PUSH=$2
shift 2
;;
-p|--pull)
PULL=$2
shift 2
;;
-s|--ssh)
SSH=true
shift 1
;;
--upload-vendor)
VENDOR=true
shift 1
;;
-h|--help)
echo "
Mini Craft Scripts 0.2.2
-u|--push [path] Upload stuff to server.
-p|--pull [path] Download stuff from server.
-w|--watch [path] Watch for local filesystem changes.
-s|--ssh Sync stuff with ssh configuration, default is ftp.
--upload-vendor This command quickly upload the vendor folder using zip.
-b|--build Run yarn dev before deploy.
-h|--help This help.
Example:
bash deploy.sh --ssh --watch templates
bash deploy.sh --pull web/images
bash deploy.sh --build
"
exit 0
;;
--) # end argument parsing
shift
break
;;
-*) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
if [[ -n "$VENDOR" ]]; then
if [[ -n "$SSH" ]]; then
zip -r vendor.zip vendor
bash deploy.sh --ssh -u vendor.zip
$SSHCONFIG $USER@$HOST "cd $RCD && unzip vendor.zip";
rm vendor.zip
exit 0
else
zip -r vendor.zip vendor
lftp -f "
open $HOST
user $USER '$PASS'
lcd $LCD
set ftp:ssl-allow no
mput $LCD/vendor.zip $RCD/vendor.zip
"
rm vendor.zip
echo "Use your hosting provider panel to unzip the vendor folder."
exit 0
fi
fi
if [[ -n "$BUILD" ]]; then
yarn dev
fi
if [[ -n "$WATCH" ]]; then
watch "$WATCH"
else
if [[ -n "$PULL" ]]; then
pull
else
push
fi
fi