Shell常用小方法

#去除換行 和 空格
function trimWhiteSpaceAndNewLine() {
    TEXT=$1
    #先替換空格
    result=`echo ${TEXT//' '/''}`
    #在替換換行
    echo ${result//'\n'/''}
}


# 大寫轉(zhuǎn)小寫
function toLowerString(){
    lower_str=$(echo ${1} | tr '[A-Z]' '[a-z]')
    echo ${lower_str}
}

#小寫轉(zhuǎn)大寫
function toUperString(){
    upper_str=$(echo ${1} | tr '[a-z]' '[A-Z]')
    echo ${upper_str}
}

# 是否包含字符串  忽略大小寫
function containStrIgoreLower(){
#大寫轉(zhuǎn)小寫
lower_str=$(toLowerString $2)
#判斷是否包含adhoc
grepResult=$(echo $1 | grep "${lower_str}")
if [[ "$grepResult" != "" ]]
then
    echo "1"
    # return 1
else
    echo "0"
    # return 0
fi
}


##json解析函數(shù)
function jsonParse() { # $1 $2  json lable
     JSON_CONTENT=$1
     KEY='"'$2'":'
     echo ${JSON_CONTENT} | awk -F  ${KEY}  '{print $2}' | awk -F '"' '{print $2}'
}







#下面是一個(gè)iOS腳本打包上傳蒲公英的自動(dòng)化腳本
#使用方法
if [ ! -d ./IPADir ];
then
mkdir -p IPADir;
fi

#工程絕對(duì)路徑
project_path=/Users/liubin/Desktop/svn/landlord
echo "環(huán)境:"
read envir_desc
echo "更新內(nèi)容:"
read update_desc

# 反引號(hào) 命令替換
branch=`cat $project_path/.git/HEAD` 
     # 分支名
     sub_branch=${branch: 16}
     # 打印
     echo "$sub_branch "

# filelist=`ls $dir_path`
# for file in $filelist
# do
#     echo "$file"
#  # 檢查目錄和git目錄是否存在
#  if [[ -d $file ]]; then
#     echo "111  $file"
#      branch=`cat $dir_path/.git/.git/HEAD`
#      # 分支名
#      sub_branch=${branch: 16}
#      # 打印
#      echo "$sub_branch    $file"
#  fi
# done

#去除換行  和  空格
function trimWhiteSpaceAndNewLine() {
    TEXT=$1
    #先替換空格
    result=`echo ${TEXT//' '/''}`
    #在替換換行
    echo ${result//'\n'/''}
}


# 大寫轉(zhuǎn)小寫
function toLowerString(){
    lower_str=$(echo ${1} | tr '[A-Z]' '[a-z]')
    echo ${lower_str}
}

#小寫轉(zhuǎn)大寫
function toUperString(){
    upper_str=$(echo ${1} | tr '[a-z]' '[A-Z]')
    echo ${upper_str}
}

# 是否包含字符串  忽略大小寫
function containStrIgoreLower(){
#大寫轉(zhuǎn)小寫
lower_str=$(toLowerString $2)
#判斷是否包含adhoc
grepResult=$(echo $1 | grep "${lower_str}")
if [[ "$grepResult" != "" ]]
then
    echo "1"
    # return 1
else
    echo "0"
    # return 0
fi

}



#工程名
project_name=Baletoo_landlord
#scheme名
scheme_name=Baletoo_landlord
product_name=Baletoo_landlord

#打包模式 Debug/Release
development_mode=Debug

#蒲公英參數(shù)
user_key=******
api_key=******

current_path=$(cd `dirname $0`; pwd)

#build文件夾路徑
build_path=${current_path}/build

#plist文件所在路徑
exportOptionsPlistPath=${current_path}/exportDebug.plist

isAdHocPackage=$(containStrIgoreLower "adhoc" "${envir_desc}")
isReleasePackage=$(containStrIgoreLower "release" "${envir_desc}")
if [[ $isAdHocPackage == 1 ]]; then
    development_mode=Release
#elif 后面也要跟then
elif [[ isReleasePackage == 1 ]]; then
    exportOptionsPlistPath=Release
    development_mode=Release
else
    exportOptionsPlistPath=Debug
fi
#導(dǎo)出.ipa文件所在路徑
exportIpaPath=${current_path}/IPADir/${development_mode}




##json解析函數(shù)
function jsonParse() { # $1 $2  json lable

     JSON_CONTENT=$1
     KEY='"'$2'":'

     echo ${JSON_CONTENT} | awk -F  ${KEY}  '{print $2}' | awk -F '"' '{print $2}'
}

##刪除斜杠'\'
function trimSlash() {
    TEXT=$1
    echo ${TEXT//'\'/''}
}


echo "第一步,進(jìn)入項(xiàng)目工程文件"
cd $project_path
echo '正在清理工程'
xcodebuild \
clean -configuration ${development_mode} -quiet  || exit
echo '清理完成'
echo '路徑:' ${project_path}/${project_name}.xcworkspace
echo '正在編譯工程:'${development_mode}


xcodebuild \
archive -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${development_mode} \
-archivePath ${build_path}/${project_name}.xcarchive -sdk iphoneos  -quiet  || exit


#找到打包簽名參數(shù)的plist文件
# echo "isAdHocPackage is ${isAdHocPackage}"
# echo "isReleasePackage is ${isReleasePackage}"

if [[ $isAdHocPackage == 1 ]]; then
    exportOptionsPlistPath=${current_path}/exportAdHoc.plist
#elif 后面也要跟then
elif [[ isReleasePackage == 1 ]]; then
    exportOptionsPlistPath=${current_path}/exportRelease.plist
else
    exportOptionsPlistPath=${current_path}/exportDebug.plist
fi
echo "exportPlistPath is ${exportPlistPathTmp}"
echo '編譯完成'
echo '開始ipa打包'
echo "=============================="
echo ${build_path}/${project_name}.xcarchive
echo ${development_mode}
echo ${exportIpaPath}
echo ${exportOptionsPlistPath}
echo "=============================="

xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit

if [ -e $exportIpaPath/$product_name.ipa ]; then
echo 'ipa包已導(dǎo)出'

    echo '發(fā)布ipa包到 =============蒲公英平臺(tái)============='
    RESPONSE=$(curl -F "file=@$exportIpaPath/$product_name.ipa" -F "uKey=${user_key}" -F "_api_key=${api_key}" -F "updateDescription=${update_desc}" https://www.pgyer.com/apiv2/app/upload)

    if [ $? -eq 0 ];then
    echo "=============提交蒲公英成功 ============="

    appQRCodeURL=$(trimSlash $(jsonParse "${RESPONSE}" "buildQRCodeURL"))
    appVersion=$(jsonParse "${RESPONSE}" "buildVersion")
    appBuildVersion=$(jsonParse "${RESPONSE}" "buildBuildVersion")

    let gitBranchName = shell("git rev-parse --abbrev-ref HEAD")
    .trimmingCharacters(in: .newlines)

    #通知到釘釘群 將xxxxxxxx替換為真實(shí)access_token `title`需要包含關(guān)鍵詞
    curl 'https://oapi.dingtalk.com/robot/send?access_token=***********' \
        -H 'Content-Type: application/json' \
        -d '
    {
        "msgtype": "markdown",
        "markdown": {
            "title":"打包好了@**",
            "text":"![screenshot]('"$appQRCodeURL"')  \n  **版本:** '"$appVersion"' (build '"$appBuildVersion"')  \n  **環(huán)境:** '"$envir_desc"'  \n  **說明:** '"$update_desc"' \n **分支:** '"$sub_branch"'"
        }
    }'
    else
    echo "=============提交蒲公英失敗 ============="
    fi
#open $exportIpaPath
else
echo 'ipa包導(dǎo)出失敗 '
fi
echo '打包ipa完成  '
exit 0


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • range()方法 start:用于指計(jì)數(shù)的起始值,默認(rèn)為從0開始。 stop:用于指計(jì)數(shù)的結(jié)束值,但不包括sto...
    林博倫閱讀 188評(píng)論 0 1
  • 原文地址:原文第二部分;原文第一部分; 自己看到感覺很不錯(cuò),留下來自己看看; 1.判斷手機(jī)號(hào)碼格式是否正確,利用正...
    d0u閱讀 149評(píng)論 0 0
  • 驗(yàn)證浮點(diǎn)數(shù)相加等于另外一個(gè)浮點(diǎn)數(shù): 列表變?yōu)樗饕?元素 字符編碼轉(zhuǎn)換 生成當(dāng)前時(shí)間唯一訂單號(hào) 生成當(dāng)前時(shí)間之前之后...
    freedom_smile閱讀 176評(píng)論 0 0
  • 1.顏色轉(zhuǎn)變成圖片 2.app評(píng)分跳轉(zhuǎn) 3.獲取當(dāng)前系統(tǒng)語言環(huán)境 4.計(jì)算字符串的高度 5.強(qiáng)行關(guān)閉app的方法 ...
    船長_閱讀 3,597評(píng)論 7 113
  • var zycTools = {//使用css選擇器選擇單個(gè)元素$:function(elem){return d...
    LIsPeri閱讀 226評(píng)論 0 0

友情鏈接更多精彩內(nèi)容