This repository has been archived by the owner on Nov 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
myprojects_template
16159 lines (14131 loc) · 607 KB
/
myprojects_template
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
#!/usr/bin/env bash
#******************************************************************************
# Copyright 2020 Clark Hsu
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#******************************************************************************
# How To
# mkdir -p ${HOME}/.my_libs/bash/
# cp myprojects_template ${HOME}/.my_libs/bash/cp myprojects
#******************************************************************************
# Source
# LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#******************************************************************************
#******************************************************************************
# Functions
# function function_01() {
# if [ "$#" != "1" ]; then
# log_e "Usage: ${FUNCNAME[0]} <ARGS>"
# log_e "${FUNCNAME[0]} $# ${*}"
# else
# log_m "${FUNCNAME[0]} $# ${*}"
# # cd "${TOP_DIR:?}" || exit 1
# fi
# }
#******************************************************************************
# Sourcing
function source_rc() {
if [ "$#" != "2" ]; then
log_e "Usage: ${FUNCNAME[0]} <DISTRO> <PLATFORM>"
log_e "${FUNCNAME[0]} $# ${*}"
else
# log_m "${FUNCNAME[0]} $# ${*}"
# cd "${TOP_DIR:?}" || exit 1
case ${1} in
# alpine) ;;
# centos | fedora | rhel | oracle-linux | alma-linux | rocky-linux) ;;
# cirros) ;;
# debian | raspios | ubuntu) ;;
# macos | macosx) ;;
# opensuse-leap | opensuse-tumbleweed | sles) ;;
windows) ;;
*)
# echo -e "\n>>> Source ${1} RC...\n"
# check_file_exist "${TOP_DIR:?}/os-openrc-${1}.sh"
# if [[ $? -ne 0 ]]; then
# echo -e "\nPlease download/setup os-openrc-${1}.sh"
# exit 1
# fi
# # shellcheck source=/dev/null
# source "${TOP_DIR:?}/os-openrc-${1}.sh"
[[ $PS1 && -f "${TOP_DIR:?}/os-openrc-${1}.sh" ]] && source "${TOP_DIR:?}/os-openrc-${1}.sh" || true
;;
esac
case ${2} in
aws | azure | gcp | openstack | vmware | vsphere)
echo -e "\n>>> Source ${2} RC...\n"
check_file_exist "${TOP_DIR:?}/container-openrc-${2}.sh"
if [[ $? -ne 0 ]]; then
echo -e "\nPlease download/setup container-openrc-${2}.sh"
exit 1
fi
# shellcheck source=/dev/null
source "${TOP_DIR:?}/container-openrc-${2}.sh"
;;
libvirt) ;;
bare-matel | host) ;;
*)
[[ $PS1 && -f "${TOP_DIR:?}/os-openrc-${2}.sh" ]] && source "${TOP_DIR:?}/os-openrc-${2}.sh" || true
;;
esac
fi
}
#******************************************************************************
# Detection Environment
# https://danilodellaquila.com/en/blog/linux-package-management-cheatsheet
# https://distrowatch.com/dwres.php?resource=package-management
# https://lzone.de/cheat-sheet/Package%20Management
# https://www.tecmint.com/list-all-running-services-under-systemd-in-linux/
function detect_package_system() {
if [ "$#" != "0" ] && [ "$#" != "2" ] && [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} [<PACKAGE_MANAGER> <PACKAGE_SYSTEM> [<DISTRO>]]"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
# cd "${TOP_DIR:?}" || exit 1
# DISTROS="alma-linux alpine arch-linux centos chromeos cirros debian fedora gentoo hyperiotos macosx opensuse-leap opensuse-tumbleweed oracle-linux photonos rancher-harvester rancker-k3os rancher-os raspios rhel rocky-linux sles ubuntu microsoft pxe"
DISTROS="alma-linux alpine centos cirros debian fedora macosx opensuse-leap opensuse-tumbleweed oracle-linux rancher-harvester rancker-k3os rancher-os rocky-linux sles ubuntu microsoft pxe"
OSS="darwin linux freebsd microsoft"
ARCHS="x86_64 amd64"
INSTALL_METHODS="bin tar bz2 xz zstd rar zip script rpm go npm pip docker podman"
PROJECT_TYPES="ansible_app bash_app bash_create_project_app bash_deployment_app bash_install_app bash_remote_deployment_app docker_app helm_app helm3_app minifest_app deployment_app terraform_app"
INFRASTRUCTURE_DEPLOYMENT_PROJECTS="terraform_env terraform_mos"
LOCATIONS="local remote"
PLATFORMS="aws azure bare-metal gcp libvirt openstack vmware vsphere"
PLATFORM_DISTROS="${DISTROS} mos"
RUNTIMES="daemon container kubernetes"
ROLES="server client master worker helloworld all"
SSH_USERS="${DISTROS} mos root ec2-user"
# if [ "${PLATFORM}" == "" ]; then
# # select_x_from_array "${PLATFORMS}" "PLATFORM" PLATFORM # "libvirt"
# read_and_confirm "PLATFORM MSG" PLATFORM "libvirt"
# fi
if [ "$#" == "2" ]; then
PACKAGE_MANAGER=${1} # apk,apt-get,brew,dnf,emerge,pacman,yum,zypper,xbps-install,tar,zip
PACKAGE_SYSTEM=${2} # apk,dpkg,pkgbuild,rpm,tar,zip,go,npm,pip,docker
if [ "${DISTRO}" == "" ]; then
select_x_from_array "${DISTROS}" "DISTRO" DISTRO # centos
fi
elif [ "$#" == "3" ]; then
PACKAGE_MANAGER=${1} # apk,apt-get,brew,dnf,emerge,pacman,yum,zypper,xbps-install,tar,zip
PACKAGE_SYSTEM=${2} # apk,dpkg,pkgbuild,rpm,tar,zip,go,npm,pip,docker
DISTRO=${2} # alpine | cirros | centos | fedora | rhel | debian | raspios | ubuntu | rancher-os | rancker-k3os | opensuse-leap | opensuse-tumbleweed | oracle-linux | sles | macosx | microsoft
else
PACKAGE_MANAGER=$(basename $(command -v {apt-get,brew,dnf,emerge,pacman,yum,zypper,xbps-install} 2>/dev/null) 2>/dev/null || basename $(command -v apk 2>/dev/null) 2>/dev/null)
PACKAGE_SYSTEM=$(basename $(command -v {dpkg,pkgbuild,rpm} 2>/dev/null) 2>/dev/null || basename $(command -v apk 2>/dev/null) 2>/dev/null)
DISTRO=$(cat /etc/*-release 2>/dev/null | uniq -u | grep ^ID= | cut -d = -f 2 | sed s/\"//g | sed s/linux/-linux/g && sw_vers -productName 2>/dev/null | sed 's/ //g' | tr A-Z a-z) # alpine | centos | debian | fedora | macosx | microsoft | opensuse-leap | opensuse-tumbleweed | oracle-linux | sles | ubuntu
fi
OS=$(uname -s | tr A-Z a-z) # darwin | linux | freebsd | microsoft
case ${OS} in
CYGWIN* | *_NT-*)
OS=windows
HOST_EXE=.exe
if [ "x${OSTYPE}" = xcygwin ]; then
OS=cygwin
fi
;;
*)
HOST_EXE=""
;;
esac
ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') # x86_64 | amd64
echo -e "\n>>> ${PACKAGE_MANAGER} ${PACKAGE_SYSTEM} ${DISTRO} ${OS} ${ARCH}...."
fi
}
function detect_host_hardware() {
if [ "$#" != "0" ] && [ "$#" != "2" ] && [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} [<PACKAGE_MANAGER> <PACKAGE_SYSTEM> [<DISTRO>]]"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
# cd "${TOP_DIR:?}" || exit 1
HOST_CPU=$(uname -p)
case ${OS} in
linux)
HOST_NUM_CPUS=$(cat /proc/cpuinfo | grep processor | wc -l)
;;
darwin | freebsd)
HOST_NUM_CPUS=$(sysctl -n hw.ncpu)
;;
windows | cygwin)
HOST_NUM_CPUS=${NUMBER_OF_PROCESSORS}
;;
*) # let's play safe here
HOST_NUM_CPUS=1 ;;
esac
case ${OS} in
linux)
HOST_RAM=$(free -m | grep "Mem:" | awk '{print ${2}}')
;;
darwin | freebsd)
HOST_RAM=$(sysctl -a | grep hw.memsize | awk '{print ${3}}')
;;
*) # let's play safe here
HOST_RAM="" ;;
esac
HOST_HHD=$(df -h | sed -n 2p | awk '{print ${2}}')
fi
}
# function set_project() {
# if [ "$#" != "1" ]; then
# log_e "Usage: ${FUNCNAME[0]} <ARGS>"
# log_e "${FUNCNAME[0]} $# ${*}"
# else
# log_m "${FUNCNAME[0]} $# ${*}"
# # cd "${TOP_DIR:?}" || exit 1
# local PLATFORMS="aws azure bare-metal gcp libvirt openstack vmware vsphere"
# # local DISTROS="alma-linux alpine arch-linux centos chromeos cirros debian fedora gentoo hyperiotos macosx opensuse-leap opensuse-tumbleweed oracle-linux photonos rancher-harvester rancker-k3os rancher-os raspios rhel rocky-linux sles ubuntu microsoft pxe"
# local DISTROS="alma-linux alpine centos cirros debian fedora macosx opensuse-leap opensuse-tumbleweed oracle-linux rancher-harvester rancker-k3os rancher-os rocky-linux sles ubuntu microsoft pxe"
# local OSS="darwin linux freebsd microsoft"
# local ARCHS="x86_64 amd64"
# if [ "${SRC_DIR}" == "" ]; then
# # select_x_from_array "a b c" "SRC_DIR" SRC_DIR # "a"
# # read_and_confirm "SRC_DIR MSG" SRC_DIR # "SRC_DIR set value"
# # SRC_DIR=${HOME}/Documents/myProject/${REPO}/${PROJECT}
# SRC_DIR=${HOME}/Documents/myProject/Template/helloworld_app
# # SRC_DIR=${HOME}/Documents/myProject/Template/helloworld_template
# fi
# if [ "${PROJECT_BIN}" == "" ]; then
# # select_x_from_array "a b c" "PROJECT_BIN" PROJECT_BIN # "a"
# PROJECT_BIN= #
# fi
# if [ "${INSTALL_METHOD}" == "" ]; then
# # select_x_from_array "bin tar bz2 xz zstd rar zip script rpm go npm pip docker podman" "INSTALL_METHOD" INSTALL_METHOD # "a"
# INSTALL_METHOD=tar #
# fi
# SYSTEMD_SERVICE_NAME=${PROJECT_BIN} #
# GITHUB_USER= #
# if [ "${GITHUB_USER}" == "" ]; then
# # select_x_from_array "cclhsu" "GITHUB_USER" GITHUB_USER # "cclhsu"
# read_and_confirm "GITHUB_USER MSG" GITHUB_USER #"cclhsu"
# fi
# GITHUB_USER_NAME= #
# if [ "${GITHUB_USER_NAME}" == "" ]; then
# # select_x_from_array "cclhsu" "GITHUB_USER_NAME" GITHUB_USER_NAME # "Clark Hsu"
# read_and_confirm "GITHUB_USER_NAME MSG" GITHUB_USER_NAME #"Clark Hsu"
# fi
# if [ "${GITHUB_PROJECT}" == "" ]; then
# read_and_confirm "GITHUB_PROJECT MSG" GITHUB_PROJECT "${PROJECT_BIN}"
# fi
# # https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
# if [ "${PACKAGE_VERSION}" == "" ]; then
# # read_and_confirm "PACKAGE_VERSION MSG" PACKAGE_VERSION "v0.0.1"
# PACKAGE_VERSION=$(curl -s "https://api.github.com/repos/${GITHUB_USER}/${GITHUB_PROJECT}/releases/latest" | jq --raw-output .tag_name)
# fi
# if [ "${PLATFORM}" == "" ]; then
# # select_x_from_array "${PLATFORMS}" "PLATFORM" PLATFORM # "libvirt"
# read_and_confirm "PLATFORM MSG" PLATFORM "libvirt"
# fi
# if [ "${PLATFORM_DISTRO}" == "" ]; then
# select_x_from_array "${PLATFORM_DISTROS}" "PLATFORM_DISTRO" PLATFORM_DISTRO # centos
# fi
# if [ "${DISTRO}" == "" ]; then
# select_x_from_array "${DISTROS}" "DISTRO" DISTRO # centos
# fi
# if [ "${OS}" == "" ]; then
# select_x_from_array "${OSS}" "OS" OS # "linux"
# read_and_confirm "OS MSG" OS "linux"
# fi
# if [ "${ARCH}" == "" ]; then
# select_x_from_array "${ARCHS}" "ARCH" ARCH # "amd64"
# read_and_confirm "ARCH MSG" ARCH "amd64"
# fi
# echo ">>> Platform/Distribution: ${PLATFORM}/${PLATFORM_DISTRO}"
# echo ">>> Package: ${DISTRO}/${GITHUB_USER}/${GITHUB_PROJECT}/${PACKAGE_VERSION}/${PROJECT_BIN}-${OS}-${ARCH}"
# fi
# }
# function set_deployment() {
# if [ "$#" != "1" ]; then
# log_e "Usage: ${FUNCNAME[0]} <ARGS>"
# log_e "${FUNCNAME[0]} $# ${*}"
# else
# log_m "${FUNCNAME[0]} $# ${*}"
# # cd "${TOP_DIR:?}" || exit 1
# local LOCATIONS="local remote"
# local PLATFORMS="aws azure bare-metal gcp libvirt openstack vmware vsphere"
# local PLATFORM_DISTROS="${DISTROS}"
# local RUNTIMES="daemon container kubernetes"
# local ROLES="server client master worker helloworld all"
# local SSH_USERS="${DISTROS} mos root ec2-user"
# if [ "${LOCATION}" == "" ]; then
# # select_x_from_array "${LOCATIONS}" "LOCATION" LOCATION # "remote"
# read_and_confirm "LOCATION MSG" LOCATION "remote"
# fi
# if [ "${PLATFORM}" == "" ]; then
# # select_x_from_array "${PLATFORMS}" "PLATFORM" PLATFORM # "libvirt"
# read_and_confirm "PLATFORM MSG" PLATFORM "libvirt"
# fi
# if [ "${PLATFORM_DISTRO}" == "" ]; then
# # select_x_from_array "${DISTROS}" "PLATFORM_DISTRO" PLATFORM_DISTRO # "centos"
# read_and_confirm "PLATFORM_DISTRO" PLATFORM_DISTRO "centos"
# fi
# if [ "${RUNTIME}" == "" ]; then
# # select_x_from_array "${RUNTIMES}" "RUNTIME" RUNTIME # "daemon"
# read_and_confirm "RUNTIME MSG" RUNTIME "daemon"
# fi
# if [ "${ROLE}" == "" ]; then
# # select_x_from_array "${ROLES}" "ROLE" ROLE # "helloworld"
# read_and_confirm "ROLE MSG" ROLE "helloworld"
# fi
# if [ "${SSH_USER}" == "" ]; then
# # select_x_from_array " "${SSH_USERS}" SSH_USER # "sles"
# read_and_confirm "SSH_USER MSG" SSH_USER "centos"
# fi
# if [ "${SSH_PASSWORD}" == "" ]; then
# read_and_confirm "SSH_PASSWORD MSG" SSH_PASSWORD "linux"
# fi
# echo ">>> Platform/Distribution: ${PLATFORM}/${PLATFORM_DISTRO}"
# echo ">>> Package: ${DISTRO}/${GITHUB_USER}/${GITHUB_PROJECT}/${PACKAGE_VERSION}/${PROJECT_BIN}-${OS}-${ARCH}"
# fi
# }
#******************************************************************************
# Set Alias
function set_alias_by_distribution() {
if [ "$#" != "0" ] && [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} [<DISTRO>] [<CASK>]"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
# cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "1" ]; then
local _DISTRO=${1} # alpine | centos | debian | fedora | macosx | microsoft | opensuse-leap | opensuse-tumbleweed | oracle-linux | sles | ubuntu
else
local _DISTRO=${DISTRO}
fi
case ${_DISTRO} in
alpine)
USER_BIN="/usr/bin"
USER_LOCAL_BIN="/usr/local/bin"
ETC="/etc"
# ADD_KEY="/etc/apk/keys/"
LIST_REPO="cat /etc/apk/repositories"
# ADD_REPO="/etc/apk/repositories" # /etc/apk/repositories
# REMOVE_REPO="/etc/apk/repositories" # /etc/apk/repositories
REPO_UPDATE="apk update"
INSTALL_PACKAGE="apk add --update --no-cache"
REINSTALL_PACKAGE=""
UNINSTALL_PACKAGE="apk del --purge"
DOWNLOAD_PACKAGE=""
UPGRADE_PACKAGE="apk upgrade"
DIST_UPGRADE="apk upgrade --available"
SEARCH_PACKAGE="apk search"
WHAT_PROVIDES=""
LIST_INSTALL_PACKAGES="apk list"
SHOW_PACKAGE_INFORMATION="apk info"
CLEAN_KERNEL=""
CLEAN_CACHE="apk cache clean; sudo rm -rf /var/cache/apk/*; ls /var/cache/apk/"
ENABLE_SERVICE=""
START_SERVICE=""
STATUS_SERVICE=""
LOG_SERVICE=""
STOP_SERVICE=""
DISABLE_SERVICE=""
LIST_SERVICE=""
OPEN="open" # xdg-open | open
;;
centos | fedora | rhel | oracle-linux | alma-linux | rocky-linux)
USER_BIN="/usr/bin"
USER_LOCAL_BIN="/usr/local/bin"
ETC="/etc"
PACKAGE_MANAGER_TYPE=yum # yum | dnf
if [ ${PACKAGE_MANAGER_TYPE} == yum ]; then
# https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf
ADD_KEY="sudo rpm --import" # /etc/pki/rpm-gpg/
LIST_REPO="sudo yum repolist"
# ADD_REPO="yum-config-manager --add-repo" # /etc/yum.repos.d/
# REMOVE_REPO="/etc/yum.repos.d/" # /etc/yum.repos.d/
REPO_UPDATE="sudo yum check-update"
INSTALL_PACKAGE="sudo yum install -y"
REINSTALL_PACKAGE=""
UNINSTALL_PACKAGE="sudo yum remove -y --remove-leaves"
DOWNLOAD_PACKAGE="sudo yum install -y --downloadonly" #--downloaddir="${DOWNLOAD_DIR}" "${PACKAGE}"
UPGRADE_PACKAGE="sudo yum update -y"
DIST_UPGRADE="sudo yum upgrade -y"
SEARCH_PACKAGE="sudo yum search" # sudo yum list
WHAT_PROVIDES="sudo yum whatprovides"
LIST_INSTALL_PACKAGES="sudo rpm -qa"
LIST_PACKAGES_CONTENT="sudo rpm -ql"
SHOW_PACKAGE_INFORMATION="sudo yum info"
CLEAN_KERNEL="package-cleanup --oldkernels --count=2;sed -i 's/^installonly_limit=.*/installonly_limit=2/g' /etc/yum.conf; rpm -q kernel;"
CLEAN_CACHE="sudo yum clean all; sudo rm -rf /var/cache/yum/*; ls /var/cache/yum/;"
else
# https://dnf.readthedocs.io/en/latest/command_ref.html
# https://cheatography.com/misterrabinhalder/cheat-sheets/dnf/
# https://www.linuxtechi.com/dnf-command-examples-rpm-management-fedora-linux/
ADD_KEY="sudo rpm --import" # /etc/pki/rpm-gpg/
LIST_REPO="sudo dnf repolist --all"
# ADD_REPO="dnf config-manager --add-repo" # /etc/yum.repos.d/
# REMOVE_REPO="/etc/yum.repos.d/" # /etc/yum.repos.d/
REPO_UPDATE="sudo dnf check-update"
INSTALL_PACKAGE="sudo dnf install -y"
REINSTALL_PACKAGE="sudo dnf reinstall -y"
UNINSTALL_PACKAGE="sudo dnf remove -y"
DOWNLOAD_PACKAGE="sudo dnf download" -y
UPGRADE_PACKAGE="sudo dnf upgrade -y"
DIST_UPGRADE="sudo dnf distro-sync"
SEARCH_PACKAGE="sudo dnf search"
WHAT_PROVIDES="sudo dnf provides"
LIST_INSTALL_PACKAGES="sudo dnf list --installed"
LIST_PACKAGES_CONTENT="sudo dnf info"
SHOW_PACKAGE_INFORMATION="sudo dnf info"
CLEAN_KERNEL="package-cleanup --oldkernels --count=2;sed -i 's/^installonly_limit=.*/installonly_limit=2/g' /etc/yum.conf; rpm -q kernel;"
CLEAN_CACHE="sudo dnf clean all; sudo rm -rf /var/cache/yum/*; ls /var/cache/yum/;"
fi
ENABLE_SERVICE="sudo systemctl enable"
START_SERVICE="sudo systemctl start"
STATUS_SERVICE="sudo systemctl status"
LOG_SERVICE="sudo journalctl -xet"
STOP_SERVICE="sudo systemctl stop"
DISABLE_SERVICE="sudo systemctl disable"
LIST_SERVICE="sudo systemctl list-units --type=service --state=running"
OPEN="open" # xdg-open | open
;;
debian | raspios | ubuntu)
USER_BIN="/usr/bin"
USER_LOCAL_BIN="/usr/local/bin"
ETC="/etc"
# https://www.debian.org/doc/manuals/refcard/refcard#
# https://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html
# https://www.cyberciti.biz/howto/question/linux/dpkg-cheat-sheet.php
ADD_KEY="sudo apt-key add"
LIST_REPO="grep -r --include '*.list' '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d/"
# ADD_REPO="/etc/apt/sources.list.d/" # /etc/apt/sources.list.d/
# REMOVE_REPO="/etc/apt/sources.list.d/" # /etc/apt/sources.list.d/
REPO_UPDATE="sudo apt-get update"
INSTALL_PACKAGE="sudo apt-get install -y --force-yes"
REINSTALL_PACKAGE="sudo apt-get update -y --fix-missing; sudo apt-get -f install -y --force-yes --fix-missing"
UNINSTALL_PACKAGE="sudo apt-get remove --purge -y"
DOWNLOAD_PACKAGE="sudo apt-get install --download-only --reinstall -y"
UPGRADE_PACKAGE="sudo apt-get upgrade -y --force-yes"
DIST_UPGRADE="sudo apt-get dist-upgrade -y --force-yes"
SEARCH_PACKAGE="sudo apt-cache search"
WHAT_PROVIDES="sudo dpkg -S"
LIST_INSTALL_PACKAGES="sudo dpkg -l"
LIST_PACKAGES_CONTENT="sudo dpkg -L"
SHOW_PACKAGE_INFORMATION="sudo apt-cache show"
CLEAN_KERNEL="sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]- [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge; sudo dpkg -l | grep linux-image; sudo dpkg -l | grep linux-header"
CLEAN_CACHE="sudo apt-get autoclean -y; sudo apt-get autoremove -y; sudo apt-get clean; sudo rm -rf /var/cache/apt/*; ls /var/cache/apt/;"
ENABLE_SERVICE="sudo systemctl enable"
START_SERVICE="sudo systemctl start"
STATUS_SERVICE="sudo systemctl status"
LOG_SERVICE="sudo journalctl -xet"
STOP_SERVICE="sudo systemctl stop"
DISABLE_SERVICE="sudo systemctl disable"
LIST_SERVICE="sudo systemctl list-units --type=service --state=running"
OPEN="open" # xdg-open | open
;;
opensuse-leap | opensuse-tumbleweed | sles)
USER_BIN="/usr/bin"
USER_LOCAL_BIN="/usr/local/bin"
ETC="/etc"
# https://en.opensuse.org/images/1/17/Zypper-cheat-sheet-1.pdf
ADD_KEY="rpm --import" # /usr/lib/rpm/gnupg/keys/
ADD_REPO="sudo zypper addrepo" # --refresh" # /etc/zypp/repos.d/
REMOVE_REPO="sudo zypper removerepo" # /etc/zypp/repos.d/
REPO_UPDATE="sudo zypper refresh"
INSTALL_PACKAGE="sudo zypper --gpg-auto-import-keys --ignore-unknown --non-interactive install"
REINSTALL_PACKAGE=""
UNINSTALL_PACKAGE="sudo zypper --non-interactive remove"
DOWNLOAD_PACKAGE="sudo zypper --non-interactive install --auto-agree-with-licenses --no-gpg-checks --quiet -f --download-only"
UPGRADE_PACKAGE="sudo zypper update --no-confirm"
DIST_UPGRADE="sudo zypper dist-upgrade --no-confirm --auto-agree-with-licenses --replacefiles --force-resolution" # --quiet --gpg-auto-import-keys
SEARCH_PACKAGE="sudo zypper search --details"
WHAT_PROVIDES="sudo rpm -qf" # zypper search --provides --match-exact | sudo rpm -qf $(which ${*})
LIST_INSTALL_PACKAGES="sudo zypper search --installed-only --details"
LIST_PACKAGES_CONTENT="sudo rpm -ql"
SHOW_PACKAGE_INFORMATION="sudo zypper info"
CLEAN_KERNEL=""
CLEAN_CACHE="sudo zypper clean --all; sudo rm -rf /var/cache/zypp/*; ls /var/cache/zypp/;"
ENABLE_SERVICE="sudo systemctl enable"
START_SERVICE="sudo systemctl start"
STATUS_SERVICE="sudo systemctl status"
LOG_SERVICE="sudo journalctl -xet"
STOP_SERVICE="sudo systemctl stop"
DISABLE_SERVICE="sudo systemctl disable"
LIST_SERVICE="sudo systemctl list-units --type=service --state=running"
OPEN="open" # xdg-open | open
;;
macos | macosx)
USER_BIN="/usr/local/bin"
USER_LOCAL_BIN="/usr/local/bin"
ETC="/usr/local/etc"
# https://docs.brew.sh/Manpage
# https://devhints.io/homebrew
ADD_KEY=""
ADD_REPO=""
REMOVE_REPO=""
REPO_UPDATE="cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core; git stash; git clean -fdx; brew update; brew list;"
if [ "${CASK}" != "" ] && [ ${CASK} == true ]; then
INSTALL_PACKAGE="brew install --cask" # --force # --with-default-names
REINSTALL_PACKAGE=""
UNINSTALL_PACKAGE="brew uninstall --cask" # --ignore-dependencies --force
DOWNLOAD_PACKAGE="brew --cache"
UPGRADE_PACKAGE="brew outdated; brew upgrade; brew outdated --cask; brew upgrade --cask; brew doctor --verbose;"
DIST_UPGRADE="sudo softwareupdate --list; sudo softwareupdate --all --install --force; sudo xcode-select -p; sxcode-select -v; gcc --version;"
SEARCH_PACKAGE="brew search --cask" #
WHAT_PROVIDES=""
LIST_INSTALL_PACKAGES="brew list --cask" #
SHOW_PACKAGE_INFORMATION="brew info"
CLEAN_KERNEL=""
CLEAN_CACHE="brew cleanup -s; rm -rf $(brew --cache)/*; ls $(brew --cache);"
# CONFIG="brew --config"
# ENV="brew --env"
else
INSTALL_PACKAGE="brew install" # --cask --force # --with-default-names
REINSTALL_PACKAGE=""
UNINSTALL_PACKAGE="brew uninstall" # --cask --ignore-dependencies --force
DOWNLOAD_PACKAGE="brew --cache"
UPGRADE_PACKAGE="brew outdated; brew upgrade; brew outdated --cask; brew upgrade --cask; brew doctor --verbose;"
DIST_UPGRADE="sudo softwareupdate --list; sudo softwareupdate --all --install --force; sudo xcode-select -p; xcode-select -v; gcc --version;"
SEARCH_PACKAGE="brew search" # --cask
WHAT_PROVIDES=""
LIST_INSTALL_PACKAGES="brew list" # --cask
SHOW_PACKAGE_INFORMATION="brew info"
CLEAN_KERNEL=""
CLEAN_CACHE="brew cleanup -s; rm -rf $(brew --cache)/*; ls $(brew --cache);"
# CONFIG="brew --config"
# ENV="brew --env"
fi
ENABLE_SERVICE=""
START_SERVICE="brew services start"
STATUS_SERVICE="brew services list"
LOG_SERVICE=""
STOP_SERVICE="brew services stop"
DISABLE_SERVICE=""
LIST_SERVICE="brew services list"
OPEN="xdg-open" # xdg-open | open
;;
microsoft) ;;
*) ;;
esac
fi
}
function add_key_repo() {
if [ "$#" != "2" ] && [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} <PACKAGES_REPO_URL> <PACKAGES_REPO_NAME> [<PACKAGES_KEY_URL>]"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
# cd "${TOP_DIR:?}" || exit 1
case ${DISTRO} in
alpine) ;;
alma-linux | arch-linux | chromeos | coreos | gentoo | hyperiotos | oracle-linux | photonos | rocky-linux) ;;
centos | fedora | rhel | oracle-linux | alma-linux | rocky-linux)
if [ "${3}" != "" ]; then
sudo rpm --import ${3}
fi
if [ "${1}" != "" ] && [ "${2}" != "" ]; then
sudo curl -L "${1}" -o "/etc/yum.repos.d/${2}.repo"
# yum-config-manager --add-repo ${1}
fi
${INSTALL_PACKAGE} epel-release
;;
rancher-harvester | rancher-k3os | rancher-os) ;;
cirros) ;;
macos | macosx) ;;
debian | raspios | ubuntu)
if [ "${3}" != "" ]; then
curl -L "${3}" | sudo apt-key add -
fi
if [ "${1}" != "" ] && [ "${2}" != "" ]; then
sudo curl -L "${1}" -o "/etc/apt/sources.list.d/${2}.list"
fi
;;
opensuse-leap | opensuse-tumbleweed | sles)
if [ "${3}" != "" ]; then
sudo rpm --import ${3}
fi
if [ "${1}" != "" ] && [ "${2}" != "" ]; then
sudo curl -L "${1}" -o "/etc/zypp/repos.d/${2}.repo"
# sudo zypper addrepo --refresh ${1}
fi
;;
microsoft) ;;
*) ;;
esac
${REPO_UPDATE}
fi
}
function delete_key_repo() {
if [ "$#" != "2" ] && [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} <PACKAGES_REPO_URL> <PACKAGES_REPO_NAME> [<PACKAGES_KEY_URL>]"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
# cd "${TOP_DIR:?}" || exit 1
case ${DISTRO} in
alpine) ;;
alma-linux | arch-linux | chromeos | coreos | gentoo | hyperiotos | oracle-linux | photonos | rocky-linux) ;;
centos | fedora | rhel | oracle-linux | alma-linux | rocky-linux)
sudo rm -f "/etc/yum.repos.d/${2}.repo"
# PACKAGE_PROVIDER= # Microsoft
# KEY=$(rpm -qa gpg-pubkey /* --qf "%{version}-%{release} %{summary}\n" | grep ${PACKAGE_PROVIDER} | awk '{print $1}')
# sudo rpm -e --allmatches gpg-pubkey-${KEY}
;;
rancher-harvester | rancher-k3os | rancher-os) ;;
cirros) ;;
macos | macosx) ;;
debian | raspios | ubuntu)
sudo rm -f "/etc/apt/sources.list.d/${2}.list"
;;
opensuse-leap | opensuse-tumbleweed | sles)
sudo rm -f "/etc/zypp/repos.d/${2}.repo"
# PACKAGE_PROVIDER= # Microsoft
# KEY=$(rpm -qa gpg-pubkey /* --qf "%{version}-%{release} %{summary}\n" | grep ${PACKAGE_PROVIDER} | awk '{print $1}')
# sudo rpm -e --allmatches gpg-pubkey-${KEY}
;;
microsoft) ;;
*) ;;
esac
${REPO_UPDATE}
fi
}
#******************************************************************************
#******************************************************************************
# alpine
#******************************************************************************
# centos | fedora | rhel
#******************************************************************************
# debian | raspios | ubuntu
#******************************************************************************
# opensuse-leap | opensuse-tumbleweed | oracle-linux | sles
#******************************************************************************
# macosx
#******************************************************************************
#******************************************************************************
# create_project_skeleton
function create_project_skeleton() {
if [ "$#" != "0" ] && [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} <DISTRO> <PLATFORM> <PROJECT_TYPE> [<CREATE_OPENRC> <NEW_ROLE>]"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
mkdir -p "${TOP_DIR:?}"
cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "3" ]; then
local DISTRO=${1}
local PLATFORM=${2}
local PROJECT_TYPE=${3}
echo '#!/usr/bin/env bash' >"${TOP_DIR:?}/os-openrc-${DISTRO}.sh"
echo '#!/usr/bin/env bash' >"${TOP_DIR:?}/container-openrc-${PLATFORM}.sh"
echo '#!/usr/bin/env bash' >"${TOP_DIR:?}/container-openrc-${PROJECT_TYPE}.sh"
else
if [ "${CREATE_OPENRC}" != "" ] && [ ${CREATE_OPENRC} == true ]; then
for DISTRO in ${DISTROS[*]}; do
echo '#!/usr/bin/env bash' >"${TOP_DIR:?}/os-openrc-${DISTRO}.sh"
done
for PLATFORM in ${PLATFORMS[*]}; do
echo '#!/usr/bin/env bash' >"${TOP_DIR:?}/container-openrc-${PLATFORM}.sh"
done
fi
fi
case ${PROJECT_TYPE} in
ansible_app) ansible_create_app_project_skeleton ;;
bash_app) create_bash_app_project_skeleton "${NEW_ROLE}" ;;
bash_deployment_app) create_bash_deployment_app_project_skeleton ;;
bash_install_app) create_bash_install_app_project_skeleton ;;
bash_remote_deployment_app) create_bash_remote_deployment_app_project_skeleton ;;
docker_app) create_docker_app_project_skeleton ;;
podman_app) create_podman_app_project_skeleton ;;
helm3_app) create_helm3_app_project_skeleton ;;
deployment_app) create_deployment_app_project_skeleton ;;
terraform_app) create_terraform_app_project_skeleton ;;
golang_app) create_golang_app_project_skeleton ;;
typescript_app) create_typescript_app_project_skeleton ;;
python3_app) create_python3_app_project_skeleton ;;
rust_app) create_rust_app_project_skeleton ;;
*) ;;
esac
fi
}
function ansible_create_bootstrap() {
if [ "$#" != "0" ] && [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} <NEW_ROLE>"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "1" ]; then
local NEW_ROLE=${1}
elif [ "${NEW_ROLE}" == "" ]; then
local NEW_ROLE=others
fi
cat <<\*EOF* >"scripts/bootstrap_ansible.sh"
#!/usr/bin/env bash
# set -x
TOP_DIR=$(cd "$(dirname "${0}")" && pwd)
if [ -x "$(command -v apt-get)" ]; then
echo -e "\n>>> Prepare APT dependencies...\n"
apt-get update
apt-get install -y ca-certificates curl gcc iproute2 python3 python3-dev sudo
elif [ -x "$(command -v yum)" ]; then
echo -e "\n>>> Prepare YUM dependencies...\n"
yum makecache
yum install -y ca-certificates curl gcc iproute python3 python3-devel sudo
elif [ -x "$(command -v zypper)" ]; then
echo -e "\n>>> Prepare Zypper dependencies...\n"
zypper --non-interactive --gpg-auto-import-keys refresh
zypper --non-interactive install -y ca-certificates curl gcc iproute2 python3 python3-devel sudo
else
echo -e "\n>>> Prepare Zypper dependencies...\n"
fi
echo -e "\n>>> Install PIP...\n"
curl -skL https://bootstrap.pypa.io/get-pip.py | python3
echo -e "\n>>Install PIP dependencies...\n"
# pip3 install --upgrade --ignore-installed --requirement requirements.txt
pip3 install --upgrade --ignore-installed \
ansible>=2.9.5 \
ansible-lint \
ansible-runner \
ansible-runner-http \
argcomplete \
docker \
flake8 \
molecule>=3.0.2 \
netaddr \
openshift \
yamllint
*EOF*
chmod +x scripts/bootstrap_ansible.sh
fi
}
function ansible_create_inventories_for_platforms() {
if [ "$#" != "0" ] && [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} <NEW_ROLE>"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "1" ]; then
local NEW_ROLE=${1}
elif [ "${NEW_ROLE}" == "" ]; then
local NEW_ROLE=others
fi
# production staging mos ${PLATFORMS[*]}
# production staging mos libvirt
for INVENTORY in production staging mos libvirt; do
cat <<*EOF* >"inventories/${INVENTORY}/hosts"
[all]
# [all:vars]
# ansible_python_interpreter=/usr/bin/python3
[remotes_mos]
10.17.1.0
10.17.2.0
10.17.3.0
10.17.4.0
10.17.5.0
10.17.6.0
10.17.7.0
10.17.8.0
10.17.9.0
10.17.10.0
10.17.11.0
10.17.12.0
[remotes_mos:vars]
# ansible_connection=ssh
ansible_user=mos
ansible_linux=linux
ansible_ssh_private_key_file=~/.ssh/id_rsa
# ansible_python_interpreter=/usr/bin/python3
# ansible_become=yes
[remotes_env]
10.17.1.0
10.17.2.0
10.17.3.0
[remotes_env:vars]
# ansible_connection=ssh
# ansible_user=centos
ansible_ssh_private_key_file=~/.ssh/id_rsa
# ansible_python_interpreter=/usr/bin/python3
# ansible_become=yes
[local]
0.0.0.0
[loadbalancer]
10.17.1.0
[alpines]
10.17.2.0
[centos]
10.17.3.0
[debian]
10.17.4.0
[fedora]
10.17.5.0
[rancher-harvester]
10.17.6.0
[rancher-k3os]
10.17.7.0
[rancher-os]
10.17.8.0
[opensuse-leap]
10.17.9.0
[opensuse-tumbleweed]
10.17.10.0
[sles]
10.17.11.0
[ubuntu]
10.17.12.0
[centos-masters]
centos-master ansible_host=10.17.2.0
[centos-masters:vars]
# ansible_connection=ssh
ansible_user=centos
# ansible_linux=linux
ansible_ssh_private_key_file=~/.ssh/id_rsa
# ansible_python_interpreter=/usr/bin/python3
# ansible_become=yes
[centos-workers]
centos-worker1 ansible_host=10.17.3.0
centos-worker2 ansible_host=10.17.3.1
[centos-workers:vars]
# ansible_connection=ssh
ansible_user=centos
# ansible_linux=linux
ansible_ssh_private_key_file=~/.ssh/id_rsa
# ansible_python_interpreter=/usr/bin/python3
# ansible_become=yes
[ubuntu-masters]
ubuntu-master ansible_host=10.17.2.0
[ubuntu-masters:vars]
# ansible_connection=ssh
ansible_user=centos
# ansible_linux=linux
ansible_ssh_private_key_file=~/.ssh/id_rsa
# ansible_python_interpreter=/usr/bin/python3
# ansible_become=yes
[ubuntu-workers]
ubuntu-worker1 ansible_host=10.17.3.0
ubuntu-worker2 ansible_host=10.17.3.1
[ubuntu-workers:vars]
# ansible_connection=ssh
ansible_user=centos
# ansible_linux=linux
ansible_ssh_private_key_file=~/.ssh/id_rsa
# ansible_python_interpreter=/usr/bin/python3
# ansible_become=yes
*EOF*
done
fi
}
function ansible_get_config() {
if [ "$#" != "0" ] && [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} <NEW_ROLE>"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "1" ]; then
local NEW_ROLE=${1}
elif [ "${NEW_ROLE}" == "" ]; then
local NEW_ROLE=others
fi
curl -L https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg -o ansible.cfg
sed -i "s/#host_key_checking = True/host_key_checking = False/g" ansible.cfg
sed -i 's/#ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s/ssh_args = -o ControlMaster=auto -o ControlPersist=60s/g' ansible.cfg
sed -i "s/#timeout = 10/#timeout = 15/g" ansible.cfg
fi
}
function ansible_create_playbooks_for_hello_world() {
if [ "$#" != "0" ] && [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} <NEW_ROLE>"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "1" ]; then
local NEW_ROLE=${1}
elif [ "${NEW_ROLE}" == "" ]; then
local NEW_ROLE=others
fi
cat <<\*EOF* >"playbooks/hello_world.yml"
---
- name: Hello World!
hosts: "{{ hosts | default('remotes') }}"
vars:
who: "world"
tasks:
- name: Hello World!
shell: echo "Hello, {{ who }}!"
- name: output a message
debug: msg="Hello, {{ who }}!"
*EOF*
fi
}
function ansible_create_playbooks_for_hello_role() {
if [ "$#" != "0" ] && [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} <NEW_ROLE>"
log_e "${FUNCNAME[0]} $# ${*}"
else
log_m "${FUNCNAME[0]} $# ${*}"
cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "1" ]; then
local NEW_ROLE=${1}
elif [ "${NEW_ROLE}" == "" ]; then
local NEW_ROLE=others
fi
cat <<\*EOF* >"playbooks/hello_role.yml"
---
- hosts: "{{ hosts | default('remotes') }}"
remote_user: mos
become: true
roles:
- role: roles/helloworld