-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_parent.sh
executable file
·200 lines (159 loc) · 6.02 KB
/
setup_parent.sh
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
set -e
base_dir=$(pwd)
#####################################################
#### Parse command-line options
#####################################################
name=""
remote=""
destination=""
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -n, --name <name> Name of the project"
echo " -r, --remote <remote> Remote repository URL"
echo " -d, --destination <destination>"
echo " Destination folder"
echo ""
echo "Example:"
echo ""
echo "$0 --name mycomponent --remote 'https://github.com/myaccount' --destination ~/myproject-parent"
echo ""
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
-n|--name) shift; name="$1" ;;
-r|--remote) shift; remote="$1" ;;
-d|--destination) shift; destination="$1" ;;
*)
echo "Unknown option: $1" >&2
usage
;;
esac
shift
done
# Validate if required options are provided
if [ -z "$name" ] || [ -z "$remote" ] || [ -z "$destination" ]; then
usage=
exit 1
fi
#####################################################
#### Setup GitHub Repositories
#####################################################
echo "Setup parent repository for name with remote $remote in $destination"
remote_parent="$remote/${name}-parent"
remote_app="$remote/${name}-app"
if curl -ILs "$remote_parent" | tac | grep -m1 HTTP | grep 404; then
echo "$remote_parent does not exist, goto GitHub and setup $remote_parent as empty repository!"
exit 0
fi
if curl -ILs "$remote_app" | tac | grep -m1 HTTP | grep 404; then
echo "$remote_app does not exist, goto GitHub and setup $remote_app as empty repository!"
exit 0
fi
#####################################################
#### Setup parent git repository
#####################################################
echo "Setup git repository"
mkdir -p "$destination"
cd "$destination"
git init
git branch -m main
echo "Setup basic files repository"
echo "# Parent repository for $name" > "$destination/README.md"
echo "0.0.1dev" > "$destination/VERSION"
cp "$base_dir/makefile" makefile
cp "$base_dir/.gitignore" .gitignore
git add .
git commit -m "Setup repository"
#####################################################
#### Create cltl-requirements in parent repository
#####################################################
echo "Add requirements"
wget https://github.com/leolani/cltl-requirements/archive/main.zip
unzip main.zip
rm main.zip
mv cltl-requirements-main cltl-requirements
echo "# Requirements for $name" > cltl-requirements/README.md
cp "$base_dir/cltl-requirements/requirements.txt" cltl-requirements/requirements.txt
rm -rf cltl-requirements/util
git add .
git commit -m "Add cltl-requirements"
#####################################################
#### Add components as git submodules
#####################################################
echo "Add submodules"
git submodule add -b main https://github.com/leolani/cltl-build.git cltl-requirements/util
git submodule add -b main --name emissor https://github.com/leolani/emissor.git emissor
git submodule add -b main --name util https://github.com/leolani/cltl-build.git util
git submodule add -b main --name cltl-combot https://github.com/leolani/cltl-combot.git cltl-combot
git submodule add -b main --name cltl-backend https://github.com/leolani/cltl-backend.git cltl-backend
git submodule add -b main --name cltl-emissor-data https://github.com/leolani/cltl-emissor-data.git cltl-emissor-data
git submodule add -b main --name cltl-vad https://github.com/leolani/cltl-vad.git cltl-vad
git submodule add -b main --name cltl-asr https://github.com/leolani/cltl-asr.git cltl-asr
git submodule add -b main --name cltl-chat-ui https://github.com/leolani/cltl-chat-ui.git cltl-chat-ui
git submodule add -b main --name cltl-eliza https://github.com/leolani/cltl-eliza.git cltl-eliza
git submodule add -b main --name cltl-leolani https://github.com/leolani/cltl-leolani.git cltl-leolani
git submodule add -b main --name cltl-object-recognition https://github.com/leolani/cltl-object-recognition.git cltl-object-recognition
git submodule update --init --recursive
git add .
git commit -m "Add submodules"
#####################################################
#### Create application repository from template
#####################################################
echo "Add ${name}-app"
git submodule add -b main --name "${name}-app" "https://github.com/leolani/cltl-template.git" "${name}-app"
cd "${name}-app"
./init_component.sh -n "${name}-app" --remote "$remote_app" --namespace "${name}"
git add .
git commit -m "Setup application for ${name}"
git push --set-upstream origin main
cd ..
git submodule set-url "${name}-app" "$remote_app"
git add .
git commit -m "Add ${name}-app"
git remote add origin $remote_parent
git push --set-upstream origin main
git submodule update --init --recursive
#####################################################
#### Copy Python application
#####################################################
echo "Setup application in $destination/${name}-app/py-app"
cd "${name}-app"
rm -rf py-app src
cp -r "$base_dir/workshop-app/py-app" py-app
cp -r "$base_dir/workshop-app/src" src
cp "$base_dir/workshop-app/makefile" makefile
cp "$base_dir/workshop-app/setup.py" setup.py
cp "$base_dir/workshop-app/requirements.txt" requirements.txt
mkdir -p py-app/storage
mkdir -p py-app/storage/audio
mkdir -p py-app/storage/image
git add .
git commit -m "Add application"
git push
cd ..
git add .
git commit -m "Add application"
git push
#####################################################
#### Change component names in makefiles and setup.py
#####################################################
echo "RENAME workshop-app in makefile and ${name}"-app/makefile"
echo "RENAME package name in ${name}"-app/setup.py"
exit 0
cd ${name}-app"
sed -i '.bak' 's/workshop-app/"${name}"-app/g' makefile
rm makefile.bak
sed -i '.bak' 's/workshop-app/"${name}"-app/g' setup.py
rm setup.py.bak
git add .
git commit -m "Adjust names"
git push
cd ..
sed -i '.bak' 's/workshop-app/"${name}"-app/g' makefile
rm makefile.bak
git add .
git commit -m "Adjust names"l
git push