Ubuntu16+PCL+OpenCV

#! /bin/bash

#logger输出函数
#参数表示:I:Info D:Debug W:Warn E:Error 
function Log()
{
    unset OPTIND
	while getopts "I:D:W:E:" arg 
    do
        case "${arg}" in
            I)
                echo -e "[\033[32m$(date +"%Y-%m-%d %T") Info\033[0m]  ""\033[32m${OPTARG}\033[0m"
            ;;
            D)
                echo -e "[\033[34m$(date +"%Y-%m-%d %T") Warning\033[0m]  ""\033[34m${OPTARG}\033[0m"
            ;;
            W)
                echo -e "[\033[33m$(date +"%Y-%m-%d %T") Warning\033[0m]  ""\033[33m${OPTARG}\033[0m"
            ;;
            E)
                echo -e "[\033[31m$(date +"%Y-%m-%d %T") Error\033[0m]  ""\033[31m${OPTARG}\033[0m"
            ;;
            ?)
                echo -e "[\033[31m$(date +"%Y-%m-%d %T") Error\033[0m]  ""\033[31mLog参数输入错误!\033[0m"
            ;;
        esac
    done
}

function Judge_Order(){
	local status=${?}
	test  ${#} -ne 2 && \
		Log -E "函数传入参数错误!" && return 80
	#判断上一条命令的返回值是否为0,若为0则执行成功,若不为0则执行失败
	if [ ${status} -eq 0 ];then
		Log -I "\"${1}\" 执行成功!"
	else 
		Log -E "\"${1}\" 执行失败!"
		test ${2} -eq 0 && 	exit 127
	fi
    echo
}

function Update_All()
{
	sudo apt-get upgrade -y
	Judge_Order "sudo apt-get upgrade -y" 1
	sudo apt-get update -y
	Judge_Order "sudo apt-get update -y" 1
	sudo apt-get -f install -y
	Judge_Order "sudo apt-get -f install -y" 1
	sudo apt-get autoremove -y
	Judge_Order "sudo apt-get autoremove -y" 1

}

function Install_PCL(){
	sudo apt-get install build-essential -y
	Judge_Order "sudo apt-get install build-essential -y" 1
	sudo apt-get install libpcl-dev -y
	Judge_Order "sudo apt-get install libpcl-dev -y" 1
}

function Install_OPENCV(){
	filepath=${HOME}/Opencv.zip
	wget -O  ${filepath} https://codeload.github.com/opencv/opencv/zip/3.4.14
	if [ ! -f ${filepath} ];then
		Log -E "${filepath} 下载失败,任务无法继续执行!"  && exit 127
	fi
	unzip ${filepath}
	Judge_Order "unzip ${filepath}" 1
	mkdir ${HOME}/opencv*/build
	cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
	make -j8
	sudo make install
	Judge_Order "sudo make install" 0
}

function Main(){
	Update_All
	Install_PCL
	Install_OPENCV
}
Main

上一篇:*** RuntimeError: CUDA error: out of memory.


下一篇:5.7 echo:显示一行文本