explodepkg 是用来解开 slackware 包的工具, 与 installpkg/removepkg/upgradepkg 想比它并不算常用, 它可以用来分析或者处理一个包的内容, 而不是安装/卸载/升级一个软件(因为它不执行 doinst.sh, 而且不记录所安装文件).
explodepkg 大概是 pkgtools 中最简单的脚本了, 所以直接在代码中加入注释的方式列在下面:
#!/bin/sh
TAR=tar-1.13
# 检查是否存在 tar-1.13
$TAR --help 1> /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
TAR=tar
fi
# 检查 tar 版本是否符合要求, 如果不符合, 则给出提示, 并延迟 5 秒
if [ ! "`LC_MESSAGES=C $TAR --version`" = "tar (GNU tar) 1.13
Copyright (C) 1988, 92,93,94,95,96,97,98, 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by John Gilmore and Jay Fenlason." ]; then
echo "WARNING: pkgtools are unstable with tar > 1.13."
echo " You should provide a \"tar-1.13\" in your \$PATH."
sleep 5
fi
# 无参数运行 explodepkg 时, 给出使用帮助
if [ $# = 0 ]; then
cat << EOF
Usage: explodepkg package_name [package_name2, ...]
Explodes a Slackware compatible software package (or any tar+gzip archive) in
the current directory. Equivalent to (for each package listed):
( umask 000 ; tar xzvf package_name )
Note: This should only be used for debugging or examining packages, not for
installing them. It doesn't execute installation scripts or update the package
indexes in /var/log/packages|scripts.
EOF
fi
# 有参数运行 explodepkg 时, 把每个参数当作一个软件包进行处理
# 所以所有的软件包都会被解压缩到当前目录, 并混合在一起(感觉不太好)
for PKG in $* ; do
echo "Exploding package $PKG in current directory:"
# 解压缩文件, umask 000 是为了避免系统内 umask 的设置影响了包内文件的权限,
# 在括号中执行避免了 umask 000 影响到此脚本后面部分的 umask 设置(因为使用的
# 是子 shell, 设置只影响子 shell), 其实这里可以不用加括号, 因为此脚本后面并
# 没有什么操作会受 umask 设置的影响, 而脚本退出之后, 是不会影响到它的父进程的, 除非你是用 . explodepkg 来执行.
( umask 000 ; $TAR xzvf $PKG 2> /dev/null )
# 检查是否存在 install/doinst.sh, 如存在, 则给出提示
if [ -r install/doinst.sh ]; then
echo
echo "An installation script was detected in ./install/doinst.sh, but"
echo "was not executed."
fi
done