deploy-tools/src/cs_to_nm.sh
Sahil Ahuja ec70398266 WIP
2025-02-05 19:56:35 +05:30

75 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Updates the nm repo's cs version
### Functions
usage()
{
echo "usage: $0 [-n nm-repo -c cs-repo -v version] | [-h]"
}
main()
{
local NM_REPO_NAME=$1
local CS_REPO_NAME=$2
local VERSION=$3
rm -rf nm-repo
git clone https://git.gmetri.io/gmetrivr/$NM_REPO_NAME.git nm-repo
cd nm-repo
#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_PATH="./c/cslist.txt"
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 "$NM_REPO_NAME updated with $CS_REPO_NAME: $VERSION"
git push origin master
}
### Starts here
while [ "$1" != "" ]; do
case $1 in
-n | --nm-repo ) shift
NM_REPO_NAME=$1
;;
-c | --cs-repo ) shift
CS_REPO_NAME=$1
;;
-v | --version ) shift
VERSION=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [[ -z $NM_REPO_NAME || -z $CS_REPO_NAME || -z $VERSION ]]
then
echo "Not enough arguments"
usage
exit
fi
main "$NM_REPO_NAME" "$CS_REPO_NAME" "$VERSION"