bash将数组添加到plist中

时间:2013-04-03 02:02:12

标签: bash post-install

我正在通过Cydia创建一个可安装的软件包,它将编写com.intelliborn.intelliscreenx 对此:

<?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>Hidden</key>
    <array>
        <string>libactivator</string>
        <string>com.aaronash.BarrelSettings</string>
        <string>com.iptm.bigboss.sbsettings</string>
    </array>
</dict>
</plist>

但我不知道如何将postinst脚本写入正确添加的位置,并将postrmv脚本放到正确删除它的位置。

安装此软件包后,hidden.plist应如下所示:

<?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>Hidden</key>
    <array>
        <string>libactivator</string>
        <string>com.aaronash.BarrelSettings</string>
        <string>com.iptm.bigboss.sbsettings</string>
            <string>com.intelliborn.intelliscreenx</string>
    </array>
</dict>

这是我的postinst&amp; postrmv脚本看起来:

的postinst

#!/bin/bash

declare -a cydia
cydia=($CYDIA)

if [[ $1 == install ]]; then
    if [[ ${CYDIA+@} ]]; then
        eval "echo 'finish:restart' >&${cydia[0]}"
    fi
fi
echo -e "\n\<string>com.intelliborn.intelliscreenx</string>\n" >> /var/mobile/Library/LibHide/hidden.plist

exit 0

postrmv

#!/bin/bash
echo " " >> /var/mobile/Library/LibHide/
sed -i 's/<string>com.intelliborn.intelliscreenx</string>\n" >> /var/mobile/Library/LibHide/hidden.plist

declare -a cydia
cydia=($CYDIA)

if [[ $1 == install ]]; then
    if [[ ${CYDIA+@} ]]; then
        eval "echo 'finish:restart' >&${cydia[0]}"
    fi
fi

exit 0

1 个答案:

答案 0 :(得分:1)

你可以使用iPhone的plutil,因为它适用于plists文件。

在cydia软件包的控制文件中,将以下内容添加到预先依赖中,如下所示,如果事先安装了plutil,则可以为postinst安装,而后台不会失败。

<强>控制

Name: com.test.package
Pre-Depends: com.ericasadun.utilities

<强>的postinst

#!/bin/bash

#add value to array
plutil -key Hidden -arrayadd -value com.intelliborn.intelliscreenx /var/mobile/Library/LibHide/hidden.plist

declare -a cydia
cydia=($CYDIA)

if [[ $1 == install ]]; then
    if [[ ${CYDIA+@} ]]; then
    eval "echo 'finish:restart' >&${cydia[0]}"
    fi
fi

exit 0