Browse code

New feature. mulle-bootstrap can now download archives from github instead of needing to clone it. This is probably in many cases preferable, because it is much faster.

Nat! authored on 23-02-2017 21:59:21
Showing 13 changed files
... ...
@@ -98,6 +98,7 @@ Setting Name                      |  Description
98 98
 Setting Name                      |  Description                                  | Default
99 99
 ----------------------------------|-----------------------------------------------|--------------
100 100
 `absolute_symlinks`               | Use absolute symlinks instead of relatives    | NO
101
+`caches_path`                     | PATH to search for repositories, before cloning |
101 102
 `embedded_symlinks`               | mulle-bootstrap will attempt to symlink regular repositories       | NO (ignored on MINGW)
102 103
 `symlinks`                        | mulle-bootstrap will attempt to symlink embedded repositories       | NO (ignored on MINGW)
103 104
 `update_gitignore`                | add cleanable directories to .gitignore       | YES
... ...
@@ -543,7 +543,7 @@ bootstrap_main()
543 543
    local ps4string
544 544
 
545 545
    local MULLE_FLAG_ANSWER="ASK"
546
-   local MULLE_FLAG_DIRTY_HARRY="YES"
546
+   local MULLE_FLAG_MAGNUM_FORCE="NO"
547 547
    local MULLE_FLAG_IGNORE_GRAVEYARD="NO"
548 548
    local MULLE_FLAG_VERBOSE_BUILD="NO"
549 549
 
... ...
@@ -589,7 +589,7 @@ bootstrap_main()
589 589
          ;;
590 590
 
591 591
          -f|--force-fetch)
592
-            MULLE_FLAG_DIRTY_HARRY="NO"
592
+            MULLE_FLAG_MAGNUM_FORCE="YES"
593 593
          ;;
594 594
 
595 595
          -ig|--ignore-graveyard)
... ...
@@ -633,7 +633,7 @@ bootstrap_main()
633 633
    #
634 634
    command="${1:-bootstrap}"
635 635
 
636
-   if [ "${MULLE_FLAG_DIRTY_HARRY}" = "NO" ]
636
+   if [ "${MULLE_FLAG_MAGNUM_FORCE}" = "YES" ]
637 637
    then
638 638
       set_fetch_needed
639 639
       set_build_needed
... ...
@@ -648,7 +648,7 @@ bootstrap_main()
648 648
          *)
649 649
             case "${command}" in
650 650
                bootstrap|nomagic|build|dist|clean|dist-clean|fetch|install|syteminstall|upgrade|update|setup-xcode|show|status|xcode|tag)
651
-                  fail "There is no ${BOOTSTRAP_DIR} or ${BOOTSTRAP_DIR}.local folder here, can't continue"
651
+                  fail "There is no ${BOOTSTRAP_DIR} or ${BOOTSTRAP_DIR}.local folder here ($PWD), can't continue"
652 652
                ;;
653 653
             esac
654 654
          ;;
... ...
@@ -659,7 +659,7 @@ bootstrap_main()
659 659
          return 1
660 660
       fi
661 661
 
662
-      if [ "${MULLE_FLAG_DIRTY_HARRY}" = "YES" ]
662
+      if [ "${MULLE_FLAG_MAGNUM_FORCE}" = "NO" ]
663 663
       then
664 664
          case "${command}" in
665 665
             clean|dist-clean|init|status|show|config|setting)
... ...
@@ -900,7 +900,7 @@ brew_main()
900 900
          *)
901 901
             case "${command}" in
902 902
                dist|clean|dist-clean|install|upgrade|update|setup-xcode|xcode)
903
-                  fail "There is no ${BOOTSTRAP_DIR} or ${BOOTSTRAP_DIR}.local folder here, can't continue"
903
+                  fail "There is no ${BOOTSTRAP_DIR} or ${BOOTSTRAP_DIR}.local folder here ($PWD), can't continue"
904 904
                ;;
905 905
             esac
906 906
          ;;
... ...
@@ -60,8 +60,6 @@ EOF
60 60
 
61 61
 defer_main()
62 62
 {
63
-   local OPTION_FORCE="NO"
64
-
65 63
    log_debug ":defer_main:"
66 64
 
67 65
    while [ $# -ne 0 ]
... ...
@@ -71,10 +69,6 @@ defer_main()
71 69
             defer_usage
72 70
          ;;
73 71
 
74
-         --force)
75
-            OPTION_FORCE=YES
76
-         ;;
77
-
78 72
          -*)
79 73
             log_error "${MULLE_EXECUTABLE_FAIL_PREFIX}: Unknown option $1"
80 74
             defer_usage
... ...
@@ -106,7 +100,7 @@ defer_main()
106 100
       [ ! -z "${masterpath}" ]  || internal_fail "is_minion file empty"
107 101
       log_warning "Master \"${masterpath}\" already owns \"${minionpath}\""
108 102
 
109
-      if [ "${OPTION_FORCE}" = "NO" ]
103
+      if [ "${MULLE_FLAG_MAGNUM_FORCE}" = "NO" ]
110 104
       then
111 105
          return
112 106
       fi
... ...
@@ -137,11 +131,12 @@ defer_main()
137 131
 
138 132
    if master_owns_minion_bootstrap_project "${masterpath}" "${minionpath}"
139 133
    then
140
-      if [ "${OPTION_FORCE}" = "NO" ]
134
+      log_warning "Master \"${masterpath}\" already owns \"${minionpath}\", but it was not detected before"
135
+
136
+      if [ "${MULLE_FLAG_MAGNUM_FORCE}" = "NO" ]
141 137
       then
142
-         internal_fail "Master \"${masterpath}\" already owns \"${minionpath}\", but it was not detected before"
138
+         return
143 139
       fi
144
-      log_warning "Master \"${masterpath}\" already owns \"${minionpath}\", but it was not detected before"
145 140
    fi
146 141
 
147 142
    #
... ...
@@ -170,8 +165,6 @@ emancipate_main()
170 165
 {
171 166
    log_debug ":emancipate_main:"
172 167
 
173
-   local OPTION_FORCE="NO"
174
-
175 168
    while [ $# -ne 0 ]
176 169
    do
177 170
       case "$1" in
... ...
@@ -179,10 +172,6 @@ emancipate_main()
179 172
             defer_usage
180 173
          ;;
181 174
 
182
-         --force)
183
-            OPTION_FORCE=YES
184
-         ;;
185
-
186 175
          -*)
187 176
             log_error "${MULLE_EXECUTABLE_FAIL_PREFIX}: Unknown option $1"
188 177
             defer_usage
... ...
@@ -213,7 +202,7 @@ emancipate_main()
213 202
    then
214 203
       log_warning "Project \"${minionpath}\" does not defer to a master and is already emancipated"
215 204
 
216
-      if [ "${OPTION_FORCE}" = "NO" ]
205
+      if [ "${MULLE_FLAG_MAGNUM_FORCE}" = "NO" ]
217 206
       then
218 207
          return
219 208
       fi
... ...
@@ -232,13 +221,18 @@ emancipate_main()
232 221
 
233 222
    if ! is_master_bootstrap_project "${masterpath}"
234 223
    then
235
-      fail "\"${masterpath}\" is not a master project"
224
+      log_warning "\"${masterpath}\" is not a master project"
225
+      if [ "${MULLE_FLAG_MAGNUM_FORCE}" = "NO" ]
226
+      then
227
+         return
228
+      fi
229
+   else
230
+      log_info "Cleaning master before emancipation"
231
+      ( clean_execute "output" )  # not really critical if fails
236 232
    fi
237 233
 
238
-   log_info "Cleaning master before emancipation"
239
-   ( clean_execute "output" )  # not really critical if fails
240
-
241 234
    log_info "Emancipating \"${minionpath}\" from \"${masterpath}\""
235
+
242 236
    master_remove_minion_bootstrap_project "${masterpath}" "${minionpath}"
243 237
 
244 238
    emancipate_minion_bootstrap_project "${minionpath}"
... ...
@@ -266,7 +266,7 @@ NO is safe, but you often say YES here."
266 266
 }
267 267
 
268 268
 
269
-_search_for_repository_in_cache()
269
+_search_for_git_repository_in_cache()
270 270
 {
271 271
    local directory
272 272
    local name
... ...
@@ -294,6 +294,16 @@ _search_for_repository_in_cache()
294 294
       fi
295 295
    fi
296 296
 
297
+   found="${directory}/${name}.git"
298
+   log_fluff "Looking for \"${found}\""
299
+   if [ -d "${found}" ]
300
+   then
301
+      log_fluff "Found \"${name}.git\" in \"${directory}\""
302
+
303
+      echo "${found}"
304
+      return
305
+   fi
306
+
297 307
    found="${directory}/${name}"
298 308
    log_fluff "Looking for \"${found}\""
299 309
    if [ -d "${found}" ]
... ...
@@ -303,12 +313,57 @@ _search_for_repository_in_cache()
303 313
       echo "${found}"
304 314
       return
305 315
    fi
316
+}
306 317
 
307
-   found="${directory}/${name}.git"
318
+
319
+search_for_git_repository_in_caches()
320
+{
321
+   local found
322
+   local directory
323
+
324
+   IFS=":"
325
+   for directory in ${CACHES_PATH}
326
+   do
327
+      IFS="${DEFAULT_IFS}"
328
+
329
+      found="`_search_for_git_repository_in_cache "${directory}" "$@"`" || exit 1
330
+      if [ ! -z "${found}" ]
331
+      then
332
+         symlink_relpath "${found}" "${ROOT_DIR}"
333
+         return
334
+      fi
335
+   done
336
+
337
+   IFS="${DEFAULT_IFS}"
338
+   return 1
339
+}
340
+
341
+
342
+_search_for_archive_in_caches()
343
+{
344
+   local directory="$1"
345
+   local name="$2"
346
+   local filename="$3"
347
+
348
+   [ $# -ne 3 ] && internal_fail "fail"
349
+
350
+   local found
351
+
352
+   found="${directory}/${name}-${filename}"
308 353
    log_fluff "Looking for \"${found}\""
309 354
    if [ -d "${found}" ]
310 355
    then
311
-      log_fluff "Found \"${name}.git\" in \"${directory}\""
356
+      log_fluff "Found \"${name}\" in \"${directory}\" as \"${found}\""
357
+
358
+      echo "${found}"
359
+      return
360
+   fi
361
+
362
+   found="${directory}/${filename}"
363
+   log_fluff "Looking for \"${found}\""
364
+   if [ -d "${found}" ]
365
+   then
366
+      log_fluff "Found \"${name}\" in \"${directory}\" as \"${found}\""
312 367
 
313 368
       echo "${found}"
314 369
       return
... ...
@@ -316,8 +371,11 @@ _search_for_repository_in_cache()
316 371
 }
317 372
 
318 373
 
319
-search_for_repository_in_caches()
374
+search_for_archive_in_caches()
320 375
 {
376
+   local name="$1"
377
+   local filename="$2"
378
+
321 379
    local found
322 380
    local directory
323 381
 
... ...
@@ -326,15 +384,17 @@ search_for_repository_in_caches()
326 384
    do
327 385
       IFS="${DEFAULT_IFS}"
328 386
 
329
-      found="`_search_for_repository_in_cache "${directory}" "$@"`" || exit 1
387
+      found="`_search_for_archive_in_caches "${directory}" "${name}" "${filename}"`" || exit 1
330 388
       if [ ! -z "${found}" ]
331 389
       then
332
-         symlink_relpath "${found}" "${ROOT_DIR}"
390
+         found="`absolutepath "${found}"`"
391
+         echo "file:///${found}"
333 392
          return
334 393
       fi
335 394
    done
336 395
 
337 396
    IFS="${DEFAULT_IFS}"
397
+   return 1
338 398
 }
339 399
 
340 400
 
... ...
@@ -357,6 +417,33 @@ mkdir_stashparent_if_missing()
357 417
 }
358 418
 
359 419
 
420
+get_cache_item()
421
+{
422
+   local reposdir="$1"  # ususally .bootstrap.repos
423
+   local name="$2"      # name of the clone, extensionless
424
+   local url="$3"       # URL of the clone
425
+   local branch="$4"    # branch of the clone
426
+   local scm="$5"       # scm to use for this clone
427
+   local tag="$6"       # tag to checkout of the clone
428
+   local stashdir="$7"  # stashdir of this clone (absolute or relative to $PWD)
429
+
430
+   if [ "${OPTION_ALLOW_SEARCH_CACHES}" = "NO" ]
431
+   then
432
+      return
433
+   fi
434
+
435
+   case "${scm}" in
436
+      git*)
437
+         search_for_git_repository_in_caches "${name}" "${branch}"
438
+      ;;
439
+
440
+      tar*|zip*)
441
+         search_for_archive_in_caches "${name}" "`basename -- "${url}"`"
442
+      ;;
443
+   esac
444
+}
445
+
446
+
360 447
 clone_or_symlink()
361 448
 {
362 449
    local reposdir="$1"  # ususally .bootstrap.repos
... ...
@@ -375,12 +462,19 @@ clone_or_symlink()
375 462
    local scmflagsdefault
376 463
 
377 464
    case "${scm}" in
378
-      git)
465
+      git*)
379 466
          operation="git_clone"
380
-         scmflagsdefault="--recursive"
381 467
       ;;
382 468
 
383
-      svn)
469
+      zip*)
470
+         operation="zip_unpack"
471
+      ;;
472
+
473
+      tar*)
474
+         operation="tar_unpack"
475
+      ;;
476
+
477
+      svn*)
384 478
          operation="svn_checkout"
385 479
       ;;
386 480
 
... ...
@@ -389,6 +483,19 @@ clone_or_symlink()
389 483
       ;;
390 484
    esac
391 485
 
486
+   local SCM_OPTIONS
487
+
488
+   #
489
+   # later: make it so tar?shasum256=djhdjhdfdh
490
+   # and check that the archive is correct
491
+   #
492
+   extra="`echo "${scm}" | sed -n 's/^[^?]*\?\(.*\)/\1/p'`"
493
+   if [ ! -z "{extra}" ]
494
+   then
495
+      log_fluff "Parsed SCM_OPTIONS as \"${extra}\""
496
+      SCM_OPTIONS="${extra}"
497
+   fi
498
+
392 499
    local stashparent
393 500
 
394 501
    stashparent="`mkdir_stashparent_if_missing "${stashdir}"`"
... ...
@@ -420,28 +527,31 @@ clone_or_symlink()
420 527
       ;;
421 528
 
422 529
       *)
423
-         if [ "${OPTION_ALLOW_SEARCH_CACHES}" = "YES" ]
424
-         then
425
-            found="`search_for_repository_in_caches "${name}" "${branch}"`"
426
-            if [ -z "${found}" ]
427
-            then
428
-               found="`search_for_repository_in_caches "${name}.git" "${branch}"`"
429
-            fi
530
+         found="`get_cache_item "${reposdir}" \
531
+                                "${name}" \
532
+                                "${url}" \
533
+                                "${branch}" \
534
+                                "${scm}" \
535
+                                "${tag}" \
536
+                                "${stashdir}"`"
430 537
 
431
-            if [ ! -z "${found}" ]
432
-            then
433
-               user_say_yes "There is a \"${found}\" folder in the repository cache.
538
+         if [ ! -z "${found}" ]
539
+         then
540
+            user_say_yes "There is \"${found}\" in the cache.
434 541
 (\"${PWD}\"). Use it ?"
435
-               if [ $? -eq 0 ]
436
-               then
437
-                  url="${found}"
438
-
439
-                  ask_symlink_it "${url}"
440
-                  if [ $? -eq 0 ]
441
-                  then
442
-                     operation=link_command
443
-                  fi
444
-               fi
542
+            if [ $? -eq 0 ]
543
+            then
544
+               url="${found}"
545
+
546
+               case "${scm}" in
547
+                  git)
548
+                     ask_symlink_it "${url}"
549
+                     if [ $? -eq 0 ]
550
+                     then
551
+                        operation=link_command
552
+                     fi
553
+                  ;;
554
+               esac
445 555
             fi
446 556
          fi
447 557
       ;;
... ...
@@ -453,7 +563,7 @@ clone_or_symlink()
453 563
                   "${branch}" \
454 564
                   "${scm}" \
455 565
                   "${tag}" \
456
-                  "${stashdir}"
566
+                  "${stashdir}" || exit 1
457 567
 
458 568
    if [ "${DONT_WARN_SCRIPTS}" != "YES" ]
459 569
    then
... ...
@@ -1363,7 +1473,7 @@ _common_main()
1363 1473
    #
1364 1474
    # "repository" caches can and usually are outside the project folder
1365 1475
    # this can be multiple paths!
1366
-   CACHES_PATH="`read_config_setting "cashes_path" "${CACHES_PATH}"`"
1476
+   CACHES_PATH="`read_config_setting "caches_path" "${CACHES_PATH}"`"
1367 1477
 
1368 1478
    OPTION_CHECK_USR_LOCAL_INCLUDE="`read_config_setting "check_usr_local_include" "NO"`"
1369 1479
    OVERRIDE_BRANCH="`read_config_setting "override_branch"`"
... ...
@@ -334,6 +334,9 @@ path_depth()
334 334
 }
335 335
 
336 336
 
337
+#
338
+# cuts off last extension only
339
+#
337 340
 extension_less_basename()
338 341
 {
339 342
    local  file
... ...
@@ -75,7 +75,7 @@ mingw_mangle_compiler()
75 75
 
76 76
    compiler="$1"
77 77
    case "${compiler}" in
78
-      mulle-clang|clang)
78
+      *clang) # mulle-clang|clang
79 79
          compiler="${compiler}-cl"
80 80
       ;;
81 81
 
... ...
@@ -192,35 +192,6 @@ all_embedded_repository_stashes()
192 192
 }
193 193
 
194 194
 
195
-# all_minion_stashdirs()
196
-# {
197
-#    local reposdir="$1"
198
-
199
-#    [ -z "${reposdir}" ] && internal_fail "repos is empty"
200
-
201
-#    local name
202
-#    local stash
203
-
204
-#    IFS="
205
-# "
206
-#    for name in `ls -1 "${reposdir}/" 2> /dev/null`
207
-#    do
208
-#       IFS="${DEFAULT_IFS}"
209
-
210
-#       stash="`stash_of_repository "${reposdir}" "${name}"`"
211
-#       if [ ! -z "${stash}" ]
212
-#       then
213
-#          if is_minion_bootstrap_project "${stash}"
214
-#          then
215
-#             echo "${stash}"
216
-#          fi
217
-#       fi
218
-#    done
219
-
220
-#    IFS="${DEFAULT_IFS}"
221
-# }
222
-
223
-
224 195
 #
225 196
 # Walkers
226 197
 #
... ...
@@ -526,7 +497,7 @@ walk_raw_clones()
526 497
 #
527 498
 _canonical_clone_name()
528 499
 {
529
-   local  url
500
+   local url
530 501
    local name
531 502
 
532 503
    url="$1"
... ...
@@ -537,10 +508,20 @@ _canonical_clone_name()
537 508
       ;;
538 509
    esac
539 510
 
540
-   name="`extension_less_basename "$url"`"
511
+   # github/gitlist urls (hacquish)
512
+   # cut off last two path components
513
+   case "$url" in
514
+      */archive/*.gz|*/archive/*.zip|*/tarball/*|*/zipball/*)
515
+         url="`dirname -- "${url}"`"
516
+         url="`dirname -- "${url}"`"
517
+      ;;
518
+   esac
519
+
520
+   name="`basename -- "${url}"`"
521
+   name="`echo "${name%%.*}"`"
541 522
 
542 523
    case "${name}" in
543
-      .*)
524
+      .*|"")
544 525
          fail "clone name can't start with a '.'"
545 526
       ;;
546 527
    esac
... ...
@@ -1037,6 +1018,7 @@ mulle_repositories_initialize()
1037 1018
 
1038 1019
    log_debug ":mulle_repositories_initialize:"
1039 1020
 
1021
+   [ -z "${MULLE_BOOTSTRAP_ARRAY_SH}" ]           && . mulle-bootstrap-array.sh
1040 1022
    [ -z "${MULLE_BOOTSTRAP_SETTINGS_SH}" ]        && . mulle-bootstrap-settings.sh
1041 1023
    [ -z "${MULLE_BOOTSTRAP_FUNCTIONS_SH}" ]       && . mulle-bootstrap-functions.sh
1042 1024
    [ -z "${MULLE_BOOTSTRAP_COMMON_SETTINGS_SH}" ] && . mulle-bootstrap-common-settings.sh
... ...
@@ -135,7 +135,7 @@ git_get_branch()
135 135
 
136 136
 git_checkout()
137 137
 {
138
-   [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
138
+   [ $# -ge 7 ] || internal_fail "git_checkout: parameters missing"
139 139
 
140 140
    local reposdir="$1" ; shift
141 141
    local name="$1"; shift
... ...
@@ -186,7 +186,7 @@ git_checkout()
186 186
 
187 187
 git_clone()
188 188
 {
189
-   [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
189
+   [ $# -ge 7 ] || internal_fail "git_clone: parameters missing"
190 190
 
191 191
    local reposdir="$1" ; shift
192 192
    local name="$1"; shift
... ...
@@ -244,14 +244,14 @@ git_fetch()
244 244
 
245 245
    (
246 246
       exekutor cd "${stashdir}" &&
247
-      exekutor git ${GITFLAGS} fetch $* ${GITOPTIONS}  >&2
247
+      exekutor git ${GITFLAGS} fetch "$@" ${GITOPTIONS}  >&2
248 248
    ) || fail "git fetch of \"${stashdir}\" failed"
249 249
 }
250 250
 
251 251
 
252 252
 git_pull()
253 253
 {
254
-   [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
254
+   [ $# -ge 7 ] || internal_fail "git_pull: parameters missing"
255 255
 
256 256
    local reposdir="$1" ; shift
257 257
    local name="$1"; shift
... ...
@@ -298,7 +298,7 @@ git_status()
298 298
 
299 299
 svn_checkout()
300 300
 {
301
-   [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
301
+   [ $# -ge 7 ] || internal_fail "svn_checkout: parameters missing"
302 302
 
303 303
    local reposdir="$1" ; shift
304 304
    local name="$1"; shift
... ...
@@ -332,7 +332,7 @@ svn_checkout()
332 332
 
333 333
 svn_update()
334 334
 {
335
-   [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
335
+   [ $# -ge 7 ] || internal_fail "svn_update: parameters missing"
336 336
 
337 337
    local reposdir="$1" ; shift
338 338
    local name="$1"; shift
... ...
@@ -369,7 +369,7 @@ svn_update()
369 369
 
370 370
 svn_status()
371 371
 {
372
-   [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
372
+   [ $# -ge 7 ] || internal_fail "svn_status: parameters missing"
373 373
 
374 374
    local reposdir="$1" ; shift
375 375
    local name="$1"; shift
... ...
@@ -392,8 +392,6 @@ svn_status()
392 392
 }
393 393
 
394 394
 
395
-
396
-
397 395
 append_dir_to_gitignore_if_needed()
398 396
 {
399 397
    local directory=$1
... ...
@@ -469,7 +467,6 @@ append_dir_to_gitignore_if_needed()
469 467
 }
470 468
 
471 469
 
472
-
473 470
 git_main()
474 471
 {
475 472
    log_debug "::: git :::"
... ...
@@ -525,6 +522,212 @@ run_git()
525 522
 }
526 523
 
527 524
 
525
+_validate_download()
526
+{
527
+   local filename="$1"
528
+   local options="$2"
529
+
530
+   local checksum
531
+   local expected
532
+
533
+   case "${options}" in
534
+      *shasum256*)
535
+         case "${UNAME}" in
536
+            mingw)
537
+               log_fluff "mingw does not support shasum" # or does it ?
538
+            ;;
539
+
540
+            *)
541
+               log_verbose "Validating ${C_MAGENTA}${C_BOLD}${filename}${C_INFO} ..."
542
+
543
+
544
+               expected="`echo "${options}" | sed -n 's/shasum256=\([a-f0-9]*\).*/\1/p'`"
545
+               checksum="`shasum -a 256 -p "${filename}" | awk '{ print $1 }'`"
546
+               if [ "${expected}" != "${checksum}" ]
547
+               then
548
+                  fail "${filename} sha256 is ${checksum}, not ${expected} as expected"
549
+               fi
550
+            ;;
551
+         esac
552
+      ;;
553
+   esac
554
+}
555
+
556
+
557
+_single_directory_in_directory()
558
+{
559
+   local count
560
+   local filename
561
+
562
+   filename="`ls -1 "${tmpdir}"`"
563
+
564
+   count="`echo "$filename}" | wc -l`"
565
+   if [ $count -ne 1 ]
566
+   then
567
+      return
568
+   fi
569
+
570
+   echo "${tmpdir}/${filename}"
571
+}
572
+
573
+
574
+_move_stuff()
575
+{
576
+   local tmpdir="$1"
577
+   local stashdir="$2"
578
+   local archivename="$3"
579
+   local name="$4"
580
+
581
+   local src
582
+   local toremove
583
+
584
+   toremove="${tmpdir}"
585
+   src="${tmpdir}/${archivename}"
586
+   if [ ! -d "${src}" ]
587
+   then
588
+      src="${tmpdir}/${name}"
589
+      if [ ! -d "${src}" ]
590
+      then
591
+         src="`_single_directory_in_directory "${tmpdir}"`"
592
+         if [ -z "${src}" ]
593
+         then
594
+            src="${tmpdir}"
595
+            toremove=""
596
+         fi
597
+      fi
598
+   fi
599
+
600
+   exekutor mv "${src}" "${stashdir}"
601
+
602
+   if [ ! -z "${toremove}" ]
603
+   then
604
+      rmdir_safer "${toremove}"
605
+   fi
606
+}
607
+
608
+#
609
+# What we do is
610
+# a) download the package using curl
611
+# b) create a temporary directory, extract into it
612
+# c) move it into place
613
+#
614
+
615
+tar_unpack()
616
+{
617
+   [ $# -ge 7 ] || internal_fail "tar_unpack: parameters missing"
618
+
619
+#   local reposdir="$1"
620
+   local name="$2"
621
+   local url="$3"
622
+#   local branch="$4"
623
+#   local scm="$5"
624
+#   local tag="$6"
625
+   local stashdir="$7"
626
+
627
+   local tmpdir
628
+   local archive
629
+   local download
630
+   local options
631
+   local archivename
632
+
633
+   download="`basename "${url}"`"
634
+   archive="${download}"
635
+
636
+   # remove .tar (or .zip et friends)
637
+   archivename="`extension_less_basename "${download}"`"
638
+   case "${archivename}" in
639
+      *.tar)
640
+         archivename="`extension_less_basename "${archivename}"`"
641
+      ;;
642
+   esac
643
+
644
+   tmpdir="`mktemp -d "${name}.tmp"`"
645
+   (
646
+      cd "${tmpdir}" || exit 1
647
+
648
+      log_info "Downloading ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
649
+
650
+      exekutor curl -O -L ${CURLOPTIONS} "${url}" || exit 1
651
+      _validate_download "${download}" "${SCM_OPTIONS}" || exit 1
652
+
653
+      case "${url}" in
654
+         *.zip)
655
+            exekutor unzip "${download}" || exit 1
656
+            archive="`basename "${download}" .zip`"
657
+            exekutor rm "${download}" || exit 1
658
+         ;;
659
+      esac
660
+
661
+      case "${UNAME}" in
662
+         darwin)
663
+         ;;
664
+
665
+         *)
666
+            case "${url}" in
667
+               *.gz)
668
+                  options="-z"
669
+               ;;
670
+
671
+               *.bz2)
672
+                  options="-j"
673
+               ;;
674
+
675
+               *.x)
676
+                  options="-J"
677
+               ;;
678
+            esac
679
+         ;;
680
+      esac
681
+
682
+      log_verbose "Extracting ${C_MAGENTA}${C_BOLD}${archive}${C_INFO} ..."
683
+
684
+      exekutor tar xf ${TAROPTIONS} ${options} "${archive}" || exit 1
685
+      exekutor rm "${archive}" || exit 1
686
+   ) || exit 1
687
+
688
+   _move_stuff "${tmpdir}" "${stashdir}" "${archivename}" "${name}"
689
+}
690
+
691
+
692
+zip_unpack()
693
+{
694
+   [ $# -ge 7 ] || internal_fail "zip_unpack: parameters missing"
695
+
696
+#   local reposdir="$1"
697
+   local name="$2"
698
+   local url="$3"
699
+#   local branch="$4"
700
+#   local scm="$5"
701
+#   local tag="$6"
702
+   local stashdir="$7"
703
+
704
+   local tmpdir
705
+   local download
706
+   local archivename
707
+
708
+   download="`basename --  "${url}"`"
709
+   archivename="`extension_less_basename "${download}"`"
710
+
711
+   tmpdir="`mktemp -d "${name}.tmp"`"
712
+   (
713
+      cd "${tmpdir}" || exit 1
714
+
715
+      log_info "Downloading ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
716
+
717
+      exekutor curl -O -L ${CURLOPTIONS} "${url}" || exit 1
718
+      _validate_download "${download}" "${SCM_OPTIONS}" || exit 1
719
+
720
+      log_verbose "Extracting ${C_MAGENTA}${C_BOLD}${download}${C_INFO} ..."
721
+
722
+      exekutor unzip "${download}" || exit 1
723
+      exekutor rm "${download}" || exit 1
724
+   ) || exit 1
725
+
726
+   _move_stuff "${tmpdir}" "${stashdir}" "${archivename}" "${name}"
727
+}
728
+
729
+
730
+
528 731
 scm_initialize()
529 732
 {
530 733
    log_debug ":scm_initialize:"
... ...
@@ -35,7 +35,15 @@ config_usage()
35 35
 {
36 36
     cat <<EOF >&2
37 37
 usage:
38
-   mulle-bootstrap config <name> [value]
38
+   mulle-bootstrap config [options] [name] [value]
39
+
40
+   Options:
41
+      -l   : list config values
42
+      -d   : delete config setting
43
+
44
+   Use:
45
+      mulle-bootstrap config <name> to read
46
+      mulle-bootstrap config <name> <value> to write
39 47
 EOF
40 48
   exit 1
41 49
 }
... ...
@@ -49,6 +57,7 @@ EOF
49 57
   exit 1
50 58
 }
51 59
 
60
+
52 61
 setting_usage()
53 62
 {
54 63
     cat <<EOF >&2
... ...
@@ -326,20 +335,11 @@ _read_home_setting()
326 335
 
327 336
    [ -z "$name" ] && internal_fail "empty name in _read_home_setting"
328 337
 
329
-   if [ "${MULLE_FLAG_LOG_SETTINGS}" = "YES" ]
330
-   then
331
-      log_trace2 "Looking for setting \"${name}\" in \"~/.mulle-bootstrap/${name}\""
332
-   fi
333
-
334 338
    if ! value="`_read_setting "${HOME}/.mulle-bootstrap/${name}"`"
335 339
    then
336 340
       return 2
337 341
    fi
338 342
 
339
-   if [ "${MULLE_FLAG_LOG_SETTINGS}" = "YES" ]
340
-   then
341
-      log_trace "Setting ${C_MAGENTA}${C_BOLD}${name}${C_TRACE} found in \"~/.mulle-bootstrap/${name}\" as ${C_MAGENTA}${C_BOLD}${value}${C_TRACE}"
342
-   fi
343 343
    warn_user_setting "${HOME}/.mulle-bootstrap/${name}"
344 344
 
345 345
    echo "$value"
... ...
@@ -126,16 +126,7 @@ show_repository()
126 126
 
127 127
    if [ "${SHOW_SCM}" = "YES" ]
128 128
    then
129
-      printf "  ["
130
-
131
-      case "${scm}" in
132
-         ""|"git")
133
-            printf "git"
134
-         ;;
135
-         *)
136
-            printf "${scm}"
137
-         ;;
138
-      esac
129
+      printf "  [${scm}"
139 130
 
140 131
       if [ ! -z "${tag}" -o ! -z "${branch}" ]
141 132
       then
... ...
@@ -153,6 +153,8 @@ _bury_zombie()
153 153
 
154 154
    if [ -d "${stashdir}" ]
155 155
    then
156
+      is_minion_bootstrap_project "${stashdir}" && internal_fail "Would bury minion \"${stashdir}\" which is wrong"
157
+
156 158
       _bury_stash "${reposdir}" "${name}" "${stashdir}"
157 159
 
158 160
       exekutor rm ${COPYMOVEFLAGS} "${zombie}" >&2
159 161
new file mode 100755
... ...
@@ -0,0 +1,118 @@
1
+#! /bin/sh -x
2
+
3
+clear_test_dirs()
4
+{
5
+   local i
6
+
7
+   for i in "$@"
8
+   do
9
+      if [ -d "$i" ]
10
+      then
11
+         rm -rf "$i"
12
+      fi
13
+   done
14
+}
15
+
16
+
17
+fail()
18
+{
19
+   echo "failed" "$@" >&2
20
+   exit 1
21
+}
22
+
23
+
24
+run_mulle_bootstrap()
25
+{
26
+   echo "####################################" >&2
27
+   echo mulle-bootstrap "$@"  >&2
28
+   echo "####################################" >&2
29
+
30
+   mulle-bootstrap "$@" || fail "mulle-bootstrap failed"
31
+}
32
+
33
+
34
+#
35
+#
36
+#
37
+setup()
38
+{
39
+   mkdir -p main/a
40
+   mkdir -p main/b
41
+
42
+   (
43
+      cd main/a
44
+
45
+      mkdir -p .bootstrap
46
+      echo "b" > .bootstrap/repositories
47
+      cat <<EOF > a.c
48
+#include <b/b.h>
49
+
50
+int main()
51
+{
52
+   return( b());
53
+}
54
+EOF
55
+
56
+      cat <<EOF > CMakeLists.txt
57
+project( a)
58
+
59
+add_executable( a
60
+a.c
61
+)
62
+EOF
63
+   )
64
+
65
+   (
66
+      cd main/b
67
+
68
+      mkdir -p .bootstrap
69
+      cat <<EOF > b.c
70
+int   b()
71
+{
72
+   return( 0);
73
+}
74
+EOF
75
+      cat <<EOF > b.h
76
+int   b()
77
+{
78
+   return( 0);
79
+}
80
+EOF
81
+      cat <<EOF > CMakeLists.txt
82
+project( b)
83
+
84
+add_library( b
85
+b.c
86
+b.h
87
+)
88
+EOF
89
+   )
90
+}
91
+
92
+
93
+fail()
94
+{
95
+   echo "$@" >&2
96
+   exit 1
97
+}
98
+
99
+BOOTSTRAP_FLAGS="$@"
100
+
101
+cmake > /dev/null 2>&1
102
+if [ $? -eq 127 ]
103
+then
104
+   echo "cmake not installed, skipping test"
105
+   exit 0
106
+fi
107
+
108
+setup || exit 1
109
+
110
+(
111
+   ( cd main/a; run_mulle_bootstrap ${BOOTSTRAP_FLAGS} defer ) || exit 1
112
+   ( cd main/b; run_mulle_bootstrap ${BOOTSTRAP_FLAGS} defer ) || exit 1
113
+   ( cd main; run_mulle_bootstrap ${BOOTSTRAP_FLAGS} ) || exit 1
114
+)
115
+
116
+
117
+echo "succeeded" >&2
118
+
0 119
new file mode 100755
... ...
@@ -0,0 +1,75 @@
1
+#! /bin/sh
2
+
3
+
4
+clear_test_dirs()
5
+{
6
+   local i
7
+
8
+   for i in "$@"
9
+   do
10
+      if [ -d "$i" ]
11
+      then
12
+         rm -rf "$i"
13
+      fi
14
+   done
15
+}
16
+
17
+
18
+fail()
19
+{
20
+   echo "failed:" "$@" >&2
21
+   kill 0
22
+   exit 1
23
+}
24
+
25
+
26
+run_mulle_bootstrap()
27
+{
28
+   echo "####################################" >&2
29
+   echo mulle-bootstrap "$@"  >&2
30
+   echo "####################################" >&2
31
+
32
+   mulle-bootstrap "$@"  || fail "mulle-bootstrap failed"
33
+}
34
+
35
+
36
+#
37
+#
38
+#
39
+setup_test_case()
40
+{
41
+   clear_test_dirs a
42
+
43
+   mkdir -p a/.bootstrap
44
+
45
+   url=https://github.com/mulle-nat/Noobie/archive/tar-test.tar.gz
46
+   checksum="a8c0251d1cd8c0a08fde83724bff57cfcd3e49fcab262369dc117c788f751c9a"
47
+   echo "${url};;;tar?shasum256=${checksum}" > a/.bootstrap/repositories
48
+
49
+   url="https://github.com/mulle-nat/Foobie/archive/tar-test.zip"
50
+   checksum="f49106180b1fb5f4061a3528f6903f99e680ad169557bb876052eadbdb7a64a2"
51
+   echo "${url};;;zip?shasum256=${checksum}" >> a/.bootstrap/repositories
52
+}
53
+
54
+
55
+
56
+test_a()
57
+{
58
+   (
59
+      cd a
60
+      MULLE_BOOTSTRAP_CACHES_PATH=/tmp run_mulle_bootstrap "$@" fetch
61
+   )
62
+}
63
+
64
+
65
+#
66
+# not that much of a test
67
+#
68
+echo "mulle-bootstrap: `mulle-bootstrap version`(`mulle-bootstrap library-path`)" >&2
69
+
70
+setup_test_case
71
+test_a "$@"
72
+clear_test_dirs a
73
+
74
+echo "succeeded" >&2
75
+