-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.deprecated-because-asdf.fish
1087 lines (1022 loc) · 42.4 KB
/
functions.deprecated-because-asdf.fish
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function execute
if test (count $argv) -eq 0
return 0
end
if which $argv[1] >/dev/null
eval $argv
return $status
else
return 1
end
end
function aws-alternate -d 'copy aws creds to alternate vars'
set -x AWS_ACCESS_KEY $AWS_ACCESS_KEY_ID
set -x AWS_SECRET_KEY $AWS_SECRET_ACCESS_KEY
end
function docker-images-tree -d 'Print docker images in a tree representation'
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz images -t
end
function docker-clean-volumes-dry-run -d 'Print volumes that could be removed'
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes --dry-run
end
function docker-clean-volumes -d 'Remove volumes that could be removed'
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes
end
function docker-clean-old-containers -d 'Remove old stopped containers'
docker ps -a | grep Exited | grep 'days ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm -v
end
function docker-clean-dangling-images -d 'Remove dangling images'
docker rmi (docker images --filter dangling=true --quiet)
end
#
# Usefull
#
function github_api_status -d 'Get github api status and quota'
curl -u "$GITHUB_BASIC_AUTH" -i https://api.github.com/users/looztra
end
function gitc -d 'Clone a git repository and prefix the local directory with the owner'
if test -z "$argv"
echo "Waiting for params that are not provided, bye"
return 1
end
set -l git_repository_url $argv[1]
set -l target_base_dir $argv[2]
set -l path_elements (string split / $git_repository_url)
set -l owner_elements (string split : $path_elements[-2])
set -l repo_elements (string split . $path_elements[-1])
set -l owner $owner_elements[-1]
set -l repo $repo_elements[1]
set -l target_dir
if test -z "$target_base_dir"
set target_base_dir "."
else
if not test -d $target_base_dir
echo "Target base [$target_base_dir] dir doesn't seem to exist, bye"
return 1
end
end
set -l target_dir "$target_base_dir/$owner--$repo"
if test -e $target_dir
echo "Cannot clone git repository [$git_repository_url] to directory [$target_dir] because file/directory already exist"
return 1
end
echo "Cloning repo [$git_repository_url] » [$target_dir]"
git clone $git_repository_url $target_dir
end
function gitct -d 'Clone a git repository, prefix the local dir with owner, and force target base dir'
set -l git_repository_url $argv[1]
set -l target_base_dir $argv[2]
set -l workspace_base_dir ~/workspace
if test -z $target_base_dir
echo "No target base dir provided, falling back to 'gitc'"
gitc $git_repository_url
else
gitc $git_repository_url $workspace_base_dir/$target_base_dir
end
end
#
# Installers / Updaters shared functions
function compute_latest_version -d "rely on latest"
set -l github_coordinates $argv[1]
printf (curl -u $GITHUB_BASIC_AUTH -s https://api.github.com/repos/$github_coordinates/releases/latest | jq -r '.tag_name')
end
function compute_latest_version_from_latest -d "rely on latest"
set -l github_coordinates $argv[1]
printf (curl -u $GITHUB_BASIC_AUTH -s https://api.github.com/repos/$github_coordinates/releases/latest | jq -r '.tag_name')
end
function compute_latest_version_from_tags -d "rely on tags"
set -l github_coordinates $argv[1]
printf (curl -u $GITHUB_BASIC_AUTH -s https://api.github.com/repos/$github_coordinates/tags | jq -rc '.[0] | .name')
end
function _use_compute_latest_version_from_latest
if type -q compute_latest_version
functions --erase compute_latest_version
end
functions --copy compute_latest_version_from_latest compute_latest_version
end
function _use_compute_latest_version_from_tags
if type -q compute_latest_version
functions --erase compute_latest_version
end
functions --copy compute_latest_version_from_tags compute_latest_version
end
function _reset_compute_latest_version
_use_compute_latest_version_from_latest
end
function compute_target_url_github -d "github style compute_target_url"
set -l github_coordinates $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
set -l target_artifact $argv[4]
set -l binary $argv[5]
printf https://github.com/$github_coordinates/releases/download/$target_version/$target_artifact
end
function create_temp_dir -d "create tmp download dir according to pattern"
set -l l_pattern $argv[1]
set -l l_base_dir /tmp/awesome-updater
mkdir -p $l_base_dir
printf (mktemp -d $l_base_dir/$l_pattern.XXXXXXXXX)
end
function download_and_install_binary
set -l target_url $argv[1]
set -l tmpdir $argv[2]
set -l binary $argv[3]
set -l no_auth $argv[4]
echo "Downloading from $target_url"
if test -n "$no_auth"
curl -Lo $tmpdir/{$binary} $target_url
else
curl -u $GITHUB_BASIC_AUTH -Lo $tmpdir/{$binary} $target_url
end
chmod +x $tmpdir/{$binary}
mv $tmpdir/{$binary} ~/.local/bin/
rm -rf $tmpdir
end
function download_and_untar_and_install
set -l target_url $argv[1]
set -l tmpdir $argv[2]
set -l binary $argv[3]
set -l no_auth $argv[4]
set -l untar_binary_ext $argv[5]
set -l untar_dir $argv[6]
set -l binary_prefix $argv[7]
if test -n "$no_auth"
curl -Lo $tmpdir/{$binary}.tgz $target_url
else
curl -u $GITHUB_BASIC_AUTH -Lo $tmpdir/{$binary}.tgz $target_url
end
and tar --directory $tmpdir -xf $tmpdir/$binary.tgz
and mv $tmpdir/{$binary}{$untar_binary_ext} ~/.local/bin/{$binary_prefix}{$binary}
and chmod +x ~/.local/bin/{$binary_prefix}{$binary}
end
function _use_download_and_install_binary
if type -q download_and_install
functions --erase download_and_install
end
functions --copy download_and_install_binary download_and_install
end
function _use_compute_target_url_github
if type -q compute_target_url
functions --erase compute_target_url
end
functions --copy compute_target_url_github compute_target_url
end
function _generic_update -d 'Generic updater'
set -l binary $argv[1]
set -l github_coordinates $argv[2]
set -l binary_version_cmd $argv[3..-1]
#
printf "binary : [$binary]\ngithub_coordinates : [$github_coordinates]\nbinary_version_cmd : [$binary_version_cmd]\n"
#
set -l tmpdir (create_temp_dir $binary)
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (compute_version)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (compute_latest_version $github_coordinates)
set target_version_short (echo $target_version | tr -d "v")
printf "Found target_version [$target_version]\nFound target_version_short [$target_version_short]\n"
if [ $target_version_short = $current_version ]
echo "Current version is already target/latest"
else
set -l target_artifact (compute_target_artifact $binary $target_version $target_version_short)
echo "Found target_artifact [$target_artifact]"
echo "Current version is not target/latest ($target_version), downloading..."
set -l target_url (compute_target_url $github_coordinates $target_version $target_version_short $target_artifact $binary)
#
download_and_install $target_url $tmpdir $binary
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(compute_version)
else
echo "[$binary] could not be installed, check logs"
end
end
end
#
# Installers / Updaters
#
function minikube-update -d 'Install latest minikube release'
execute minikube version >/dev/null ^/dev/null
if test $status -eq 0
set current_version (minikube version | cut -d " " -f 3)
echo "Current version $current_version"
else
set current_version ""
echo "Minikube is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/kubernetes/minikube/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/{$target_version}/minikube-linux-amd64
and chmod +x minikube
and mv minikube ~/.local/bin/
execute minikube version >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(minikube version | cut -d " " -f 3)
else
echo "Minikube could not be installed, check logs"
end
end
end
function minishift-update -d 'Install latest minishift release'
execute minishift version >/dev/null ^/dev/null
if test $status -eq 0
set current_version (minishift version | cut -d "+" -f 1 | cut -d " " -f 2)
echo "Current version $current_version"
else
set current_version ""
echo "Minishift is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/minishift/minishift/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
curl -Lo $HOME/tmp/minishift.tgz https://github.com/minishift/minishift/releases/download/{$target_version}/minishift-{$target_version_short}-linux-amd64.tgz
and tar --directory $HOME/tmp -xf $HOME/tmp/minishift.tgz
and chmod +x $HOME/tmp/minishift-{$target_version_short}-linux-amd64/minishift
and mv $HOME/tmp/minishift-{$target_version_short}-linux-amd64/minishift ~/.local/bin/
and rm -rf $HOME/tmp/minishift-{$target_version_short}-linux-amd64 $HOME/tmp/minishift.tgz
execute minishift version >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(minishift version | cut -d "+" -f 1 | cut -d " " -f 2)
else
echo "minishift could not be installed, check logs"
end
end
end
function kubectl-update -d 'Update kubectl to latest release'
set -l binary kubectl
set -l binary_artifact $binary
set -l tmpdir (mktemp -d)
set -l binary_version_cmd $binary version --client --short
set -l version_url https://storage.googleapis.com/kubernetes-release/release/stable.txt
function compute_artifact_url
set -l t_version $argv[1]
set -l t_artifact $argv[2]
printf "https://storage.googleapis.com/kubernetes-release/release/$t_version/bin/linux/amd64/$t_artifact"
end
#
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (execute $binary_version_cmd | cut -d " " -f 3)
echo "Current version $current_version"
else
set current_version ""
echo "$binary is not installed yet"
end
set target_version (curl -s $version_url)
if not test -z "$argv"
set target_version $argv
end
if [ $target_version = $current_version ]
echo "Current version is already target/latest ($target_version)"
else
echo "Current version is not target/latest ($target_version), downloading..."
echo "target_url "(compute_artifact_url $target_version $binary_artifact)
curl -Lo $tmpdir/$binary (compute_artifact_url $target_version $binary_artifact)
and chmod +x $tmpdir/$binary
and mv $tmpdir/$binary ~/.local/bin/
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd | cut -d " " -f 3)
else
echo "$binary could not be installed, check logs"
end
end
rm -rf $tmpdir
end
function oc-update -d 'Update oc to latest release'
set -l binary oc
set -l binary_artifact {$binary}.tar.gz
set -l tmpdir (mktemp -d)
mkdir -p $tmpdir/untar
set -l binary_version_cmd $binary version
#
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (execute $binary_version_cmd | head -n 1 | cut -d " " -f 2)
echo "Current version $current_version"
else
set current_version ""
echo "$binary is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/openshift/origin/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
if [ $target_version = $current_version ]
echo "Current version is already target/latest ($target_version)"
else
echo "Current version is not target/latest ($target_version), downloading..."
set -l target_artifact_path (curl -s https://api.github.com/repos/openshift/origin/releases/latest | jq '.assets[1].name' | tr -d '"')
set -l target_artifact_archive_dir (echo $target_artifact_path | cut -d "." -f 1-3)
set -l target_url https://github.com/openshift/origin/releases/download/{$target_version}/{$target_artifact_path}
echo "target_url $target_url"
curl -Lo $tmpdir/$binary_artifact $target_url
and tar --directory $tmpdir/untar -xf $tmpdir/$binary_artifact | true
and chmod +x $tmpdir/untar/{$target_artifact_archive_dir}/{$binary}
and mv $tmpdir/untar/{$target_artifact_archive_dir}/{$binary} ~/.local/bin/
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd | head -n 1 | cut -d " " -f 2)
else
echo "$binary could not be installed, check logs"
end
end
rm -rf $tmpdir
end
function compose-update -d 'Update docker-compose to version provided in param or latest release if no param provided'
set compose_version (curl -s https://api.github.com/repos/docker/compose/releases/latest | jq .tag_name | tr -d '"')
set -l tmpdir (mktemp -d)
if not test -z "$argv"
set compose_version $argv
end
echo "Retreiving docker-compose version $compose_version"
echo "gna"
curl -Lo {$tmpdir}/docker-compose https://github.com/docker/compose/releases/download/$compose_version/docker-compose-Linux-x86_64
chmod +x {$tmpdir}/docker-compose
and mv {$tmpdir}/docker-compose ~/.local/bin/
which docker-compose
docker-compose version
rm -rf $tmpdir
end
function machine-update -d 'Update docker-machine to version provided in param or latest release if no param provided'
set machine_version (curl -s https://api.github.com/repos/docker/machine/releases/latest | jq .tag_name | tr -d '"')
set -l tmpdir (mktemp -d)
set version_type default
if not test -z "$argv"
set version_type forced
set machine_version $argv
end
echo "Retreiving docker-machine version $machine_version ($version_type)"
curl -Lo {$tmpdir}/docker-machine https://github.com/docker/machine/releases/download/$machine_version/docker-machine-Linux-x86_64
chmod +x {$tmpdir}/docker-machine
and mv {$tmpdir}/docker-machine ~/.local/bin/
which docker-machine
docker-machine version
rm -rf $tmpdir
end
function terraform-update -d 'Update terraform to latest release'
set -l tmpdir (mktemp -d ~/tmp/tmp.terraform-XXXXXXXX)
file $tmpdir
set tf_version (curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | jq .tag_name | tr -d '"' | tr -d 'v')
curl -Lo $tmpdir/terraform.latest.zip https://releases.hashicorp.com/terraform/{$tf_version}/terraform_{$tf_version}_linux_amd64.zip
unzip -o $tmpdir/terraform.latest.zip -d $tmpdir/
chmod +x $tmpdir/terraform
and mv $tmpdir/terraform ~/.local/bin
and rm -rf $tmpdir
terraform version
end
function packer-update -d 'Update packer to latest release'
set -l tmpdir (mktemp -d ~/tmp/tmp.packer-XXXXXXXX)
file $tmpdir
set -l target_version (curl -s https://api.github.com/repos/hashicorp/packer/tags | jq -rc '.[0] | .name' | tr -d 'v')
set -l target_url https://releases.hashicorp.com/packer/{$target_version}/packer_{$target_version}_linux_amd64.zip
echo "Target url : $target_url"
curl -Lo $tmpdir/packer.latest.zip $target_url
file $tmpdir/packer.latest.zip
unzip -o $tmpdir/packer.latest.zip -d $tmpdir/
chmod +x $tmpdir/packer
and mv $tmpdir/packer ~/.local/bin
and rm -rf $tmpdir
packer version
end
function bat-update -d 'Install latest bat release'
# https://github.com/sharkdp/bat/releases/download/v0.6.1/bat-v0.6.1-x86_64-unknown-linux-gnu.tar.gz
set -l binary bat
set -l binary_artifact {$binary}.tar.gz
set -l binary_version_cmd $binary --version
set github_coordinates sharkdp/bat
set -l tmpdir (mktemp -d)
mkdir -p $tmpdir/untar
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version v(execute $binary_version_cmd | cut -d " " -f 2)
echo "Current version $current_version"
else
set current_version ""
echo "bat is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
set -l target_artifact {$binary}-{$target_version}-x86_64-unknown-linux-gnu.tar.gz
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
curl -Lo $tmpdir/{$binary_artifact} https://github.com/{$github_coordinates}/releases/download/{$target_version}/bat-{$target_version}-x86_64-unknown-linux-gnu.tar.gz
and tar --directory $tmpdir/untar -xf $tmpdir/{$binary_artifact}
and mv $tmpdir/untar/bat-{$target_version}-x86_64-unknown-linux-gnu/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd | cut -d " " -f 2)
else
echo "bat could not be installed, check logs"
end
end
end
function stern-update -d 'Install latest stern release'
# https://github.com/wercker/stern/releases/download/1.8.0/stern_linux_amd64
set -l binary stern
set -l binary_artifact $binary
set -l binary_version_cmd $binary --version
set github_coordinates wercker/stern
set -l tmpdir (mktemp -d)
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (execute $binary_version_cmd | cut -d " " -f 3)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
set -l target_artifact {$binary}_linux_amd64
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
set target_url https://github.com/{$github_coordinates}/releases/download/{$target_version}/{$target_artifact}
echo "Downloading from $target_url"
curl -Lo $tmpdir/{$binary_artifact} $target_url
and chmod +x $tmpdir/{$binary}
and mv $tmpdir/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd | cut -d " " -f 3)
else
echo "[$binary] could not be installed, check logs"
end
end
end
function rke-update -d 'Install latest rke release'
# https://github.com/rancher/rke/releases/download/v0.1.9/rke_linux-amd64
set -l binary rke
set -l binary_artifact $binary
set -l binary_version_cmd $binary --version
set github_coordinates rancher/rke
set -l tmpdir (mktemp -d)
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (execute $binary_version_cmd | cut -d " " -f 3)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
set -l target_artifact {$binary}_linux-amd64
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
set target_url https://github.com/{$github_coordinates}/releases/download/{$target_version}/{$target_artifact}
echo "Downloading from $target_url"
curl -Lo $tmpdir/{$binary_artifact} $target_url
and chmod +x $tmpdir/{$binary}
and mv $tmpdir/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd | cut -d " " -f 3)
else
echo "[$binary] could not be installed, check logs"
end
end
end
function helm-update -d 'Install latest helm release'
# https://github.com/helm/helm/releases/latest
# https://storage.googleapis.com/kubernetes-helm/helm-v2.11.0-linux-amd64.tar.gz
set -l binary helm
set -l binary_artifact {$binary}.tgz
set -l binary_version_cmd $binary version --client --template '"{{.Client.SemVer}}"'
set github_coordinates helm/helm
set -l tmpdir (mktemp -d /tmp/tmp.{$binary}-XXXXXXXX)
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (execute $binary_version_cmd | cut -d " " -f 3)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
set -l target_artifact {$binary}-{$target_version}-linux-amd64.tar.gz
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
set target_url https://storage.googleapis.com/kubernetes-helm/{$target_artifact}
echo "Downloading from $target_url"
curl -Lo $tmpdir/{$binary_artifact} $target_url
and tar --directory $tmpdir -xf $tmpdir/{$binary_artifact}
and mv $tmpdir/linux-amd64/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd | cut -d " " -f 3)
else
echo "[$binary] could not be installed, check logs"
end
end
end
function bats-update -d 'Update bat to latest release'
set -l binary bats
set -l binary_version_cmd $binary --version
set -l github_coordinates sstephenson/bats
set -l tmpdir (mktemp -d ~/tmp/tmp.{$binary}-XXXXXXXX)
file $tmpdir
set -l target_version (curl -s https://api.github.com/repos/{$github_coordinates}/tags | jq -rc '.[0] | .name')
set -l target_version_short (echo $target_version | tr -d 'v')
set -l target_url https://github.com/{$github_coordinates}/archive/{$target_version}.zip
echo "Target url : $target_url"
curl -Lo $tmpdir/{$binary}.latest.zip $target_url
file $tmpdir/{$binary}.latest.zip
unzip -o $tmpdir/{$binary}.latest.zip -d $tmpdir
execute {$tmpdir}/{$binary}-{$target_version_short}/install.sh ~/.local
rm -rf $tmpdir
execute $binary_version_cmd
end
function kubespy-update -d 'Install latest kubespy release'
# https://github.com/helm/helm/releases/latest
# https://github.com/pulumi/kubespy/releases/download/v0.4.0/kubespy-linux-amd64.tar.gz
set -l binary kubespy
set -l binary_artifact {$binary}.tgz
set -l binary_version_cmd $binary version
set github_coordinates pulumi/kubespy
set -l tmpdir (mktemp -d /tmp/tmp.{$binary}-XXXXXXXX)
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (execute $binary_version_cmd)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
set -l target_artifact {$binary}-linux-amd64.tar.gz
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
set target_url https://github.com/{$github_coordinates}/releases/download/{$target_version}/{$target_artifact}
echo "Downloading from $target_url"
curl -Lo $tmpdir/{$binary_artifact} $target_url
and tar --directory $tmpdir -xf $tmpdir/{$binary_artifact}
and mv $tmpdir/releases/kubespy-linux-amd64/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(execute $binary_version_cmd)
else
echo "[$binary] could not be installed, check logs"
end
end
end
function dep-update -d 'Install latest dep release'
# https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
set -l binary dep
set -l binary_version_cmd $binary version
set -l github_coordinates golang/dep
set -l target_artifact {$binary}-linux-amd64
set -l tmpdir (mktemp -d)
function compute_version
dep version | grep version | grep -v "go" | sed "s/ *//g" | cut -d ":" -f2
end
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version (compute_version)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq .tag_name | tr -d '"')
if not test -z "$argv"
set target_version $argv
end
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
set target_url https://github.com/{$github_coordinates}/releases/download/{$target_version}/{$target_artifact}
echo "Downloading from $target_url"
curl -Lo $tmpdir/{$binary} $target_url
and chmod +x $tmpdir/{$binary}
and mv $tmpdir/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version "(compute_version)
else
echo "[$binary] could not be installed, check logs"
end
end
end
function terraform-docs-update -d 'Install latest terraform-docs release'
# https://github.com/segmentio/terraform-docs/releases/download/v0.6.0/terraform-docs-v0.6.0-linux-amd64
set -l binary terraform-docs
set -l binary_version_cmd $binary --version
set -l github_coordinates segmentio/terraform-docs
set -l tmpdir (mktemp -d /tmp/tmp.$binary.XXXXXXXX)
function compute_version
terraform-docs --version
end
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
set current_version "v"(compute_version)
echo "Current version $current_version"
else
set current_version ""
echo "[$binary] is not installed yet"
end
set target_version (curl -s https://api.github.com/repos/{$github_coordinates}/releases/latest | jq -r .tag_name)
if not test -z "$argv"
set target_version $argv
end
if [ $target_version = $current_version ]
echo "Current version is already target/latest"
else
echo "Current version is not target/latest ($target_version), downloading..."
set target_version_short (echo $target_version | tr -d "v")
set -l target_artifact {$binary}-{$target_version}-linux-amd64
set target_url https://github.com/{$github_coordinates}/releases/download/{$target_version}/{$target_artifact}
echo "Downloading from $target_url"
curl -Lo $tmpdir/{$binary} $target_url
and chmod +x $tmpdir/{$binary}
and mv $tmpdir/{$binary} ~/.local/bin/
and rm -rf $tmpdir
execute $binary_version_cmd >/dev/null ^/dev/null
if test $status -eq 0
echo "Installed version v"(compute_version)
else
echo "[$binary] could not be installed, check logs"
end
end
end
function vault-update -d 'Update vault to latest release'
set -l tmpdir (mktemp -d ~/tmp/tmp.vault-XXXXXXXX)
file $tmpdir
set -l target_version (curl -s https://api.github.com/repos/hashicorp/vault/tags | jq -rc '.[0] | .name' | tr -d 'v')
set -l target_url https://releases.hashicorp.com/vault/{$target_version}/vault_{$target_version}_linux_amd64.zip
echo "Target url : $target_url"
curl -Lo $tmpdir/vault.latest.zip $target_url
file $tmpdir/vault.latest.zip
unzip -o $tmpdir/vault.latest.zip -d $tmpdir/
chmod +x $tmpdir/vault
and mv $tmpdir/vault ~/.local/bin
and rm -rf $tmpdir
vault version
end
function k9s-update -d 'Update k9s to latest release'
# https://github.com/derailed/k9s/releases/download/0.1.2/k9s_0.1.2_Linux_x86_64.tar.gz
set -l binary k9s
set -l binary_version_cmd $binary version
set -l github_coordinates derailed/k9s
function compute_version
k9s version | cut -d " " -f1 | cut -d ":" -f2
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s_%s_Linux_x86_64.tar.gz" $binary $target_version_short
end
function download_and_install
set -l target_url $argv[1]
set -l tmpdir $argv[2]
set -l binary $argv[3]
set -l no_auth ""
set -l untar_binary_ext ""
set -l untar_dir ""
set -l binary_prefix ""
download_and_untar_and_install $target_url $tmpdir $binary $no_auth $untar_binary_ext $untar_dir $binary_prefix
end
_use_compute_latest_version_from_tags
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
_reset_compute_latest_version
end
function rbac-lookup-update -d 'Install latest rbac-lookup release'
# https://github.com/reactiveops/rbac-lookup/releases/download/v0.2.1/rbac-lookup_0.2.1_Linux_x86_64.tar.gz
set -l binary rbac-lookup
set -l binary_version_cmd $binary version
set -l github_coordinates reactiveops/rbac-lookup
function compute_version
rbac-lookup version | cut -d " " -f 3
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s_%s_Linux_x86_64.tar.gz" $binary $target_version_short
end
function download_and_install
set -l target_url $argv[1]
set -l tmpdir $argv[2]
set -l binary $argv[3]
set -l no_auth ""
set -l untar_binary_ext ""
set -l untar_dir ""
set -l binary_prefix ""
download_and_untar_and_install $target_url $tmpdir $binary $no_auth $untar_binary_ext $untar_dir $binary_prefix
end
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function kustomize-update -d 'Install latest kustomize release'
# https://github.com/kubernetes-sigs/kustomize/releases/download/v2.0.1/kustomize_2.0.1_linux_amd64
set -l binary kustomize
set -l binary_version_cmd $binary version
set -l github_coordinates kubernetes-sigs/kustomize
function compute_version
kustomize version | cut -d ":" -f3 | cut -d " " -f1
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s_%s_linux_amd64" $binary $target_version_short
end
_use_download_and_install_binary
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function krew-update -d 'Install latest krew release'
# https://storage.googleapis.com/krew/v0.2.1/krew.tar.gz
set -l binary krew
set -l binary_version_cmd kubectl-{$binary} version
set -l github_coordinates GoogleContainerTools/krew
function compute_version
kubectl-krew version | grep GitTag | cut -d "v" -f2
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf $binary".tar.gz"
end
function compute_target_url -d "google style compute_target_url"
set -l github_coordinates $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
set -l target_artifact $argv[4]
set -l binary $argv[5]
printf https://storage.googleapis.com/{$binary}/{$target_version}/{$target_artifact}
end
function download_and_install
set -l target_url $argv[1]
set -l tmpdir $argv[2]
set -l binary $argv[3]
set -l no_auth NO_AUTH_BECAUSE_GOOGLE_STORAGE
set -l untar_binary_ext "-linux_amd64"
set -l untar_dir ""
set -l binary_prefix "kubectl-"
download_and_untar_and_install $target_url $tmpdir $binary $no_auth $untar_binary_ext $untar_dir $binary_prefix
end
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function kubeval-update -d 'Install latest kubeval release'
# OLD https://github.com/garethr/kubeval/releases/download/0.7.3/kubeval-linux-amd64.tar.gz
# https://github.com/instrumenta/kubeval/releases/download/0.10.0/kubeval-linux-amd64.tar.gz
set -l binary kubeval
set -l github_coordinates instrumenta/$binary
set -l binary_version_cmd $binary --version
function compute_version
kubeval --version | grep Version | cut -d ":" -f2 | tr -d " "
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf $binary"-linux-amd64.tar.gz"
end
function download_and_install
set -l target_url $argv[1]
set -l tmpdir $argv[2]
set -l binary $argv[3]
set -l no_auth ""
set -l untar_binary_ext ""
set -l untar_dir ""
set -l binary_prefix ""
download_and_untar_and_install $target_url $tmpdir $binary $no_auth $untar_binary_ext $untar_dir $binary_prefix
end
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function terragrunt-update -d 'Install latest terragrunt release'
# https://github.com/gruntwork-io/terragrunt/releases/download/v0.18.0/terragrunt_linux_amd64
set -l binary terragrunt
set -l binary_version_cmd $binary --help
set -l github_coordinates gruntwork-io/terragrunt
function compute_version
terragrunt --help | grep -A2 VERSION | paste -sd ',' | tr -d '[:space:]' | cut -d "," -f2 | tr -d "v"
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s_linux_amd64" $binary
end
_use_download_and_install_binary
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function ytt-update -d 'Install latest ytt release'
# https://github.com/get-ytt/ytt/releases/download/v0.1.0/ytt-linux-amd64
set -l binary ytt
set -l binary_version_cmd $binary version
set -l github_coordinates get-ytt/ytt
function compute_version
ytt version | cut -d " " -f2
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s-linux-amd64" $binary
end
_use_download_and_install_binary
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function reg-update -d 'Install latest reg release'
#https://github.com/genuinetools/reg/releases/download/v0.16.0/reg-linux-amd64
set -l binary reg
set -l binary_version_cmd $binary version
set -l github_coordinates genuinetools/reg
function compute_version
reg version | grep version | grep -v "go" | cut -d ":" -f2 | tr -d " " | tr -d "v"
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s-linux-amd64" $binary
end
_use_download_and_install_binary
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end
function skaffold-update -d 'Install latest skaffold release'
# https://github.com/GoogleContainerTools/skaffold/releases/download/v0.24.0/skaffold-linux-amd64
set -l binary skaffold
set -l binary_version_cmd $binary version
set -l github_coordinates GoogleContainerTools/skaffold
function compute_version
skaffold version | tr -d "v"
end
function compute_target_artifact
set -l binary $argv[1]
set -l target_version $argv[2]
set -l target_version_short $argv[3]
printf "%s-linux-amd64" $binary
end
_use_download_and_install_binary
_use_compute_target_url_github
#
# Nothing more to customize down here (crossing fingers)
#
_generic_update $binary $github_coordinates $binary_version_cmd
end