#!/bin/bash # Updates the nm repo's cs version ### Functions usage() { echo "usage: $0 [-c cs-repo -v version -k kustomization_list] | [-h]" } main() { local CS_REPO_NAME=$1 local VERSION=$2 local CSLIST_PATH=$3 #"./.github/cslist.txt" #Get list of repos from cslist.txt # Example lines in file: #cs-brx mat81-dev/brx/brx-2jitsi/kustomization.yaml cs-brx.git\/\/brx\/brx-2jitsi?ref= #cs-brx mat81-dev/brx/brx-3main/kustomization.yaml cs-brx.git\/\/brx\/brx-3main?ref= CSLIST=$(cat $CSLIST_PATH | grep ^$CS_REPO_NAME | tr -s " " | awk -v FS=' ' -v OFS='\t' '/^[^#]/' ) echo "$CSLIST" #doublequote preserves the shape of the input variable, including endlines if [ -z "$CSLIST" ] then echo "Nothing to update"; exit; fi #If we use a for loop, it iterates over spaces too instead of just endlines while IFS= read -r CSLIST_LINE; do KUST_PATH=$(echo $CSLIST_LINE | tr -s " " | cut -d " " -f 2) SEARCH_STRING=$(echo $CSLIST_LINE | tr -s " " | cut -d " " -f 3) #Replace repo version in kustomization.yaml echo sed -i -e "s/${SEARCH_STRING}.*/${SEARCH_STRING}${VERSION}/" $KUST_PATH sed -i -e "s/${SEARCH_STRING}.*/${SEARCH_STRING}${VERSION}/" $KUST_PATH git add $KUST_PATH done <<< "$CSLIST" git commit -m "$CS_REPO_NAME updated to $VERSION" } ### Starts here while [ "$1" != "" ]; do case $1 in -c | --cs-repo ) shift CS_REPO_NAME=$1 ;; -v | --version ) shift VERSION=$1 ;; -k | --kustomization_list ) shift CSLIST_PATH=$1 ;; -h | --help ) usage exit ;; * ) usage exit 1 esac shift done if [[ -z $CS_REPO_NAME || -z $VERSION || -z $CSLIST_PATH ]] then echo "Not enough arguments" usage exit fi main "$CS_REPO_NAME" "$VERSION" "$CSLIST_PATH"