#!/bin/sh
# Busybox smoke tests.
# shellcheck disable=SC1091
#回显命令执行及其参数
set -x
#进入目录,分先后执行两个脚本文件,再返回到当前目录
cd ../../utils
. ./sys_info.sh
. ./sh-test-lib
cd -
#Test user id
#检查是否是root 用户
if [ `whoami` != 'root' ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
#发行版的版本,目前只针对centos 来安装包
case $distro in
"centos")
#安装四个package
yum install gcc -y
yum install make -y
yum install bzip2 -y
yum install wget -y
#下载busybox的tar包
wget https://busybox.net/downloads/busybox-1.27.2.tar.bz2
#检查下载是否成功
print_info $? download-busybox
#加压tar包
tar -jxvf busybox-1.27.2.tar.bz2
#检查解压是否成功
print_info $? tar-busybox
#进入到目录开始编译busybox,并检查编译是否成功
cd busybox-1.27.2/
make defconfig
make
print_info $? make-busybox
;;
esac
#针对centos和debian busybox执行的方式不同
case $distro in
"centos")
commond="./busybox"
;;
"debian")
commond="busybox"
;;
esac
#这就就是执行busybox的中包含的pwd命令
$commond pwd
#通过$? 建厂busybox的pwd 命令是否执行成功
print_info $? busybox-pwd
$commond mkdir dir
print_info $? busybox-mkdir
$commond touch dir/file.txt
print_info $? busybox-touch
$commond ls dir/file.txt
print_info $? busybox-ls
$commond cp dir/file.txt dir/file.txt.bak
print_info $? busybox-cp
$commond rm dir/file.txt.bak
print_info $? busybox-rm
$commond echo 'busybox test' > dir/file.txt
print_info $? busybox-echo
$commond cat dir/file.txt
print_info $? busybox-cat
$commond grep 'busybox' dir/file.txt
print_info $? busybox-grep
# shellcheck disable=SC2016
$commond awk '{printf("%s: awk\n", $0)}' dir/file.txt
print_info $? busybox-awk
$commond free
print_info $? busybox-free
$commond df
print_info $? busybox-df
#检查是否存在busybox的进程
count=`ps -aux | grep busybox | wc -l`
#如果busybox的进程大于0,则通过pidof 得到这个进程的pid后,再通过kill 杀掉这个进程
if [ $count -gt 0 ]; then
kill -9 $(pidof busybox)
print_info $? kill-busybox
fi
#如果发行版是centos的话,在测试结束后,删掉这三个package
case $distro in
"centos")
yum remove gcc -y
yum remove make -y
yum remove bzip2 -y
;;
esac