/
mulle-fetch
executable file
Β·418 lines (323 loc) Β· 10.9 KB
/
mulle-fetch
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#! /usr/bin/env mulle-bash
# shellcheck shell=bash
#
# Copyright (c) 2015-2017 Nat! - Mulle kybernetiK
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of Mulle kybernetiK nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
[ "${TRACE:-}" = 'YES' -o "${MULLE_FETCH_TRACE:-}" = 'YES' ] && set -x && : "$0" "$@"
MULLE_EXECUTABLE_VERSION="4.1.1"
#
# Determine location of own libexec directory. Which is `src` in development
# and ../libexec when deployed. MULLE_EXECUTABLE needs to be defined for this.
#
if ! [ ${MULLE_FETCH_LIBEXEC_DIR+x} ]
then
r_get_libexec_dir "${MULLE_EXECUTABLE}" "mulle-fetch" "mulle-fetch-archive.sh"
MULLE_FETCH_LIBEXEC_DIR="${RVAL}"
fi
set +u
#
# This is the fetch::main user interface to mulle-fetch
# sorta like git
#
fetch::print_commands()
{
local show_all="${1:-NO}"
SHOWN_COMMANDS="\
domain : special commands to query remote tags
cfetch : conveniently fetch and unpack URL by guessing a lot (default)
fetch : explicitly fetch archive or repository into a directory
search-local: search repo in folders given in MULLE_FETCH_SEARCH_PATH
update : update repository (-> git fetch)
upgrade : upgrade repository (-> git pull)"
HIDDEN_COMMANDS="\
allow : allow this directory being symlinked by projects (default)
exists : check if url is accessible (returns 0=YES)
libexec-dir : print path to mulle-fetch libexec
operation : list operations available (for mulle-sourcetree)
list : list plugins available
prevent : prevent this directory from being symlinked by other projects
uname : mulle-fetchs simplified uname(1)
version : print mulle-fetch version"
printf "%s\n" "${SHOWN_COMMANDS}"
if [ "${show_all}" != 'NO' ]
then
printf "%s\n" "${HIDDEN_COMMANDS}"
fi
}
fetch::print_flags()
{
echo " -f : force operation"
echo " --recursive : recursive fetch (git only)"
options_technical_flags_usage " : "
}
fetch::do_usage()
{
local verbose="${1:-NO}"
cat <<EOF
Usage:
${MULLE_USAGE_NAME} [flags] <url> [directory] | <command> ...
Retrieve and unpack zip/tar archive, git repositories, svn repositories.
Usually a zip/tar archive is faster.
Use the explicit "fetch" command for complete control and many more
available options.
For quick and dirty fetches, use mulle-fetch with just an URL. Repositories
that support \`clib\` with a "clib.json" file, mulle-fetch supports this
too.
Examples:
mulle-fetch "github:mulle-core/mulle-core"
mulle-fetch "github:mulle-core/mulle-core@0.1.0" "src/mulle-core"
mulle-fetch "github:mulle-core/mulle-core.tar"
mulle-fetch "clib:mulle-core/mulle-core" "src/""
mulle-fetch "https://github.com/mulle-core/mulle-mmap/archive/0.0.1.zip"
Flags:
EOF
fetch::print_flags | LC_ALL=C sort
cat <<EOF
Commands:
EOF
fetch::print_commands "${verbose}" | LC_ALL=C sort
cat <<EOF
(Options are command specific. Use mulle-fetch <command> -h for help.)
EOF
cat <<EOF
Environment:
MULLE_FETCH_ARCHIVE_DIR : local cache of archives
MULLE_FETCH_MIRROR_DIR : local mirror of git repositories
MULLE_FETCH_SEARCH_PATH : specify local directories to search, : separated
MULLE_FETCH_CLIB_MODE : either hardlink or copy or symlink (symlink)
EOF
if [ "${verbose}" = 'NO' ]
then
cat <<EOF
(use ${MULLE_USAGE_NAME} -v help to show more commands)
EOF
fi
}
fetch::usage()
{
fetch::do_usage "$@" >&2
exit 1
}
fetch::main()
{
local MULLE_FLAG_MAGNUM_FORCE='NO'
# technical flags
local MULLE_TRACE
local MULLE_FLAG_EXEKUTOR_DRY_RUN='NO'
local MULLE_FLAG_LOG_LOCAL='NO'
local MULLE_FLAG_LOG_DEBUG='NO'
local MULLE_FLAG_LOG_EXEKUTOR='NO'
local MULLE_FLAG_LOG_FLUFF='NO'
local MULLE_FLAG_LOG_SCRIPTS='NO'
local MULLE_FLAG_LOG_SETTINGS='NO'
local MULLE_FLAG_LOG_VERBOSE='NO'
local MULLE_FLAG_LOG_MERGE='NO'
local MULLE_TRACE_POSTPONE='NO'
local GIT_FETCH_FLAGS
local cmd
#
# simple option handling
#
while [ $# -ne 0 ]
do
if options_technical_flags "$1"
then
shift
continue
fi
case "$1" in
-f|--force)
MULLE_FLAG_MAGNUM_FORCE='YES'
;;
-h*|--help|help)
fetch::usage "${MULLE_TRACE}"
;;
--github|--github-user)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
OPTION_GITHUB_USER="$1"
;;
--git-terminal-prompt)
[ $# -eq 1 ] && fail "Missing argument to \"$1\""
shift
GIT_TERMINAL_PROMPT="$1"
export GIT_TERMINAL_PROMPT
;;
--recursive)
GIT_FETCH_FLAGS="$1" # for git
;;
--version)
printf "%s\n" "${MULLE_EXECUTABLE_VERSION}"
exit 0
;;
-*)
# forward unknown flags to cfetch command
cmd="cfetch"
break
;;
*)
break
;;
esac
shift
done
options_setup_trace "${MULLE_TRACE}" && set -x
#
#
if [ -z "${cmd}" -a $# -ne 0 ]
then
cmd="$1"
shift
fi
case "${cmd}" in
""|help)
fetch::usage
;;
allow)
if [ -f ".mulle/etc/fetch/no-symlink" -o -f ".mulle/etc/fetch/no-search" ]
then
log_info "${PWD} is local-searchable and can be symlinked again"
remove_file_if_present ".mulle/etc/fetch/no-search"
rmdir_if_empty .mulle/etc/fetch
rmdir_if_empty .mulle/etc
rmdir_if_empty .mulle
else
log_verbose "${PWD} is already local-searchable and symlinkable"
fi
;;
# "hidden" test code
debug-clib-fetch)
. "${MULLE_FETCH_LIBEXEC_DIR}/mulle-fetch-plugin.sh" || fail "failed to load ${MULLE_FETCH_LIBEXEC_DIR}/mulle-fetch-source.sh"
fetch::plugin::load "clib"
fetch::plugin::clib::symlink_or_copy "$@"
;;
checkout)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::checkout_main "$@"
;;
exists)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::exists_main "$@"
;;
cfetch|convenient-fetch)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::convenient_fetch_main "$@"
;;
fetch)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::fetch_main "$@"
;;
"libexec-dir"|"library-path")
printf "%s\n" "${MULLE_FETCH_LIBEXEC_DIR}"
;;
list)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::plugin::main "$@" list
;;
operation)
# shellcheck source=src/mulle-fetch-operation.sh
include "fetch::operation"
fetch::commands::operation_main "$@"
;;
plugin)
# shellcheck source=src/mulle-fetch-commands.sh
. "${MULLE_FETCH_LIBEXEC_DIR}/mulle-fetch-plugin.sh"
fetch::plugin::main "$@"
;;
prevent)
if [ ! -f ".mulle/etc/fetch/no-symlink" -o ! -f ".mulle/etc/fetch/no-search" ]
then
log_info "${PWD} will not be local-searched or symlinked anymore"
mkdir_if_missing .mulle/etc/fetch
redirect_exekutor ".mulle/etc/fetch/no-symlink" echo "# existence of file is enough"
redirect_exekutor ".mulle/etc/fetch/no-search" echo "# existence of file is enough"
else
log_verbose "${PWD} is already not local-searchable and symlinkable"
fi
;;
search-local)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::search_local_main "$@"
;;
set-url)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::set_url_main "$@"
;;
status)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::status_main "$@"
;;
uname)
printf "%s\n" "${MULLE_UNAME}"
;;
update)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::update_main "$@"
;;
upgrade)
# shellcheck source=src/mulle-fetch-commands.sh
include "fetch::commands"
fetch::commands::upgrade_main "$@"
;;
version)
printf "%s\n" "${MULLE_EXECUTABLE_VERSION}"
return 0
;;
# # cheap shortcut to avoid typing fetch
# *:*)
# # shellcheck source=src/mulle-fetch-commands.sh
# . "${MULLE_FETCH_LIBEXEC_DIR}/mulle-fetch-commands.sh"
#
# fetch::commands::convenient_fetch_main "${cmd}" "$@"
# ;;
*)
# shellcheck source=src/mulle-fetch-commands.sh
if [ -e "${cmd}" ]
then
. "${MULLE_FETCH_LIBEXEC_DIR}/mulle-fetch-commands.sh"
fetch::commands::fetch_main --symlink "${cmd}" "$@"
return $?
fi
# shellcheck source=src/mulle-fetch-commands.sh
. "${MULLE_FETCH_LIBEXEC_DIR}/mulle-fetch-commands.sh"
fetch::commands::convenient_fetch_main --no-print "${cmd}" "$@"
;;
esac
}
call_with_flags "fetch::main" "${MULLE_FETCH_FLAGS:-}" "$@"