-
Notifications
You must be signed in to change notification settings - Fork 0
/
.expo_functions
executable file
·168 lines (142 loc) · 2.75 KB
/
.expo_functions
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
#!/bin/bash
# helper script executor, called by expo units after defining unit specific
# helper functions
############################# RH helper functions ##############################
_rh_try_ret_help()
{
if [ ! -z $RH_RUNTIME_REQUEST_HELP ]
then
echo $1
exit 1;
fi
}
############################### default functions ##############################
# defined when unit doesn't define
func_nonex()
{
# if the main expo script called, do not define overwritable unit specific functions
if [ "function" = "$(type -t units_list)" ]
then
return 1
fi
[ "function" != "$(type -t $1)" ]
return $?
}
if func_nonex init
then
init()
{
_rh_try_ret_help 'Prepares compose stack to run'
mkdir -p ./data/
}
fi
if func_nonex start
then
start()
{
_rh_try_ret_help 'Starts expo stack'
docker compose up -d
}
fi
if func_nonex purge
then
purge()
{
_rh_try_ret_help 'Erases all user data'
rm -Rf ./data
}
fi
if func_nonex up
then
up()
{
_rh_try_ret_help 'Initializes and starts expo stack'
init
start
}
fi
if func_nonex down
then
down()
{
_rh_try_ret_help 'Stops services but keep user files'
docker compose down
}
fi
if func_nonex destroy
then
destroy()
{
_rh_try_ret_help 'Stops expo unit and purge user data'
down
purge
}
fi
if func_nonex dc
then
dc()
{
_rh_try_ret_help 'Forwards docker compose calls'
docker compose "$@"
}
fi
if func_nonex readme
then
readme()
{
_rh_try_ret_help 'Prints the content of the readme file is exists'
if [ -f README.md ]
then
cat << EOF
################################################################################
# README of expo unit $(basename $(readlink -f .))
################################################################################
EOF
cat README.md
echo ""
else
echo "There is no README file attached"
fi
}
fi
############################ RH built-in functions #############################
help()
{
_rh_try_ret_help "Returns help with the list of all annotated functions"
echo "It is a wrapper script wherein you can collect tiny commands."
echo "Specify one helper function from the followings:"
RH_RUNTIME_REQUEST_HELP=true
for f in ${RH_FUNCTIONS[@]}
do
# if the command has help
if type $f | grep -qzP '{\s+_rh_try_ret_help '
then
echo -e "\t$f - "$($f)
fi
done
}
############################## Application area ################################
# Collection available commands
RH_FUNCTIONS=()
for func in `typeset -F | grep -Po '(?<=-f).*$' | sort`
do
RH_FUNCTIONS+=($func);
done
# print help if nothing specified
if [ $# '<' '1' ]
then
help
exit 1
fi
# run command
for f in ${RH_FUNCTIONS[@]}
do
if [ "$1" "=" "$f" ]
then
$f "${@:2}"
exit $?
fi
done
echo "Expo helper function $1 not found, so now printing help..."
help
exit 1