#! /bin/sh for arg in $@; do option=`echo "'$arg'" | cut -d'=' -f1 | tr -d "'"` value=`echo "'$arg'" | cut -d'=' -f2- | tr -d "'"` if [ "$value" == "$option" ]; then value=""; fi case "$option" in -d|--git-dir) GIT_DIR=$value;; -t|--tasks-dir) TASKS_DIR=$value;; *) GIT_REMOTE=$arg;; esac done GIT_DIR=${GIT_DIR:-$HOME/usr/git} TASKS_DIR=${TASKS_DIR:-$GIT_DIR/templates/ruby-gem/tasks} DIFF_OPTS=${DIFF_OPTS:--y --suppress-common-lines} RESET="\033[0m" RED="\033[0;31m" GREEN="\033[0;32m" BROWN="\033[0;33m" PURPLE="\033[0;35m" CYAN="\033[0;36m" YELLOW="\033[1;33m" function update() { echo -e "\n${BROWN}${1}${RESET} : ${YELLOW}${2} ${PURPLE}${3}${RESET} differs ..." diff ${DIFF_OPTS} ${3} ${2} read -p " update it? [yN]" RET if [ "${RET}" = "Y" -o "${RET}" = "y" ]; then cp ${2} ${3} fi } function copy() { echo -e "\n${BROWN}${1}${RESET} : ${PURPLE}${3}${RESET} does not exists" read -p " create it? [yN]" RET if [ "${RET}" = "Y" -o "${RET}" = "y" ]; then cp ${2} ${3} fi } echo -e "task dir:${YELLOW}${TASKS_DIR}${RESET}" for gitdir in ${GIT_DIR}; do echo -e "enter ${BROWN}${gitdir}${RESET}" && cd ${gitdir} || return 1 for dir in $(ls -1); do [ -d ${dir} ] && [ -e ${dir}/tasks/gem.rake ] || continue # SEARCH REMOTE echo -e " enter ${BROWN}${dir}${RESET}" && cd $dir || exit 1 for task_file in ${TASKS_DIR}/*; do dest="./tasks/${task_file##*/}" if [ -e $dest ]; then cmp -s ${task_file} ${dest} || update ${dir} ${task_file} ${dest} else copy ${dir} ${task_file} ${dest} fi done echo -e " leave ${BROWN}${dir}${RESET}\n" && cd .. || exit 1 done echo -e "leave ${BROWN}${gitdir}${RESET}" done