shell 常用脚本


#获取当前目录
rootPath=$(cd "$(dirname "$0")"; pwd)
echo ${rootPath}

#获取上一层目录
lastDir=$(dirname "$PWD") 

#遍历文件夹下面文件
for file in `ls $rootPath`
do
echo "文件名=$file"

#获取文件后缀名
ext=${file##*.}
if [ "$ext" == "txt" ]; then
echo "是txt文件"
fi
done 

#钥匙串解锁
security unlock-keychain -p 123456 /Users/$(whoami)/Library/Keychains/login.keychain

#设置语言
export LANG=en_US.UTF-8

#删除文件或者目录
rm -drf ${rootPath}/build

#创建目录
mkdir ${rootPath}/build

#拷贝文件
cp -r -f ${rootPath}/1.txt ${rootPath}/build/2.txt

#导入p12证书
security import ${rootPath}/package/autopackage/cert/cert.p12 -A -k ~/Library/Keychains/login.keychain -P ${password} -T /usr/bin/codesign

# 获取描述文件信息
mobileprovision_file=${rootPath}/package/autopackage/cert/cert.mobileprovision
mobileprovision_teamname=`/usr/libexec/PlistBuddy -c "Print TeamName" /dev/stdin <<< $(security cms -D -i $mobileprovision_file)`
echo $mobileprovision_teamname
CODE_SIGN_IDENTITY="iPhone Distribution: $mobileprovision_teamname"
echo "$CODE_SIGN_IDENTITY"
PROVISIONING_PROFILE_SPECIFIER=`/usr/libexec/PlistBuddy -c "Print AppIDName" /dev/stdin <<< $(security cms -D -i $mobileprovision_file)`
UUID=`/usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(security cms -D -i $mobileprovision_file)`
echo "UUID:"$UUID

#拷贝描述文件
cp ${rootPath}/package/autopackage/cert/cert.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/${UUID}.mobileprovision

#计算时间差
startTime=`date +%s`
endTime=`date +%s`
secs=`expr $endTime - $startTime`
h=`expr $secs / 3600`
m=`expr $secs % 3600 / 60`
s=`expr $secs % 60`
echo "总时间: ${h}h ${m}m ${s}s"


#删除文件的第34行
sed  -i '' 34d  ${rootPath}/1.h

https://blog.youkuaiyun.com/weiguang1017/article/details/80345058
#表示在文本的1.txt的第二行之后插入abc文本
sed -i "" "/2/ a\  
abc   
" 1.txt 

#替换字符串 1/2 为 3
sed -i "" 's/1\/2/3/g' 1.h

#读取info.plist里面的配置文件的版本号
Version=`/usr/libexec/PlistBuddy -c "print:CFBundleShortVersionString" ${rootPath}/info.plist`
AppName=`/usr/libexec/PlistBuddy -c "print:CFBundleDisplayName" ${rootPath}/info.plist`  


#压缩文件
zip -r ${rootPath}/build/xcarchive.zip ./test.xcarchive

rootPath=$(cd "$(dirname "$0")"; pwd)
echo ${rootPath}


APPDESTENT=${rootPath}/appentitlements.plist
DESTENT=${rootPath}/entitlements.plist
LOGINDESTENT=${rootPath}/LoginItemEntitlements.plist
PROFILE="${rootPath}/profile.plist"

rm -drf ${DESTENT}
rm -drf ${APPDESTENT}
rm -drf ${PROFILE}

/usr/bin/security cms -D -i "${rootPath}/MacTestnetworkextensionDis.provisionprofile"  > "${PROFILE}"
/usr/libexec/PlistBuddy -x -c 'Print :Entitlements' "${PROFILE}" > "${DESTENT}"
/bin/rm "${PROFILE}"

/usr/bin/security cms -D -i "${rootPath}/MacTestDistribute.provisionprofile"  > "${PROFILE}"
/usr/libexec/PlistBuddy -x -c 'Print :Entitlements' "${PROFILE}" > "${APPDESTENT}"
/bin/rm "${PROFILE}"

/usr/bin/security cms -D -i "${rootPath}/LoginHelperDis.provisionprofile"  > "${PROFILE}"
/usr/libexec/PlistBuddy -x -c 'Print :Entitlements' "${PROFILE}" > "${LOGINDESTENT}"
/bin/rm "${PROFILE}"

echo "重签名插件"
codesign -f -s "Developer ID Application: xxx." --entitlements "${DESTENT}" ${rootPath}/WireGuard.app/Contents/PlugIns/WireGuardNetworkExtension.appex


echo "重签名dly"
rm -drf ${PROFILE}
/usr/bin/security cms -D -i "${rootPath}/MacDistribute.provisionprofile"  > "${PROFILE}"
/usr/libexec/PlistBuddy -x -c 'Print :Entitlements' "${PROFILE}" > "${APPDESTENT}"
mDylibs=`find ${rootPath}/WireGuard.app/Contents/Frameworks -name *.dylib`
for dylib in $mDylibs;
do   
    codesign -f -s "Developer ID Application: xxx." --entitlements "$APPDESTENT" "${dylib}"
    echo "codesign dylib: ${dylib}"
done

echo "重签名App"
codesign --timestamp=none -f -v -s "Developer ID Application: xxx." --entitlements "${LOGINDESTENT}" ${rootPath}/WireGuard.app/Contents/Library/LoginItems/WireGuardLoginItemHelper.app
codesign --timestamp=none -f -v -s "Developer ID Application: xxx." --entitlements "${APPDESTENT}" WireGuard.app
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值