<commit_before>#!/bin/bash

PEER_NAME=peer0.scray.org
BASE_PATH=$PWD

createEnvForNewConf() {
  mkdir -p target/$PEER_NAME
  cp k8s-peer.yaml ./target/$PEER_NAME
  cp k8s-peer-service.yaml ./target/$PEER_NAME
  cp configure-deployment.sh ./target/$PEER_NAME/
  cd ./target/$PEER_NAME/
}

yq() {
  $BASE_PATH/bin/yq $1 $2 $3 $4 $5
}

# Check if yq exists
checkYqVersion() {
  dowloadYqBin
}

dowloadYqBin() {
  if [[ ! -f "./bin/yq" ]]
  then
    echo "yq does not exists"
    echo "download linux_amd64 yq binary"
    
    mkdir bin
    curl -L https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -o ./bin/yq
    chmod u+x ./bin/yq
  fi
}

setValuesInLocalFile() {
  yq w -i k8s-peer.yaml "metadata.name" $PEER_NAME
  yq w -i k8s-peer.yaml "metadata.labels.app" $PEER_NAME 
  yq w -i k8s-peer.yaml "spec.selector.matchLabels.app" $PEER_NAME 
  yq w -i k8s-peer.yaml "spec.template.metadata.labels.app" $PEER_NAME
  yq w -i k8s-peer.yaml "spec.template.spec.containers(name==peer0-org1-scray-org).name" $PEER_NAME

  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_ID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_ADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_CHAINCODEADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_GOSSIP_BOOTSTRAP).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_GOSSIP_EXTERNALENDPOINT).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_LOCALMSPID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 



  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_ID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_ADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_CHAINCODEADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_GOSSIP_BOOTSTRAP).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_GOSSIP_EXTERNALENDPOINT).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_LOCALMSPID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME

  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==HOSTNAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==ORG_NAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME

  yq w  -i k8s-peer.yaml "spec.template.spec.initContainers(name==cert-creator).env(name==HOSTNAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.initContainers(name==cert-creator).env(name==ORG_NAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME


  # Configure service
  yq w -i k8s-peer-service.yaml 'metadata.name' $PEER_NAME 
  yq w -i k8s-peer-service.yaml 'metadata.labels.run' $PEER_NAME 
  yq w -i k8s-peer-service.yaml 'spec.selector.app' $PEER_NAME 
}


usage()
{
    echo "usage: Create peer K8s configuration [[[-n ] [-i]] | [-h]]"
}


while [ "$1" != "" ]; do
    case $1 in
        -n | --name )   shift
				PEER_NAME=$1
				checkYqVersion
				createEnvForNewConf
				setValuesInLocalFile
                                ;;
        -i | --inplace )   	shift
	       			PEER_NAME=$1
				checkYqVersion
				setValuesInLocalFile
                                ;;
        -h | --help )           usage
                                exit
                                ;;
	-c| --check )		checkYqVersion
				;;
        * )                     usage
                                exit 1
    esac
    shift
done
<commit_msg>Fix configmap name for data share<commit_after>#!/bin/bash

PEER_NAME=peer0.scray.org
BASE_PATH=$PWD

createEnvForNewConf() {
  mkdir -p target/$PEER_NAME
  cp k8s-peer.yaml ./target/$PEER_NAME
  cp k8s-peer-service.yaml ./target/$PEER_NAME
  cp configure-deployment.sh ./target/$PEER_NAME/
  cd ./target/$PEER_NAME/
}

yq() {
  $BASE_PATH/bin/yq $1 $2 $3 $4 $5
}

# Check if yq exists
checkYqVersion() {
  dowloadYqBin
}

dowloadYqBin() {
  if [[ ! -f "./bin/yq" ]]
  then
    echo "yq does not exists"
    echo "download linux_amd64 yq binary"
    
    mkdir bin
    curl -L https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -o ./bin/yq
    chmod u+x ./bin/yq
  fi
}

setValuesInLocalFile() {
  yq w -i k8s-peer.yaml "metadata.name" $PEER_NAME
  yq w -i k8s-peer.yaml "metadata.labels.app" $PEER_NAME 
  yq w -i k8s-peer.yaml "spec.selector.matchLabels.app" $PEER_NAME 
  yq w -i k8s-peer.yaml "spec.template.metadata.labels.app" $PEER_NAME
  yq w -i k8s-peer.yaml "spec.template.spec.containers(name==peer0-org1-scray-org).name" $PEER_NAME

  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_ID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_ADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_CHAINCODEADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_GOSSIP_BOOTSTRAP).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_GOSSIP_EXTERNALENDPOINT).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==$PEER_NAME).env(name==CORE_PEER_LOCALMSPID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME 



  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_ID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_ADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_CHAINCODEADDRESS).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_GOSSIP_BOOTSTRAP).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_GOSSIP_EXTERNALENDPOINT).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==CORE_PEER_LOCALMSPID).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME

  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==HOSTNAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.containers(name==scray-peer-cli).env(name==ORG_NAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME

  yq w  -i k8s-peer.yaml "spec.template.spec.initContainers(name==cert-creator).env(name==HOSTNAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.initContainers(name==cert-creator).env(name==ORG_NAME).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME
  yq w  -i k8s-peer.yaml "spec.template.spec.initContainers(name==cert-creator).env(name==DATA_SHARE).valueFrom.configMapKeyRef.name" hl-fabric-peer-$PEER_NAME


  # Configure service
  yq w -i k8s-peer-service.yaml 'metadata.name' $PEER_NAME 
  yq w -i k8s-peer-service.yaml 'metadata.labels.run' $PEER_NAME 
  yq w -i k8s-peer-service.yaml 'spec.selector.app' $PEER_NAME 
}


usage()
{
    echo "usage: Create peer K8s configuration [[[-n ] [-i]] | [-h]]"
}


while [ "$1" != "" ]; do
    case $1 in
        -n | --name )   shift
				PEER_NAME=$1
				checkYqVersion
				createEnvForNewConf
				setValuesInLocalFile
                                ;;
        -i | --inplace )   	shift
	       			PEER_NAME=$1
				checkYqVersion
				setValuesInLocalFile
                                ;;
        -h | --help )           usage
                                exit
                                ;;
	-c| --check )		checkYqVersion
				;;
        * )                     usage
                                exit 1
    esac
    shift
done

{'fraction_non_alphanumeric': 0.14330051369863014, 'fraction_numerical': 0.010166952054794521, 'mean_word_length': 3.3976470588235292, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6001284', 'n_tokens_mistral': 3837, 'n_tokens_neox': 3683, 'n_words': 503}