1 用法,在我们编写的软件为了让用户使用你的软件,就有一个usage,例如
usage()
{
ECHO "Usage: create-lsb-image ARCH ROOTFS_IMAGE"
ECHO "ARCH : x86 or x86-64 or ppc32"
ECHO "ROOTFS_IMAGE: Name of the rootfs image with suffix /"rootfs.tar.bz2/", i.e."
ECHO " poky-image-lsb-qemux86-20110317030443.rootfs.tar.bz2"
ECHO ""
ECHO "Examples:"
ECHO " creat-lsb-image x86 poky-image-lsb-qemux86-20110317030443.rootfs.tar.bz2"
}
-参数要用抽象的变量来代替
-然后解释每个变量
-增加一个具体的用法
2 如何得到文件明的后缀
suffix=${PACKAGE_NAME##*.}
3 替代
arch=${qemux86_64/x86_64/x86-64}
4 如果是重复的工作要用一个循环
这是一个不好的方式,下载每个包都要加好些语句
if [ -d lsb-test-suite-${MACHINE_ARCH} ];then
cd lsb-test-suite-${MACHINE_ARCH}
ECHO "Download lsb test suite, it could take some time..."
wget -c -t 5 http://ftp.linuxfoundation.org/pub/lsb/bundles/released-4.1.0/dist-testkit/lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz
exit_check
ECHO "Download lsb-xdg-utils-4.0.0-2.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/lsbdev/released-4.1.0/binary/${T_ARCH}/lsb-xdg-utils-4.0.0-2.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-apache-2.2.8-2.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-apache-2.2.14-3.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-tcl-8.5.1-2.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-tcl-8.5.7-6.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-expect-5.43.0-7.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-expect-5.43.0-11.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-groff-1.19.2-4.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-groff-1.20.1-5.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-raptor-1.4.16-2.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-raptor-1.4.19-3.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-xpdf-1.01-7.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-xpdf-1.01-10.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-samba-3.0.28a-3.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-samba-3.4.3-5.lsb4.${P_ARCH}.rpm
exit_check
ECHO "Downlocad lsb-rsync-3.0.0-2.lsb4.${P_ARCH}.rpm"
wget -c -t 5 http://ftp.linux-foundation.org/pub/lsb/app-battery/released-4.1.0/${T_ARCH}/lsb-rsync-3.0.6-3.lsb4.${P_ARCH}.rpm
exit_check
else
ECHO "Can't find lsb test suite for ${MACHINE_ARCH}"
fi
好的方式,应该这样
if [ "${ARCH}" == "x86-64" ]; then
COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${P_ARCH}.tar.gz"
else
COM_PACKAGE_LIST="lsb-dist-testkit-4.1.0-5.${T_ARCH}.tar.gz"
fi
APP_PACKAGE_RPMLIST="lsb-apache-2.2.14-3.lsb4.${P_ARCH}.rpm
lsb-tcl-8.5.7-6.lsb4.${P_ARCH}.rpm
lsb-expect-5.43.0-11.lsb4.${P_ARCH}.rpm
lsb-groff-1.20.1-5.lsb4.${P_ARCH}.rpm
lsb-raptor-1.4.19-3.lsb4.${P_ARCH}.rpm
lsb-xpdf-1.01-10.lsb4.${P_ARCH}.rpm
lsb-samba-3.4.3-5.lsb4.${P_ARCH}.rpm
lsb-rsync-3.0.6-3.lsb4.${P_ARCH}.rpm"
APP_PACKAGE_SOURCELIST="expect-tests.tar /
tcl-tests.tar /
raptor-tests.tar /
test1.pdf /
test2.pdf"
PACKAGE_LIST="${COM_PACKAGE_LIST} ${APP_PACKAGE_RPMLIST} ${APP_PACKAGE_SOURCELIST}"
RELEASE=released-4.1.0 #Version for lSB TEST SUITE
WGET="wget -c -t 5" # Tools of download packages
SERVER1="http://ftp.linuxfoundation.org/pub/lsb/bundles/${RELEASE}/dist-testkit" #URL
SERVER2="http://ftp.linux-foundation.org/pub/lsb/app-battery/${RELEASE}/${T_ARCH}" #URL
SERVER3="http://ftp.linuxfoundation.org/pub/lsb/snapshots/appbat/tests" #URL
download()
{
for i in $@; do
ECHO " -->Downloading package /"${i}/""
PACKAGE_NAME=${i}
suffix=${PACKAGE_NAME##*.}
if [ $suffix = "gz" ];then
${WGET} ${SERVER1}/${i}
elif [ $suffix = "rpm" ];then
${WGET} ${SERVER2}/${i}
else
${WGET} ${SERVER3}/${i}
fi
done
}
if [ -d lsb-test-suite-${MACHINE_ARCH} ];then
cd lsb-test-suite-${MACHINE_ARCH}
ECHO "Downloading lsb test suite, it could take some time..."
download ${PACKAGE_LIST}
else
ECHO "Can't find lsb test suite for ${MACHINE_ARCH}"
fi
5 如何处理交互
在自动脚本中,类似mkfs.ext3 在运行的时候需要用户输入(yes/no),如果我们的答案是肯定的。可用如下的方法
mkfs.ext3 poky-image-lsb-${MACHINE_ARCH}-test.ext3 > /dev/null 2>&1 <<End-Of-Session
y
End-Of-Session
6 > /dev/null/ 2>&1
将输出映射到/dev/null,将错误映射到输出。