Bash Flags are not passing through

I need help with this bash script please. For some reason, my flags are not being passed through. I’m using the unix getopts function,

Could someone take a look and let me know where I am going wrong?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/bin/bash
### Pass Flags
#Define the help function
function help(){
echo "Options:";
echo "-rg Resource Group Name"
echo "-loc Location of Resource Group"
echo "-clus Cluster Name"
echo "-e Email for LetsEncrypt"
echo "-hos Hostname for Nginx"
exit 1;
}
#Initialize the default values for the variables.
rg="rg";
loc="location";
clus="cluster";
e="email";
hos="hostname";
#Define the getopts variables
options="rg:loc:clus:e:hos:h";
#Start the getopts code
while getopts $options opt; do
case $opt in
rg) #Get the username
rg=$OPTARG
;;
loc) #Get the password
location=$OPTARG
;;
clus) #Get the repository name
cluster=$OPTARG
;;
e) #Get the service name
email=$OPTARG
;;
hos) #Get the branch name
hostname=$OPTARG
;;
h) #Execute the help function
"echo here"
help;
;;
?) #unrecognized option - show help
echo "Invalid option."
help;
;;
esac
done
#This tells getopts to move on to the next argument.
shift $((OPTIND-1))
#End getopts code
#rg="jc-test29-aks-rg"
#location="francecentral"
#cluster="jc-aks-test29-cluster"
## Create RG
echo "Creating Resource Group $rg"
az group create --name $rg --location $location
## Create AKS Cluster
echo "Creating AKS Cluster $cluster"
az aks create -g $rg -n $cluster --enable-managed-identity --node-vm-size Standard_B2s --node-count 3 --load-balancer-sku Standard
## Conect to Cluster
echo "Connecting to AKS Cluster"
az aks get-credentials --resource-group $rg --name $cluster --overwrite-existing
## Wait for the Cluster to Come online.
sleep 5m
## Add the Repos
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo add cert-manager https://charts.jetstack.io
helm repo add argo https://argoproj.github.io/argo-helm
## Install nginx-ingress
helm install nginx-ingress ingress-nginx/ingress-nginx
--namespace ingress-nginx --create-namespace
--set controller.replicaCount=2
--set controller.admissionWebhooks.patch.nodeSelector."kubernetes.io/os"=linux
--set controller.service.annotations."service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path"=/healthz
--set controller.service.externalTrafficPolicy=Local
--set controller.nodeSelector."kubernetes.io/os"=linux
--set defaultBackend.nodeSelector."kubernetes.io/os"=linux
## Install Cert Manager
helm install cert-manager cert-manager/cert-manager
--namespace cert-manager --create-namespace
--version v1.14.5
--set nodeSelector."kubernetes.io/os"=linux
--set installCRDs=true
--set 'extraArgs={--dns01-recursive-nameservers=1.1.1.1:53}'
## Install ArgoCD
helm install argocd argo/argo-cd
--namespace argocd --create-namespace
--version "6.9.2"
--set installCRDs=true
-f argocd-values.yaml
-f deployenvcongifmap.yaml
cat << EOF | kubectl -
port-forward svc/argocd-server 8080:443
EOF
#git clone https://github.com/cloudflare/origin-ca-issuer.git
cd origin-ca-issuer
kubectl apply -f deploy/crds
kubectl apply -f deploy/rbac
kubectl apply -f deploy/manifests
kubectl create secret generic jasons-api-key
-n cert-manager
--from-literal api-token='VALUE'
sleep 60
cat << EOF | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: lets-encrypt-jasons-cert
namespace: cert-manager
spec:
acme:
email: $email
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
# Secret resource that will be used to store the account's private key.
name: lets-encrypt-jasons-cert
solvers:
- dns01:
cloudflare:
email: $email
apiTokenSecretRef:
name: jasons-api-key
key: api-token
selector:
dnsZones:
- 'companydomain.com'
EOF
cat << EOF | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: letsencrypt-jasons-cert
spec:
secretName: letsencrypt-jasons-cert
issuerRef:
name: lets-encrypt-jasons-cert
kind: ClusterIssuer
commonName: 'testing-jc2.companydomain.com'
dnsNames:
- 'testing-jc2.companydoamin.com'
EOF
cat << EOF | kubectl replace -f -
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: argocd-server
app.kubernetes.io/part-of: argocd
name: argocd-server
namespace: argocd
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
- name: https
port: 443
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/name: argocd-server
EOF
cat << EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd-server-ingress
namespace: argocd
annotations:
cert-manager.io/cluster-issuer: lets-encrypt-jasons-cert
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: 'true'
nginx.ingress.kubernetes.io/ssl-passthrough: 'true'
nginx.ingress.kubernetes.io/backend-protocol: 'HTTPS'
spec:
rules:
- host: $hostname
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-server
port:
name: https
tls:
- hosts:
- $hostname
secretName: argocdingress-cert
EOF
echo "Deployment Complete"
</code>
<code>#!/bin/bash ### Pass Flags #Define the help function function help(){ echo "Options:"; echo "-rg Resource Group Name" echo "-loc Location of Resource Group" echo "-clus Cluster Name" echo "-e Email for LetsEncrypt" echo "-hos Hostname for Nginx" exit 1; } #Initialize the default values for the variables. rg="rg"; loc="location"; clus="cluster"; e="email"; hos="hostname"; #Define the getopts variables options="rg:loc:clus:e:hos:h"; #Start the getopts code while getopts $options opt; do case $opt in rg) #Get the username rg=$OPTARG ;; loc) #Get the password location=$OPTARG ;; clus) #Get the repository name cluster=$OPTARG ;; e) #Get the service name email=$OPTARG ;; hos) #Get the branch name hostname=$OPTARG ;; h) #Execute the help function "echo here" help; ;; ?) #unrecognized option - show help echo "Invalid option." help; ;; esac done #This tells getopts to move on to the next argument. shift $((OPTIND-1)) #End getopts code #rg="jc-test29-aks-rg" #location="francecentral" #cluster="jc-aks-test29-cluster" ## Create RG echo "Creating Resource Group $rg" az group create --name $rg --location $location ## Create AKS Cluster echo "Creating AKS Cluster $cluster" az aks create -g $rg -n $cluster --enable-managed-identity --node-vm-size Standard_B2s --node-count 3 --load-balancer-sku Standard ## Conect to Cluster echo "Connecting to AKS Cluster" az aks get-credentials --resource-group $rg --name $cluster --overwrite-existing ## Wait for the Cluster to Come online. sleep 5m ## Add the Repos helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo add cert-manager https://charts.jetstack.io helm repo add argo https://argoproj.github.io/argo-helm ## Install nginx-ingress helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace --set controller.replicaCount=2 --set controller.admissionWebhooks.patch.nodeSelector."kubernetes.io/os"=linux --set controller.service.annotations."service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path"=/healthz --set controller.service.externalTrafficPolicy=Local --set controller.nodeSelector."kubernetes.io/os"=linux --set defaultBackend.nodeSelector."kubernetes.io/os"=linux ## Install Cert Manager helm install cert-manager cert-manager/cert-manager --namespace cert-manager --create-namespace --version v1.14.5 --set nodeSelector."kubernetes.io/os"=linux --set installCRDs=true --set 'extraArgs={--dns01-recursive-nameservers=1.1.1.1:53}' ## Install ArgoCD helm install argocd argo/argo-cd --namespace argocd --create-namespace --version "6.9.2" --set installCRDs=true -f argocd-values.yaml -f deployenvcongifmap.yaml cat << EOF | kubectl - port-forward svc/argocd-server 8080:443 EOF #git clone https://github.com/cloudflare/origin-ca-issuer.git cd origin-ca-issuer kubectl apply -f deploy/crds kubectl apply -f deploy/rbac kubectl apply -f deploy/manifests kubectl create secret generic jasons-api-key -n cert-manager --from-literal api-token='VALUE' sleep 60 cat << EOF | kubectl apply -f - apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata: name: lets-encrypt-jasons-cert namespace: cert-manager spec: acme: email: $email server: https://acme-v02.api.letsencrypt.org/directory privateKeySecretRef: # Secret resource that will be used to store the account's private key. name: lets-encrypt-jasons-cert solvers: - dns01: cloudflare: email: $email apiTokenSecretRef: name: jasons-api-key key: api-token selector: dnsZones: - 'companydomain.com' EOF cat << EOF | kubectl apply -f - apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: letsencrypt-jasons-cert spec: secretName: letsencrypt-jasons-cert issuerRef: name: lets-encrypt-jasons-cert kind: ClusterIssuer commonName: 'testing-jc2.companydomain.com' dnsNames: - 'testing-jc2.companydoamin.com' EOF cat << EOF | kubectl replace -f - apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/component: server app.kubernetes.io/name: argocd-server app.kubernetes.io/part-of: argocd name: argocd-server namespace: argocd spec: ports: - name: http port: 80 protocol: TCP targetPort: 8080 - name: https port: 443 protocol: TCP targetPort: 8080 selector: app.kubernetes.io/name: argocd-server EOF cat << EOF | kubectl apply -f - apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: argocd-server-ingress namespace: argocd annotations: cert-manager.io/cluster-issuer: lets-encrypt-jasons-cert kubernetes.io/ingress.class: nginx kubernetes.io/tls-acme: 'true' nginx.ingress.kubernetes.io/ssl-passthrough: 'true' nginx.ingress.kubernetes.io/backend-protocol: 'HTTPS' spec: rules: - host: $hostname http: paths: - path: / pathType: Prefix backend: service: name: argocd-server port: name: https tls: - hosts: - $hostname secretName: argocdingress-cert EOF echo "Deployment Complete" </code>
#!/bin/bash
### Pass Flags
#Define the help function
function help(){
    echo "Options:";
    echo "-rg    Resource Group Name"
    echo "-loc    Location of Resource Group"
    echo "-clus    Cluster Name"
    echo "-e    Email for LetsEncrypt"
    echo "-hos    Hostname for Nginx"
    exit 1;
}


#Initialize the default values for the variables.
rg="rg";
loc="location";
clus="cluster";
e="email";
hos="hostname";

#Define the getopts variables
options="rg:loc:clus:e:hos:h";

#Start the getopts code
while getopts $options opt; do
    case $opt in
            rg) #Get the username
                    rg=$OPTARG
            ;;
            loc) #Get the password
                    location=$OPTARG
            ;;
            clus) #Get the repository name
                    cluster=$OPTARG
            ;;
            e) #Get the service name
                    email=$OPTARG
            ;;
            hos) #Get the branch name
                    hostname=$OPTARG
            ;;
            h) #Execute the help function
        "echo here"
                    help;
            ;;
            ?) #unrecognized option - show help
                    echo "Invalid option."
                    help;
            ;;
    esac
done

#This tells getopts to move on to the next argument.
shift $((OPTIND-1))
#End getopts code


#rg="jc-test29-aks-rg"
#location="francecentral"
#cluster="jc-aks-test29-cluster"

## Create RG
echo "Creating Resource Group $rg"
az group create --name $rg --location $location

## Create AKS Cluster
echo "Creating AKS Cluster $cluster"

az aks create -g $rg -n $cluster --enable-managed-identity --node-vm-size Standard_B2s --node-count 3 --load-balancer-sku Standard

## Conect to Cluster
echo "Connecting to AKS Cluster"
az aks get-credentials --resource-group $rg --name $cluster --overwrite-existing

## Wait for the Cluster to Come online.
sleep 5m

## Add the Repos
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo add cert-manager https://charts.jetstack.io
helm repo add argo https://argoproj.github.io/argo-helm

## Install nginx-ingress
helm install nginx-ingress ingress-nginx/ingress-nginx 
--namespace ingress-nginx --create-namespace 
--set controller.replicaCount=2 
--set controller.admissionWebhooks.patch.nodeSelector."kubernetes.io/os"=linux 
--set controller.service.annotations."service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path"=/healthz 
--set controller.service.externalTrafficPolicy=Local 
--set controller.nodeSelector."kubernetes.io/os"=linux 
--set defaultBackend.nodeSelector."kubernetes.io/os"=linux

## Install Cert Manager
helm install cert-manager cert-manager/cert-manager 
--namespace cert-manager --create-namespace 
--version v1.14.5 
--set nodeSelector."kubernetes.io/os"=linux 
--set installCRDs=true 
--set 'extraArgs={--dns01-recursive-nameservers=1.1.1.1:53}'

## Install ArgoCD 
helm install argocd argo/argo-cd 
--namespace argocd --create-namespace 
--version "6.9.2" 
--set installCRDs=true 
-f argocd-values.yaml 
-f deployenvcongifmap.yaml

cat << EOF | kubectl - 
port-forward svc/argocd-server 8080:443 
EOF

#git clone https://github.com/cloudflare/origin-ca-issuer.git

cd origin-ca-issuer

kubectl apply -f deploy/crds

kubectl apply -f deploy/rbac

kubectl apply -f deploy/manifests


kubectl create secret generic jasons-api-key 
    -n cert-manager
    --from-literal api-token='VALUE'

sleep 60

cat  << EOF | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: lets-encrypt-jasons-cert
  namespace: cert-manager
spec:
  acme:
    email: $email
    server: https://acme-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      # Secret resource that will be used to store the account's private key.
      name: lets-encrypt-jasons-cert
    solvers:
    - dns01:
        cloudflare:
          email: $email
          apiTokenSecretRef:
            name: jasons-api-key
            key: api-token
      selector:
        dnsZones:
        - 'companydomain.com'
EOF

cat << EOF | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: letsencrypt-jasons-cert
spec:
  secretName: letsencrypt-jasons-cert
  issuerRef:
    name: lets-encrypt-jasons-cert
    kind: ClusterIssuer
  commonName: 'testing-jc2.companydomain.com'
  dnsNames:
  - 'testing-jc2.companydoamin.com'
EOF


cat << EOF | kubectl replace -f -
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: server
    app.kubernetes.io/name: argocd-server
    app.kubernetes.io/part-of: argocd
  name: argocd-server
  namespace: argocd
spec:
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 8080
    - name: https
      port: 443
      protocol: TCP
      targetPort: 8080
  selector:
    app.kubernetes.io/name: argocd-server
EOF

cat << EOF | kubectl apply -f - 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd-server-ingress
  namespace: argocd
  annotations:
    cert-manager.io/cluster-issuer: lets-encrypt-jasons-cert
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: 'true'
    nginx.ingress.kubernetes.io/ssl-passthrough: 'true'
    nginx.ingress.kubernetes.io/backend-protocol: 'HTTPS'
spec:
  rules:
    - host: $hostname
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: argocd-server
                port:
                  name: https
  tls:
    - hosts:
        - $hostname
      secretName: argocdingress-cert
EOF

echo "Deployment Complete"

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật