rpm 的 %pretrans、%pre 等 scriptlet 部分似乎不支持 /bin/sh
rpm's %pretrans, %pre, etc. scriptlet section doesn't seem to support /bin/sh
rpm 的 %pretrans、%pre、%post 等 scriptlet 部分是否不支持所有 /bin/sh?
%pretrans
[ -n "$VERBOSE" ] && echo "pretrans called with argument \`'" >&2
[ -n "$VERBOSE" ] && set -x
%preun
以上在安装rpm时出现如下错误
# rpm -i dist/mapr-bogus-0.0.0-1.noarch.rpm
error: %pretrans(mapr-bogus-0.0.0-1.noarch) scriptlet failed, exit status 1
如果我在条件语句下添加 "echo hello" rpm 安装没有错误。 rpm 脚本中是否有关于短路条件的规则?
bash-4.1# rpmbuild --version
RPM version 4.8.0
bash-4.1# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.1 (Final)
Release: 6.1
Codename: Final
当最后一个命令失败时,RPM 小脚本失败(与每个 shell 脚本一样)。当 '$VERBOSE' 为空时,则 '[' returns 1:
$ [ -n "$VERBOSE" ]
$ echo $?
1
因为你使用 && 没有执行任何其他操作。所以最后一个命令以状态代码 1 退出,因此整个 scriptlet 以状态代码 1 结束。此 RPM 评估该 scriptlet 失败。
正确的解可以是:
%pretrans
[ -n "$VERBOSE" ] && echo "pretrans called with argument \`'" >&2
[ -n "$VERBOSE" ] && set -x
:
其中“:”是 'true' 的通用别名。
@msuchy 回答的补充:
以 "right" 方式抑制错误的另一种方法,如果您 运行 在 "set -e" 下也可以工作,那就是反转测试,使其始终为真:
[ -z "$VERBOSE" ] || echo "thingywhatsit"
如果$VERBOSE 为空,则第一个测试为真,回显不是运行。如果它是假的,它将 运行 回显,并且只有当回显返回错误时它才会是错误。这正是您想要的。
请记住 运行 里面的 "if" 语句不会触发失败:$?为 0,除非 "then" 或 "else" 块中的内容产生错误。
rpm 的 %pretrans、%pre、%post 等 scriptlet 部分是否不支持所有 /bin/sh?
%pretrans
[ -n "$VERBOSE" ] && echo "pretrans called with argument \`'" >&2
[ -n "$VERBOSE" ] && set -x
%preun
以上在安装rpm时出现如下错误
# rpm -i dist/mapr-bogus-0.0.0-1.noarch.rpm
error: %pretrans(mapr-bogus-0.0.0-1.noarch) scriptlet failed, exit status 1
如果我在条件语句下添加 "echo hello" rpm 安装没有错误。 rpm 脚本中是否有关于短路条件的规则?
bash-4.1# rpmbuild --version
RPM version 4.8.0
bash-4.1# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.1 (Final)
Release: 6.1
Codename: Final
RPM 小脚本失败(与每个 shell 脚本一样)。当 '$VERBOSE' 为空时,则 '[' returns 1:
$ [ -n "$VERBOSE" ]
$ echo $?
1
因为你使用 && 没有执行任何其他操作。所以最后一个命令以状态代码 1 退出,因此整个 scriptlet 以状态代码 1 结束。此 RPM 评估该 scriptlet 失败。
正确的解可以是:
%pretrans
[ -n "$VERBOSE" ] && echo "pretrans called with argument \`'" >&2
[ -n "$VERBOSE" ] && set -x
:
其中“:”是 'true' 的通用别名。
@msuchy 回答的补充:
以 "right" 方式抑制错误的另一种方法,如果您 运行 在 "set -e" 下也可以工作,那就是反转测试,使其始终为真:
[ -z "$VERBOSE" ] || echo "thingywhatsit"
如果$VERBOSE 为空,则第一个测试为真,回显不是运行。如果它是假的,它将 运行 回显,并且只有当回显返回错误时它才会是错误。这正是您想要的。
请记住 运行 里面的 "if" 语句不会触发失败:$?为 0,除非 "then" 或 "else" 块中的内容产生错误。