Functions.core.sh 3.34 KB
Newer Older
据说甜蜜呢 committed
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash

set -e

function ToLower()
{
   declare input=$1
   declare output=($(echo "${input}" | tr 'A-Z' 'a-z'))
   eval $2=${output}
}

据说甜蜜呢 committed
12 13 14 15 16 17 18 19 20
function Replace()
{
  declare input=$1
  declare sourceExpr=$2
  declare targetExpr=$3
  declare output=${input//${sourceExpr}/${targetExpr}}
  eval $4=${output}
}

21 22 23 24
# function GetServices()
# {
#	
# }
据说甜蜜呢 committed
25 26 27 28 29 30 31 32 33

function GetServiceCsProjFile()
{
    declare prefix=${1}
	declare name=${2}
	declare csprojFile="./src/Services/${prefix}/${name}/${name}.csproj"
	eval $3="${csprojFile}"
}

据说甜蜜呢 committed
34 35 36 37 38 39 40 41
function GetServiceDir()
{
    declare prefix=${1}
	declare name=${2}
	declare dir="./src/Services/${prefix}/${name}"
	eval $3="${dir}"
}

据说甜蜜呢 committed
42 43 44 45 46 47 48 49 50 51 52 53 54
function GetServiceName()
{
    declare prefix=${1}
	declare name=($(ls ./src/Services/${prefix}|head -n 1|xargs -d '/' echo))
	eval $2="${name}"
}

function GetAppName()
{
    declare name=($(grep -oP '(?<=AppName>)[^<]+' "./devops/app.props"))
	eval $1="${name}"
}

据说甜蜜呢 committed
55 56 57
function GetNameSpace()
{
    GetMajor major
58
	declare ns=($(grep -oP '(?<=NameSpace>)[^<]+' "./devops/app.props"))
59
	ToLower "${ns}-v${major}" nsOfK8s
60
	eval $1=${nsOfK8s}
据说甜蜜呢 committed
61 62
}

据说甜蜜呢 committed
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
function GetSolutionName()
{
    declare name=($(grep -oP '(?<=SolutionName>)[^<]+' "./devops/app.props"))
	eval $1="${name}"
}

function GetImageUserName()
{
    declare name=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
	eval $1="${name}"
}

function GetCiCdSettings()
{
    declare all=($(grep -oP '(?<=AllPublishable>)[^<]+' "/tmp/cicd.props"))
    declare no=($(grep -oP '(?<=NoPublishable>)[^<]+' "/tmp/cicd.props"))
	eval $1=${all}
	eval $2=${no}
}

function GetMajor()
{
    declare m=($(grep -oP '(?<=Major>)[^<]+' "./devops/version.props"))
	eval $1=${m}
}

function GetVersion()
{
    declare major=($(grep -oP '(?<=Major>)[^<]+' "./devops/version.props"))
	declare minor=($(grep -oP '(?<=Minor>)[^<]+' "./devops/version.props"))
	declare patch=($(grep -oP '(?<=Patch>)[^<]+' "./devops/version.props"))
	eval $1="${major}.${minor}.${patch}"
}

function GetImageRegistrySettings()
{
    declare host=($(grep -oP '(?<=ImageRegistryHost>)[^<]+' "devops/deploy.props"))
    declare username=($(grep -oP '(?<=ImageUserName>)[^<]+' "devops/deploy.props"))
	eval $1=${host}
	eval $2=${username}
}

105 106 107 108 109 110
function GetReplicas()
{
    declare count=($(grep -oP '(?<=Replicas>)[^<]+' "devops/deploy.props"))
	eval $1=${count}
}

111
function GetAccessToken()
据说甜蜜呢 committed
112
{
113 114
    ToLower ${Environment} environment
    declare token=($(grep -oP "(?<=AccessToken>)[^<]+" "devops/deploy.${environment}.props"))
据说甜蜜呢 committed
115 116 117
	eval $1="${token}"
}

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
function GetRegistryHost()
{
    ToLower ${Environment} environment
    declare host=($(grep -oP "(?<=RegistryHost>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${host}"
}

function GetK8sApiServer()
{
    ToLower ${Environment} environment
    declare host=($(grep -oP "(?<=K8sApiServer>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${host}"
}

function GetKongApiServer()
{
    ToLower ${Environment} environment
    declare host=($(grep -oP "(?<=KongApiServer>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${host}"
}

function GetKongRouteDomain()
{
    ToLower ${Environment} environment
    declare domain=($(grep -oP "(?<=KongRouteDomain>)[^<]+" "devops/deploy.${environment}.props"))
	eval $1="${domain}"
}

据说甜蜜呢 committed
146 147 148 149 150 151
function IsPublishableOf()
{
    declare prefix=$0
    declare isP=($(grep -oP "(?<=${prefix}Publishable>)[^<]+" "/tmp/cicd.props"))
	eval $1=isP
}