diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-03 21:43:10 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-03 21:43:10 +0100 |
commit | 037579d9b1843b5696c148c31f84908e24a388e4 (patch) | |
tree | 92f85362e94145194a50f5348b0ed3478b04c0b1 | |
parent | 179b0d5750cd5a6263563858ade46815d434c4d9 (diff) | |
download | bin-037579d9b1843b5696c148c31f84908e24a388e4.zip bin-037579d9b1843b5696c148c31f84908e24a388e4.tar.gz |
deploy-ruby-tasks: add -u --force-update and -c --no-create flags
-rwxr-xr-x | deploy-ruby-tasks | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/deploy-ruby-tasks b/deploy-ruby-tasks index e1d3321..f3fae27 100755 --- a/deploy-ruby-tasks +++ b/deploy-ruby-tasks @@ -7,6 +7,8 @@ for arg in $@; do case "$option" in -d|--git-dir) GIT_DIR=$value;; -t|--tasks-dir) TASKS_DIR=$value;; + -c|--no-create) NO_CREATE=1;; + -u|--force-update) FORCE_UPDATE=1;; *) GIT_REMOTE=$arg;; esac done @@ -14,6 +16,8 @@ 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} +NO_CREATE=${NO_CREATE:-0} +FORCE_UPDATE=${ORCE_UPDATE:-0} RESET="\033[0m" RED="\033[0;31m" @@ -23,20 +27,28 @@ PURPLE="\033[0;35m" CYAN="\033[0;36m" YELLOW="\033[1;33m" +function copy() { + echo -e " copy ${PURPLE}${1}${RESET} into ${CYAN}${2}${RESET}" && cp ${1} ${2} +} + 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} + if [ $FORCE_UPDATE -eq 1 ]; then + echo -n -e "\n${RED}${1}${RESET} : " && copy ${2} ${3} + else + echo -e "\n${RED}${1}${RESET} : ${PURPLE}${2} ${CYAN}${3}${RESET} differs ..." + diff ${DIFF_OPTS} ${3} ${2} + read -p " update it? [yN]" RET + if [ "${RET}" = "Y" -o "${RET}" = "y" ]; then + copy ${2} ${3} + fi fi } -function copy() { - echo -e "\n${BROWN}${1}${RESET} : ${PURPLE}${3}${RESET} does not exists" +function create() { + echo -e "\n${RED}${1}${RESET} : ${CYAN}${3}${RESET} does not exists" read -p " create it? [yN]" RET if [ "${RET}" = "Y" -o "${RET}" = "y" ]; then - cp ${2} ${3} + copy ${2} ${3} fi } @@ -51,8 +63,8 @@ for gitdir in ${GIT_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} + elif [ $NO_CREATE -eq 0 ];then + create ${dir} ${task_file} ${dest} fi done echo -e " leave ${BROWN}${dir}${RESET}\n" && cd .. || exit 1 |