#!/bin/zsh ERRS=./err_file REPORT=./report makepath() { if [[ ${#1} -eq 0 || -d "$1" ]]; then return 0; fi if [[ "${1%/*}" = "$1" ]]; then mkdir "$1" return $? fi makepath ${1%/*} || return 1 mkdir "$1" return $? } rcsname() { echo ${1},v } checkargs() { if [[ $# != 2 ]]; then print -u2 "usage: makercs source dest" exit 1 fi if [[ ! -d "$1" ]]; then print -u2 "$1: Not a directory" exit 1 fi if [[ -a "$2" && ! -d "$2" ]]; then print -u2 "$2: Not a directory" exit 1 fi if [[ "$1" = "$2"* || "$2" = "$1"* ]]; then print -u2 "Cannot make one directory above or below the other." exit 1 fi return 0 } checkargs "$@" # Open error and report files exec 3>$ERRS exec 4>$REPORT source="$1" dest="$2" coproc find "$source" -print while read pathname <&p; do target=$dest${pathname#$source} if [[ -d "$pathname" ]]; then makepath "$target" || print -u3 "Cannot create directory $target" elif [[ -f "$pathname" ]]; then target=$(rcsname "$target") ci -l -q "-t-$pathname" "$pathname" "$target" >&4 2>&3 || print -u3 "Cannot create $target" else print -u4 "$pathname is not a directory or regular file: skipped" fi done exec 3<&- exec 4<&- # Remove error and report files if nothing in them! if [[ ! -s $ERRS ]]; then /bin/rm -f $ERRS; fi if [[ ! -s $REPORT ]]; then /bin/rm -f $REPORT; fi exit 0