dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit dc41d3d9a4f505d62d37ee4b91b840c49436d23b
parent 3ce0c5f7895c9c8282d8b828ab094bc63565193b
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Sun, 25 Aug 2019 12:53:02 +0200

Merge branch 'master' of gitlab.com:admesg/dotfiles

Diffstat:
A.local/bin/syncdir | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+), 0 deletions(-)

diff --git a/.local/bin/syncdir b/.local/bin/syncdir @@ -0,0 +1,73 @@ +#!/bin/sh +set -e + +version=0.1 +host=iddqd + +show_help() { + echo "usage: ${0##*/} DIR1 [DIR2 ...]" + echo "performs a two-way sync of the contents of the specified DIRs to $host" + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -H, --host VALUE use specified host instead of default ($host)" + echo " -- do not consider any following args as options" +} + +show_version() { + echo "${0##*/} version $version" + echo "Licensed under the GNU Public License, v3+" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://gitlab.com/admesg/dotfiles" +} + +die() { + printf '%s\n' "$1" >&2 + exit 1 +} + +sync_dir() { + echo "syncing $1 to $host" + rsync -rav --progress -e "ssh" "$1/" "$host":"$1/" + + echo "syncing $host to $1" + rsync -rav --progress -e "ssh" "$host":"$1/" "$1/" +} + +while :; do + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -H|--host) + host="$2" + shift + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift +done + +if [ $# -lt 1 ]; then + show_help + exit 1 +fi + +for d in "$@"; do + [ ! -d "$d" ] && die "Error: $d is not a directory" + sync_dir "$d" +done