-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-ftp.sh
98 lines (78 loc) · 2.33 KB
/
sync-ftp.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
#!/bin/sh
# ==============================================================================
# FTP SYNC script
# ==============================================================================
#
# Requirements:
# -------------------------------
# This script requires lftp. To install on Mac OS X, obtain brew
# <http://mxcl.github.io/homebrew/> and run the following command:
#
# brew install lftp
#
# That will install dependencies needed and the lftp application. An update might
# be needed for this to work in which case you can run `brew update`.
#
#
# Usage:
# -------------------------------
# See README.md
#
# Author: Richard Sumilang <[email protected]>
# Date: April 17th, 2013
#==========================================================
# Arguments
#==========================================================
SOURCE_PATH=$2
DEPLOY_PATH=$3
PROTOCOL=$4
#==========================================================
# Determine what configuration to use
#==========================================================
if [ -z $1 ]; then
echo $"Usage: $0 config-file.sh source-path deploy-path [protocol]"
exit 1
fi
CONFIG="$1"
if [ -e $CONFIG ]; then
source $CONFIG
else
echo "Error: Configuration not valid. Please check path."
exit 2
fi
#==========================================================
# Check if source directory is valid
#==========================================================
if [ ! -d $SOURCE_PATH ]; then
echo "Invalid source path: \"$SOURCE_PATH\""
exit 3
fi
#==========================================================
# Check whether or not to remove deleted files
#==========================================================
if [ $DELETE -eq 1 ]; then
DELETE_ARG="--delete";
else
DELETE_ARG="";
fi
#==========================================================
# Set $PROTOCOL to ftp as default
#==========================================================
if [ -z "$PROTOCOL" ]; then
PROTOCOL="ftp"
fi
#==========================================================
# Start the sync
#==========================================================
echo "Syncing \"$SOURCE_PATH\"..."
lftp -c "set ftp:list-options -a;
open $PROTOCOL://$USER:$PASS@$HOST;
lcd $SOURCE_PATH;
cd $DEPLOY_PATH;
mirror --reverse $DELETE_ARG \
--verbose \
--exclude-glob .DS_Store $MIRROR_OPTIONS
$ADD_CMDS
bye
"
echo "Done syncing \"$SOURCE_PATH\" files..."