shell

2018-11-16  本文已影响3人  jameiShi

简介:

Shell 首先是 UNIX/Linux 下的脚本编程语言,它是解释执行的,无需提前编译。Shell 的语法细节和你熟悉的大部分编程语言都不太一样,需要重点学习。

Shell 同时也是一个程序,它的一端连接着 UNIX/Linux 内核,另一端连接着用户和其它应用程序;换句话说,Shell 是用户和应用程序与内核沟通的桥梁。


shell.png

shell 脚本:

解释型语言,执行时,需要使用解释器一行一行地转换为代码.如其它解释型语言:perl,python等.
第一个 shell 脚本:

#!/bin/bash
echo "Hello World !"

运行shell 脚本有两种方法:

1.作为可执行程序:
将上面的代码保存为 test.sh,并 cd 到相应目录:

chmod +x ./test.sh  #使脚本具有执行权限
./test.sh  #执行脚本

2.作为解释器参数:

/bin/sh test.sh

语法:

语法

应用

#bin/bsah - l

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

cd /Users/suanle/ios_mmc
git pull
/usr/local/bin/pod install --verbose --no-repo-update

# 工程名
scheme_name="MMCApp"

# 文件名前缀
APP_NAME="买买车"

# info.plist路径
project_infoplist_path="${scheme_name}/Other/Info.plist"

#指定输出路径
export_path=/Library/WebServer/Documents/ota/MMCApp


#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
echo "========= $bundleShortVersion ========"

bundleShortVersion=$(($bundleShortVersion + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bundleShortVersion" "${project_infoplist_path}"
echo "========= $bundleShortVersion ========"

# 指定要打包编译的方式 : Release,Debug,AdHoc...
for build_configuration in Debug AdHoc Release
do
echo "**********build_configuration: $build_configuration"

# 指定输出ipa路径
export_ipa_path="${export_path}/${build_configuration}"
echo "*********输出的ipa路径: ${export_ipa_path}"
# 指定输出归档文件地址
export_archive_path="$export_path/${build_configuration}/$scheme_name.xcarchive"
echo "*********输出的归档文件路径: ${export_archive_path}"

# manifest.plist的文件路径
mainfestPlistPath="/Library/WebServer/Documents/ota/MMCApp/manifest/manifest_${build_configuration}_${bundleShortVersion}_mmc.plist"
echo "*********manifest.plist的文件路径:${mainfestPlistPath}"

cat << EOF > ${mainfestPlistPath}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>items</key>
    <array>
        <dict>
            <key>assets</key>
            <array>
                <dict>
                    <key>kind</key>
                    <string>software-package</string>
                    <key>url</key>
                    <string></string>
                </dict>
                <dict>
                    <key>kind</key>
                    <string>display-image</string>
                    <key>url</key>
                    <string></string>
                </dict>
                <dict>
                    <key>kind</key>
                    <string>full-size-image</string>
                    <key>url</key>
                    <string></string>
                </dict>
            </array>
            <key>metadata</key>
            <dict>
                <key>bundle-identifier</key>
                <string>com.ucarinc.mmcapp</string>
                <key>bundle-version</key>
                <string>2.0.0</string>
                <key>kind</key>
                <string>software</string>
                <key>title</key>
                <string>MMCApp</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>

EOF

#ipa下载地址
ipa_download_path="https://10.99.33.133/ota/$scheme_name/${build_configuration}"

# 导出ipa所需要的plist文件路径
if [ "$build_configuration" = "AdHoc" ] ; then
ExportOptionsPlistPath="$export_path/AdHocExportOptionsPlist.plist"
elif [ "$build_configuration" = "Release" ] ; then
ExportOptionsPlistPath="$export_path/AppStoreExportOptionsPlist.plist"
elif [ "$build_configuration" = "Debug" ] ; then
ExportOptionsPlistPath="$export_path/DevelopmentExportOptionsPlist.plist"
fi

# 指定输出ipa名称 : scheme_name + bundleShortVersion
DATE="$(date +%Y%m%d%H-%M-%S)"
ipa_name="${scheme_name}_V${bundleShortVersion}_${DATE}.ipa"

#下面2行是集成有Cocopods的用法
echo "=================clean================="
# xcodebuild -workspace "${scheme_name}.xcworkspace" -scheme "${scheme_name}"  -configuration ${build_configuration} clean

echo "+++++++++++++++++build+++++++++++++++++"

xcodebuild -workspace "${scheme_name}.xcworkspace" -scheme "${scheme_name}" -sdk iphoneos -configuration ${build_configuration} SYMROOT='$(PWD)'

xcodebuild clean -workspace ${scheme_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration}

xcodebuild archive -workspace ${scheme_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}

xcodebuild  -exportArchive \
-archivePath ${export_archive_path} \
-exportPath ${export_ipa_path} \
-exportOptionsPlist ${ExportOptionsPlistPath}

# 修改ipa文件名称
mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name

# 获取IPA下载链接
ipa_download_url=$(/usr/libexec/PlistBuddy -c "print items:0:assets:0:url" "${mainfestPlistPath}")

ipa_download_url=$"$ipa_download_path/$ipa_name"
echo "********ipa下载链接: $ipa_download_url ========"
# 更改 plist 文件中的下载地址
/usr/libexec/PlistBuddy -c "Set :items:0:assets:0:url $ipa_download_url" "${mainfestPlistPath}"

done
checkpodsmanifest.lock.png
上一篇 下一篇

猜你喜欢

热点阅读