Commit 82872f7b authored by Ambrevar's avatar Ambrevar
Browse files

local/bin/rshare: Init.

parent 137b68fb
#!/bin/sh
PORT=8888
CONFIG=$HOME/.config/rsync/rsync.conf
CACHE_DIR=$HOME/.cache/rsyncd
IP=$(ip addr | awk '/state UP/ {getline; getline; $0=$2; gsub(/\/.*/, "");print; exit}')
usage () {
cat <<EOF>&2
Usage: ${0##*/} PATH
Startup an rsync daemon and share PATH as read-only under the 'files' module.
Clients can sync with, for instance:
rsync -iavzzP rsync://$IP:$PORT/files
Options:
-p PORT: Specify a port number (default: $PORT).
Must be above 1024 to run without privileges.
EOF
}
while getopts ":hp:" opt; do
case $opt in
h)
usage
exit ;;
p)
PORT="$OPTARG" ;;
\?)
usage
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
[ $# -ne 1 ] && usage && exit 1
[ "$1" = "-h" ] && usage && exit
[ "$1" = "--" ] && shift
mkdir -p "$(dirname "$CONFIG")" "$CACHE_DIR"
TARGET=$(realpath "$1")
cat<<EOF>"$CONFIG"
pid file = $CACHE_DIR/rsyncd.pid
lock file = $CACHE_DIR/rsyncd.lock
log file = $CACHE_DIR/rsyncd.log
port = $PORT
use chroot = false
[files]
path = $TARGET
comment = Rsync share
read only = true
timeout = 300
EOF
rsync --daemon --config="$CONFIG" && \
echo "rsync daemon listening on $IP:$PORT"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment