-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrdo
executable file
·243 lines (210 loc) · 6.12 KB
/
rdo
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env bash
#
# Docker test environment for rTorrent
#
# https://github.com/rakshasa/rtorrent-docker
set -eu
cd "$(dirname "${BASH_SOURCE[0]}")"
source "./functions/common/init"
include_source=(
common/args
common/utils
common.init
common.container
common.image
common.system
# Preload any headers for commands that are likely to be executed
# multiple times.
build
build.context
docker
docker.clean
init
network
run
stage
torrent
torrent.wait
)
for src in "${include_source[@]}"; do
is_header_included "${src}" || source "./functions/${src}"
done
rdo() {
# eval "$(args::init_subcommand "rdo" "RTorrent docker test environment")"
# args::new_option "debug" empty "d" "Output additional debug information" \
# 'set -x'
# args::new_command "bash" default "Start custom bash session" \
# 'is_header_included machine || source "./functions/machine"; rdo_bash "${@}"'
# args::new_command "batch" default "Run batch file" \
# 'rdo_batch "${@}"'
# args::new_command "build" default "Build projects" \
# 'rdo_build "${@}"'
# args::new_command "docker" default "Manage docker" \
# 'rdo_docker "${@}"'
# args::new_command "env" default "." \
# 'is_header_included env || source "./functions/env"; rdo_env "${@}"'
# args::new_command "git" default "." \
# 'is_header_included git || source "./functions/git"; do_git "${@}"'
# args::new_command "init" default "Initalize the environment" \
# 'rdo_init "${@}"'
# args::new_command "machine" default "Manage docker machines" \
# 'is_header_included machine || source "./functions/machine"; rdo_machine "${@}"'
# args::new_command "network" default "Manage networks" \
# 'rdo_network "${@}"'
# args::new_command "stage" default "Stage environments" \
# 'rdo_stage "${@}"'
# args::new_command "torrent" default "Manage torrents" \
# 'rdo_torrent "${@}"'
# args::new_command "watch" empty "Watch docker images" \
# 'rdo_watch "${@}"'
# eval "$(args::process)"
while true; do
case "${1}" in
--debug|-d)
shift
set -x
;;
--help|-h|'')
echo "Usage: rdo COMMAND"
echo
echo "RTorrent docker test environment"
echo
echo "Options:"
echo " -d, --debug Output additional debug information"
echo
echo "Commands:"
echo " bash Start custom bash session"
echo " batch Run batch file"
echo " build Build projects"
echo " docker Manage docker"
echo " env ."
echo " git ."
echo " init Initalize the environment"
echo " machine Manage docker machines"
echo " network Manage networks"
echo " node Manage nodes"
echo " stage Stage environments"
echo " torrent Manage torrents"
echo " watch Watch docker images"
echo
echo "Run 'rdo COMMAND --help' for more information on a command."
exit 0
;;
*)
if [[ -n "${1}" ]] && [[ -z "${1##-*}" ]]; then
print_error "${args__root}: unknown flag: ${1}"
return 1
fi
break
;;
esac
done
local args__root="rdo"
local args__cmd="${1}"
shift || :
case "${args__cmd}" in
bash)
is_header_included machine || source "./functions/machine"; rdo_bash "${@}"
;;
batch)
rdo_batch "${@}"
;;
build)
rdo_build "${@}"
;;
docker)
rdo_docker "${@}"
;;
env)
is_header_included env || source "./functions/env"; rdo_env "${@}"
;;
git)
is_header_included git || source "./functions/git"; rdo_git "${@}"
;;
init)
rdo_init "${@}"
;;
machine)
is_header_included machine || source "./functions/machine"; rdo_machine "${@}"
;;
network)
rdo_network "${@}"
;;
node)
rdo_node "${@}"
;;
stage)
rdo_stage "${@}"
;;
torrent)
rdo_torrent "${@}"
;;
watch)
args::verify_command_empty "${@}"
rdo_watch "${@}"
;;
*)
print_error "rdo: unknown command: ${args__cmd}"
exit 1
;;
esac
}
rdo_test_begin() {
rdo_test__name="$(basename "${BASH_SOURCE[1]}")"
rdo_test__name="${rdo_test__name//-/ }"
print_progress "staging ${rdo_test__name} tests"
rdo_stage_init
}
rdo_test_end() {
print_progress "completed ${rdo_test__name} tests"
}
rdo_batch() {
# eval "$(args::init_options_string "rdo batch FILENAME" "filename" "Run batch file")"
# eval "$(args::process)"
# start of generated bash args 'rdo batch FILENAME'
while true; do
case "${1}" in
--help|-h)
echo "Usage: rdo batch FILENAME"
echo
echo "Run batch file"
echo
echo "Run 'rdo batch FILENAME COMMAND --help' for more information on a command."
exit 0
;;
*)
if [[ -n "${1}" ]] && [[ -z "${1##-*}" ]]; then
print_error "${args__root}: unknown flag: ${1}"
return 1
fi
break
;;
esac
done
if (( ${#} > 1 )); then
print_error "rdo batch FILENAME: too many arguments"
exit 1
fi
if (( ${#} == 0 )) || [[ -z "${1}" ]]; then
print_error "rdo batch FILENAME: missing or empty argument"
exit 1
fi
local filename="${1}"
shift
# end of generated bash args 'rdo batch FILENAME'
source "${filename}"
}
rdo_watch() {
watch -n5 'docker images --filter "label=ancestor_project_root=rdo" | pr -t -2 -o 4 -w 260'
}
prune_containers() {
docker container prune --force --filter 'ancestor=rtorrent.ancestor'
}
prune_images() {
if [[ -n "$(docker images -q --filter 'ancestor=rtorrent.ancestor' --filter 'dangling=true')" ]]; then
docker rmi --force $(docker images -q --filter 'since=rtorrent.ancestor' --filter 'dangling=true')
else
print_progress "no dangling images"
fi
}
rdo "${@}"