blob: f3fae2751c8adeface0dccb47915e84dc8132e79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#! /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;;
-c|--no-create) NO_CREATE=1;;
-u|--force-update) FORCE_UPDATE=1;;
*) 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}
NO_CREATE=${NO_CREATE:-0}
FORCE_UPDATE=${ORCE_UPDATE:-0}
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 copy() {
echo -e " copy ${PURPLE}${1}${RESET} into ${CYAN}${2}${RESET}" && cp ${1} ${2}
}
function update() {
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 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
copy ${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}
elif [ $NO_CREATE -eq 0 ];then
create ${dir} ${task_file} ${dest}
fi
done
echo -e " leave ${BROWN}${dir}${RESET}\n" && cd .. || exit 1
done
echo -e "leave ${BROWN}${gitdir}${RESET}"
done
|