fix typo in manual page
[rsync.git] / packaging / samba-rsync
blob8691846a016f4e1f17de92c68ace17dcdaf58a67
1 #!/bin/bash
2 # This script makes it easy to update the ftp & html directories on the samba.org server.
3 # It expects the 2 *_DEST directories to contain updated files that need to be sent to
4 # the remote server. If these directories don't exist yet, they will be copied from the
5 # remote server (while also making the html dir a git checkout).
7 FTP_SRC="$HOME/samba-rsync-ftp"
8 HTML_SRC="$HOME/samba-rsync-html"
10 FTP_DEST="/home/ftp/pub/rsync"
11 HTML_DEST="/home/httpd/html/rsync"
13 HTML_GIT='git.samba.org:/data/git/rsync-web.git'
15 export RSYNC_PARTIAL_DIR=''
17 case "$RSYNC_SAMBA_HOST" in
18 *.samba.org) ;;
20 echo "You must set RSYNC_SAMBA_HOST in your environment to the samba hostname to use." >&2
21 exit 1
23 esac
25 MODE=''
26 REVERSE=''
27 while (( $# )); do
28 case "$1" in
29 -R|--reverse) REVERSE=yes ;;
30 f|ftp) MODE=ftp ;;
31 h|html) MODE=html ;;
32 -h|--help)
33 echo "Usage: [-R] [f|ftp|h|html]"
34 echo "-R --reverse Copy the files from the server to the local host."
35 echo " The default is to update the remote files."
36 echo "-h --help Output this help message."
37 echo " "
38 echo "The script will prompt if ftp or html is not specified on the command line."
39 echo "Only one category can be copied at a time. When pulling html files, a git"
40 echo "checkout will be either created or updated prior to the rsync copy."
41 exit
44 echo "Invalid option: $1" >&2
45 exit 1
47 esac
48 shift
49 done
51 while [ ! "$MODE" ]; do
52 if [ "$REVERSE" = yes ]; then
53 DIRECTION=FROM
54 else
55 DIRECTION=TO
57 echo -n "Copy which files $DIRECTION the server? ftp or html? "
58 read ans
59 case "$ans" in
60 f*) MODE=ftp ;;
61 h*) MODE=html ;;
62 '') exit 1 ;;
63 *) echo "You must answer f or h to copy the ftp or html data." ;;
64 esac
65 done
67 if [ "$MODE" = ftp ]; then
68 SRC_DIR="$FTP_SRC"
69 DEST_DIR="$FTP_DEST"
70 FILT=".filt"
71 else
72 SRC_DIR="$HTML_SRC"
73 DEST_DIR="$HTML_DEST"
74 FILT="filt"
77 function do_rsync {
78 rsync --dry-run "${@}" | grep -v 'is uptodate$'
79 echo ''
80 echo -n "Run without --dry-run? [n] "
81 read ans
82 case "$ans" in
83 y*) rsync "${@}" | grep -v 'is uptodate$' ;;
84 esac
87 if [ -d "$SRC_DIR" ]; then
88 REVERSE_RSYNC=do_rsync
89 else
90 echo "The directory $SRC_DIR does not exist yet."
91 echo -n "Do you want to create it? [n] "
92 read ans
93 case "$ans" in
94 y*) ;;
95 *) exit 1 ;;
96 esac
97 REVERSE=yes
98 REVERSE_RSYNC=rsync
101 if [ "$REVERSE" = yes ]; then
102 OPTS='-aivOHP'
103 TMP_FILT="$SRC_DIR/tmp-filt"
104 echo "Copying files from $RSYNC_SAMBA_HOST to $SRC_DIR ..."
105 if [ "$MODE" = html ]; then
106 if [ $REVERSE_RSYNC = rsync ]; then
107 git clone "$HTML_GIT" "$SRC_DIR" || exit 1
108 else
109 cd "$SRC_DIR" || exit 1
110 git pull || exit 1
112 sed -n -e 's/[-P]/H/p' "$SRC_DIR/$FILT" >"$TMP_FILT"
113 OPTS="${OPTS}f._$TMP_FILT"
114 else
115 OPTS="${OPTS}f:_$FILT"
117 $REVERSE_RSYNC "$OPTS" "$RSYNC_SAMBA_HOST:$DEST_DIR/" "$SRC_DIR/"
118 rm -f "$TMP_FILT"
119 exit
122 cd "$SRC_DIR" || exit 1
123 echo "Copying files from $SRC_DIR to $RSYNC_SAMBA_HOST ..."
124 do_rsync -aivOHP --del -f._$FILT . "$RSYNC_SAMBA_HOST:$DEST_DIR/"