@@ -369,6 +369,20 @@ latest_local_version() {
369
369
}
370
370
371
371
remote_html_cache=" "
372
+ remote_versions_read=0
373
+
374
+ normalize_version_for_match () {
375
+ local version=" $1 "
376
+ if [[ -n " $version " && ! " $version " =~ [* ] ]]; then
377
+ # not already a glob pattern
378
+ if [[ ! " $version " =~ ^v ]]; then
379
+ version=" v$version "
380
+ fi
381
+ version=" ${version% .} "
382
+ fi
383
+ echo " $version "
384
+ }
385
+
372
386
parse_remote_versions () {
373
387
local line
374
388
while read -r line; do
@@ -389,34 +403,40 @@ parse_remote_versions() {
389
403
load_remote_versions () {
390
404
local line
391
405
392
- [[ -n " $2 " ]] && {
393
- REMOTE_VERSIONS=()
406
+ [[ -n " $1 " ]] && {
407
+ remote_versions_read=0
394
408
}
395
409
396
- if [ ${# REMOTE_VERSIONS[@]} -eq 0 ]; then
410
+ if [ $remote_versions_read -eq 0 ]; then
411
+ REMOTE_VERSIONS=()
397
412
if [ -z " $remote_html_cache " ]; then
398
- [ -z " $1 " ] && logn " Downloading index from $ppa_host "
413
+ [ -z " $2 " ] && logn " Downloading index from $ppa_host "
399
414
remote_html_cache=$( download $ppa_host $ppa_index )
400
- [ -z " $1 " ] && log
415
+ [ -z " $2 " ] && log
401
416
fi
402
417
418
+ version_for_match=" $( normalize_version_for_match " $1 " ) "
403
419
IFS=$' \n '
404
420
while read -r line; do
421
+ (( remote_versions_read++ ))
405
422
# reinstate original rc suffix join character
406
423
if [[ $line =~ ^([^~]+)~([^~]+)$ ]]; then
407
424
[[ $use_rc -eq 0 ]] && continue
408
425
line=" ${BASH_REMATCH[1]} -${BASH_REMATCH[2]} "
409
426
fi
410
- [[ -n " $2 " ]] && [[ ! " $line " =~ $2 ]] && continue
411
- REMOTE_VERSIONS+=(" $line " )
427
+ if [[ -z " $version_for_match " ]] || \
428
+ [[ " $line " == $version_for_match || " $line " == $version_for_match .* || " $line " == $version_for_match -* ]]
429
+ then
430
+ REMOTE_VERSIONS+=(" $line " )
431
+ fi
412
432
done < <( parse_remote_versions | sort -V)
413
433
unset IFS
414
434
fi
415
435
}
416
436
417
437
latest_remote_version () {
418
- load_remote_versions 1 " $1 "
419
- echo " ${REMOTE_VERSIONS[${#REMOTE_VERSIONS[@]} -1]}"
438
+ load_remote_versions " $1 " 1
439
+ [[ ${ # REMOTE_VERSIONS[@]} -gt 0 ]] && echo " ${REMOTE_VERSIONS[${#REMOTE_VERSIONS[@]} -1]}"
420
440
}
421
441
422
442
check_environment () {
@@ -430,7 +450,7 @@ guard_run_as_root () {
430
450
if [ " $( id -u) " -ne 0 ]; then
431
451
echo " The '$run_action ' command requires root privileges"
432
452
exit 2
433
- fi
453
+ fi
434
454
}
435
455
436
456
# execute requested action
@@ -535,15 +555,13 @@ Optional:
535
555
;;
536
556
remote-list)
537
557
check_environment
538
- load_remote_versions
558
+ load_remote_versions " ${action_data[0]} "
539
559
540
560
# shellcheck disable=SC2015
541
561
[[ -n " $( command -v column) " ]] && { column=" column -x" ; } || { column=" cat" ; }
542
562
543
563
(for version in " ${REMOTE_VERSIONS[@]} " ; do
544
- if [ -z " ${action_data[0]} " ] || [[ " $version " =~ ${action_data[0]} ]]; then
545
- echo " $version "
546
- fi
564
+ echo " $version "
547
565
done) | $column
548
566
;;
549
567
install)
@@ -558,42 +576,37 @@ Optional:
558
576
version=$( latest_remote_version)
559
577
log
560
578
561
- if containsElement " $version " " ${LOCAL_VERSIONS[@]} " ; then
562
- logn " Latest version is $version but seems its already installed"
563
- else
564
- logn " Latest version is: $version "
565
- fi
566
-
567
- if [ $do_install -gt 0 ] && [ $assume_yes -eq 0 ]; then
568
- logn " , continue? (y/N) "
569
- [ $quiet -eq 0 ] && read -rsn1 continue
570
- log
579
+ [[ -z " $version " ]] && {
580
+ err " No readable versions found"
581
+ exit 2
582
+ }
571
583
572
- [ " $continue " != " y" ] && [ " $continue " != " Y" ] && { exit 0; }
573
- else
574
- log
575
- fi
584
+ logn " Latest version is $version "
576
585
else
577
- load_remote_versions
586
+ load_remote_versions " ${action_data[0]} "
578
587
579
- version=" "
580
- if containsElement " v${action_data[0]# v} " " ${REMOTE_VERSIONS[@]} " ; then
581
- version=" v" ${action_data[0]# v}
582
- fi
588
+ version=$( latest_remote_version)
583
589
584
590
[[ -z " $version " ]] && {
585
591
err " Version '${action_data[0]} ' not found"
586
592
exit 2
587
593
}
588
594
shift
589
595
590
- if [ $do_install -gt 0 ] && containsElement " $version " " ${LOCAL_VERSIONS[@]} " && [ $assume_yes -eq 0 ]; then
591
- logn " It seems version $version is already installed, continue? (y/N) "
592
- [ $quiet -eq 0 ] && read -rsn1 continue
593
- log
596
+ logn " Specified version matches $version "
597
+ fi
594
598
595
- [ " $continue " != " y" ] && [ " $continue " != " Y" ] && { exit 0; }
596
- fi
599
+ if containsElement " $version " " ${LOCAL_VERSIONS[@]} " ; then
600
+ logn " but it seems it's already installed"
601
+ fi
602
+ if [ $do_install -gt 0 ] && [ $assume_yes -eq 0 ]; then
603
+ logn " , continue? (y/N) "
604
+ [ $quiet -eq 0 ] && read -rsn1 continue
605
+ log
606
+
607
+ [ " $continue " != " y" ] && [ " $continue " != " Y" ] && { exit 0; }
608
+ else
609
+ log
597
610
fi
598
611
599
612
[ ! -d " $workdir " ] && {
0 commit comments