-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathabaco-init.sh
More file actions
executable file
·123 lines (105 loc) · 2.24 KB
/
abaco-init.sh
File metadata and controls
executable file
·123 lines (105 loc) · 2.24 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
#!/bin/bash
THIS=$(basename $0)
THIS=${THIS%.sh}
THIS=${THIS//[-]/ }
HELP="
Usage: ${THIS} [OPTION]... [IMAGE]
Initializes a new Abaco actor project.
Options:
-h show help message
-n project name (e.g. my_new_actor)
-l language (default: python3)
"
function usage() { echo "$HELP"; exit 0; }
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/abaco-common.sh"
function slugify {
echo "${1}" | tr -c -d [0-9A-Za-z\ _-] | tr ' ' '_' | tr '[:upper:]' '[:lower:]'
}
name=
repo=
lang=
tenant=
while getopts ":hl:n:i:" o; do
case "${o}" in
n) # name
name=${OPTARG}
;;
l) # language
lang=${OPTARG}
;;
h | *) # print help text
usage
;;
esac
done
shift $((OPTIND-1))
repo="$1"
if [ -z "${name}" ]
then
usage
fi
# URL-safen name
safename=`slugify "${name}"`
if [ "$safename" != "$name" ]
then
info "Making project name URL safe: $safename"
name="$safename"
fi
# Ensure directory $name is doens't exist yet
if [ ! -d "$name" ]
then
mkdir -p "$name"
else
die "Project directory $name exists."
fi
# Template language - default Python2
if [ -z "${lang}" ]
then
lang="python3"
info "Defaulting to Python 3.6"
fi
# set repo to name if not passed by user
# else, check user-passed repo is valid (slugify)
if [ -z "${repo}" ]
then
repo=${name}
else
saferepo=$(slugify $repo)
if [ "$saferepo" != "$repo" ]
then
info "Making repo name URL safe: $saferepo"
repo="$saferepo"
fi
fi
# Get tenant ID
if [ -f "$HOME/.agave/current" ]
then
tenant=${TENANTID}
else
die "Can't determine TACC Cloud tenant"
fi
# Copy in template
if [ -d "$DIR/templates/$tenant/$lang" ]
then
if [ ! -f "$DIR/templates/$tenant/$lang/placeholder" ]
then
cp -R ${DIR}/templates/${tenant}/${lang}/ ${name}/
else
die "Template support for $lang is not yet implemented."
fi
else
rm -rf ${name}
die "Error creating project directory $name"
fi
# Template out the reactor.rc file
cat << EOF > "${name}/reactor.rc"
# Reactor mandatory settings
REACTOR_NAME=${name}
# REACTOR_DESCRIPTION=
# REACTOR_ALIAS=reactor-nickname
# Docker settings
DOCKER_HUB_ORG=your_docker_registory_uname
DOCKER_IMAGE_TAG=${repo}
DOCKER_IMAGE_VERSION=0.1
EOF