-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombish-cli
More file actions
executable file
·166 lines (138 loc) · 4.48 KB
/
combish-cli
File metadata and controls
executable file
·166 lines (138 loc) · 4.48 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
## TODO: How to add this as a combish script itself to ease maintenance?
##
#!/bin/bash
cmd=$1 ## 'build', 'detach' and 'generate' only supported for now.
## TODO: Add 'help' and 'del' to ease cleanup.
## 'integ' for "detached" ones that got maintained
## separately for some time and must be re-integrated
src=$2
more_opt=$3 ## used as 2nd parameter to cmd, to add an option to "init/00/<src>/modifiers.bash.inc"
## e.g. script_group=psefilters/bin/utils
COMBISH_ROOTDIR=$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)
BUILD_ROOTDIR="${COMBISH_ROOTDIR}/build"
INIT_ROOTDIR="${COMBISH_ROOTDIR}/init"
LIB_ROOTDIR="${COMBISH_ROOTDIR}/lib"
MAIN_ROOTDIR="${COMBISH_ROOTDIR}/main"
DETACHED_ROOTDIR="${BUILD_ROOTDIR}/detach/${src}"
usage_syntax() {
echo 'Usage: combish-cli <cmd> <src_name>'
echo 'Following commands are supported:'
echo ' * build'
echo ' * detach'
echo ' * generate'
echo
exit 1
} ## END: usage_syntax()
## Missing $src is a blocker ...
##
if [[ $# -lt 2 ]]; then
echo 'ERROR: Too few parameters, aborted!'
usage_syntax
echo 'Available projects:'
for x in $(ls -1d $MAIN_ROOTDIR/*); do
echo "* $(basename $x)"
done
echo
exit 1
fi
## dir2git - Add a simple file to a directory to make it eligible for git commit
##
dir2git() {
local dir2mark=$1
cat > ${dir2mark}/.gitignore << EOL
# Ignore everything in this directory
#~*
# Except this file
!.gitignore
EOL
} ## END: dir2git()
create_detached_runner() {
local src=$1
cat > $DETACHED_ROOTDIR/run_${src}.sh << EOL
#!/bin/bash
COMBISH_ROOTDIR=\$(cd "\$(dirname "\${BASH_SOURCE[1]}")" && pwd)
## Source the core code ...
##
source \$COMBISH_ROOTDIR/init/00/combish.bash.inc
## call it..
combish $src
EOL
} ## END: create_detached_runner()
create_default_main() {
local src=$1
cat > $MAIN_ROOTDIR/${src}/main.bash.inc << EOL
main() {
:
} ## END: main()
main
EOL
} ## END: create_default_main()
case $cmd in
build)
## -------------------------------------
## source specified, proceed below ...
## -------------------------------------
## Source the core code ...
##
source $INIT_ROOTDIR/00/combish.bash.inc
## call it..
combish $src
;;
detach)
DETACHED_ROOTDIR="${BUILD_ROOTDIR}/detach/${src}"
mkdir -p ${DETACHED_ROOTDIR}/build
## Copy all "init/00" (since detached on cannot function without combish tooling)
rsync -avz ${INIT_ROOTDIR}/00 ${DETACHED_ROOTDIR}/init/
## Copy all "init/01/${src}
rsync -avz ${INIT_ROOTDIR}/01/${src} ${DETACHED_ROOTDIR}/init/01/
## Copy all "init/10/${src}"
rsync -avz ${INIT_ROOTDIR}/10/${src} ${DETACHED_ROOTDIR}/init/10/
## Copy all "init/10/common"
## TODO: Restrict copying to common.txt
rsync -avz ${INIT_ROOTDIR}/10/common ${DETACHED_ROOTDIR}/init/10/
## Copy all "lib/${src}"
rsync -avz ${LIB_ROOTDIR}/${src} ${DETACHED_ROOTDIR}/lib/
## Copy all "lib/common" (but only the ones specified in earlier common.txt
## TODO: Restrict copying to common.txt
rsync -avz ${LIB_ROOTDIR}/${common} ${DETACHED_ROOTDIR}/lib/
## Copy all "main/${src}"
rsync -avz ${MAIN_ROOTDIR}/${src} ${DETACHED_ROOTDIR}/main/
## TODO: Create run_${src}.sh as runner
create_detached_runner $src
;;
generate)
## Check first that <src> isn't an existing one.
##
src_main="${MAIN_ROOTDIR}/${src}"
if [[ -d ${src_main} ]]; then
echo "ERROR: Cannot proceed. '${src}' already exist."
exit 1
fi
## No duplicate src? Proceed
## TODO: Add some readme as guide on what each dir is for
gen_list="
${INIT_ROOTDIR}/01/${src}
${INIT_ROOTDIR}/10/${src}
${LIB_ROOTDIR}/${src}
${src_main}
"
for each_item in $gen_list; do
mkdir -pv $each_item
dir2git $each_item ## make it eligible for 'git add'
done
## add default main script
create_default_main ${src}
## $more_opt given? Process it
if [[ "$more_opt" != "" ]]; then
modifier_rootdir=${INIT_ROOTDIR}/00/${src}
mkdir -p $modifier_rootdir
MODIFIER_FILE=${modifier_rootdir}/modifiers.bash.inc
## sed part re-adds the single quotes auto-stripped-off in bash script
echo $more_opt | sed "s/\([a-z_0-9]*=\)\(.*\)/\1'\2'/" > $MODIFIER_FILE
fi
;;
*)
echo 'ERROR: Unrecognized command.'
usage_syntax
;;
esac