-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdojo-init
executable file
·55 lines (50 loc) · 2.03 KB
/
dojo-init
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
#!/bin/bash
set -Eeuo pipefail
function get_dojo_last_version {
local git_url=${1?git_url not set}
git_tag=$(git ls-remote --tags ${git_url} | sort -t '/' -k 3 -V | awk '{print $2}' | cut -d'/' -f3 | tail -1)
if [[ "${git_tag}" == "" ]];then
echo "fail! getting git tag failed"
return 1
fi
echo "${git_tag}"
}
repo_name=${1?repo_name not set}
dojo_git_url="https://github.com/ai-traders/dojo.git"
if [[ "${repo_name}" != "docker-"*"-dojo" ]]; then
echo "repo_name=${repo_name} does not match pattern docker-*-dojo, continue? (y/n)"
read -n 1 x
if [[ "${x}" != "y" ]]; then
echo -e "\nExiting"
exit 0
fi
fi
if [[ -d "${repo_name}" ]]; then
echo "repo_name=${repo_name} directory already exists, exit 1"
exit 1
fi
set +u
dojo_version=${2}
if [[ ${dojo_version} == "" ]]; then
dojo_version=$(get_dojo_last_version "${dojo_git_url}")
fi
echo "Using dojo version: ${dojo_version}"
set -u
docker_image_name=$(echo ${repo_name} | sed "s/docker-//g")
echo "Creating ${repo_name}..."
cp -r templates ${repo_name}
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
find ${repo_name} -type f -exec sed -i '' "s;\${TODO_REPLACE_dojo_git_url};${dojo_git_url};g" {} \;
find ${repo_name} -type f -exec sed -i '' "s;\${TODO_REPLACE_dojo_version};${dojo_version};g" {} \;
find ${repo_name} -type f -exec sed -i '' "s;\${TODO_REPLACE_dojo_image_name};${docker_image_name};g" {} \;
find ${repo_name} -type f -exec sed -i '' "s;\${TODO_REPLACE_repo_name};${repo_name};g" {} \;
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under GNU/Linux platform
find ${repo_name} -type f -exec sed -i "s;\${TODO_REPLACE_dojo_git_url};${dojo_git_url};g" {} \;
find ${repo_name} -type f -exec sed -i "s;\${TODO_REPLACE_dojo_version};${dojo_version};g" {} \;
find ${repo_name} -type f -exec sed -i "s;\${TODO_REPLACE_dojo_image_name};${docker_image_name};g" {} \;
find ${repo_name} -type f -exec sed -i "s;\${TODO_REPLACE_repo_name};${repo_name};g" {} \;
fi
chmod +x ${repo_name}/tasks
echo "Done"