前言
為了友善其他人搭建dm368 ipnc3.0環境,我寫了個腳本,執行腳本就可以自動搭建好環境了,絕對的傻瓜操作了,不過有一個地方讓我很郁悶,那就是在用sed替換掉某段内容的時候(143行--156行),替換的文本有很多行且裡面某些行必須要tab開頭(makefile要求,這裡看不出,上傳的問題),在我寫的時候發現我必須把替換的内容靠在最左邊,如果我想放到右邊寫,替換後内容就會包含左邊的那些空格。放在最左邊導緻一點也不美觀了,誰有更好的方法可以告訴我哈,先謝謝了! (注意:我的代碼其實是有對齊的,放上來就全部都靠左了,看不出我上面說的sed的問題了,實際情況如下圖:sed替換的内容放到了最左邊, 但我想要把sed替換的内容的每行靠右些,與上面的對齊,不知道我描述清楚了沒,呵呵。 還有,如果有人想用這個腳本的話,請自己再測試下,因為我怕上傳導緻某些tab啊空格啊變了,我不怎麼寫腳本,是以有些地方可能有更好的方法實作,希望大家提出來,一起學習下,謝謝!)
注: 内部有一些對特定檔案的處理,主要是因為我的環境是fedora14,make的版本較高和我認為ipnc3.0原始檔案裡面有個别檔案有些小bug及針對于我們自己的裝置的一些小的修改。
#!/bin/sh
#this script is used for configuration of the dm368 3.0 ipnc environment ----rongp
#date: 2012/3/24
PID=$$
BashId=`pidof bash`
DEFAULT_INSTALL_PATH=/home/kez/dm368_3.0_ipnc
INSTALL_PATH=$DEFAULT_INSTALL_PATH
DEFAULT_MV_DIR=/opt/mv_pro_5.0
MV_DIR=$DEFAULT_MV_DIR
MVTOOL_DIR=$MV_DIR/montavista/pro/devkit/arm/v5t_le
function help() {
clear
echo -e "\
\n\n\nI'm assume that : \n\
\tThe default installation path is \"$DEFAULT_INSTALL_PATH\" \n\
and mvtool path is \"$MV_DIR\". if not, please input 'n' or \n\
'N' to exit and use -i option with installation Path or -m option \n\
with Mvtool path to try again! the partion of installtion path should \n\
have 2G can use and the partion of mvtool path should 2G can use.\n"
read -p "continue ?(Y[y]/N[n]): " Yn #-t 3
if [ "$Yn" == "Y" ] || [ "$Yn" == "y" ]; then
return 0
else
return 254
fi
}
function handler_input() {
unset OPTIND
local name=
local ret=0
while getopts "i:m:" name; do
case $name in
i)
INSTALL_PATH=$OPTARG
# echo "get option $INSTALL_PATH"
ret=$(($ret+1))
;;
m)
MV_DIR=$OPTARG
# echo "get option $MVTOOL_DIR"
ret=$(($ret+1))
;;
?)
echo "Input Error!!! Argument invalid!!!"
return 255 #means error occured
;;
esac
done
return $ret
}
function clean_package() {
find "$INSTALL_PATH" -name *.tar.gz | xargs -i rm -rf {} >/dev/null 2>&1
find "$INSTALL_PATH" -name *.bin | xargs -i rm -rf {} >/dev/null 2>&1
echo -e "clean *tar.gz ok, you can remove IPNC_RDK_DM36x_Release_3.0.0 \nfrom shared zone to other disk or partion to reduce virtual disk size"
}
function check_exec_method() {
for i in $BashId
do
if [ "$PID" == "$i" ]; then
PID=""
break;
fi
done
if [ "$PID" != "" ]; then
echo "Error!!! Usage: use source to excute the script, Don't use sh srcipt or ./srcipt!!!eg: source init.sh"
exit 1
fi
}
check_exec_method
handler_input $@
ret=$?
if [ "$ret" != "255" ]; then
help
ret=$?
fi
if [ $((ret)) -lt 250 ]; then
if [ "$INSTALL_PATH" == "$DEFAULT_INSTALL_PATH" ]; then
mkdir -p "$INSTALL_PATH" >/dev/null 2>&1
fi
if [ "$MV_DIR" == "$DEFAULT_MV_DIR" ]; then
mkdir -p "$MV_DIR" >/dev/null 2>&1
fi
[ ! -d "$INSTALL_PATH" ] || [ ! -d "$MV_DIR" ] && { ret=253; echo "Input Error!!! $INSTALL_PATH or $MVTOOL_DIR is not a Dir!!!"; }
fi
if [ $((ret)) -lt 250 ]; then
clear
echo "===================================================="
echo "Please wait, it will spend about 3-6 minutes!"
echo "Starting Decompress...Please wait!"
if [ ! -e "$MVTOOL_DIR" ];then
tar -zkxf Mvtool/mvltools5_0_0801921_update.tar.gz -C $MV_DIR
[ $? ] && echo "Decompress mvltools5_0_0801921_update.tar.gz Ok..."
tar -zkxf Mvtool/DaVinciLSP_02_10_00_14.tar.gz -C $MV_DIR
[ $? ] && echo "Decompress DaVinciLSP_02_10_00_14.tar.gz Ok..."
else
echo -e "echo $MVTOOL_DIR already exists, skip decompress Mvtool"
fi
tar -zkxf Private/PrivateTI_IPNC_DM36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress PrivateTI_IPNC_DM36x_3.0.0.tar.gz Ok..."
tar -zkxf Open/OpenSrc_IPNC_DM36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress OpenSrc_IPNC_DM36x_3.0.0.tar.gz Ok..."
tar -zkxf Appro/Appro_IPNC_DM36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress Appro_IPNC_DM36x_3.0.0.tar.gz Ok..."
cd $INSTALL_PATH >/dev/null
mkdir ipnc_psp
mkdir -p ipnc_rdk/tftp
mkdir -p ipnc_rdk/target
tar -zkxf $INSTALL_PATH/Application/src/dvsdk_ipnctools_dm36x_3.0.0.tar.gz -C $INSTALL_PATH
[ $? ] && echo "Decompress dvsdk_ipnctools_dm36x_3.0.0.tar.gz Ok..."
tar -zkxf $INSTALL_PATH/Application/src/lsp_ipnc_dm36x_3.0.0.tar.gz -C $INSTALL_PATH/ipnc_psp
[ $? ] && echo "Decompress lsp_ipnc_dm36x_3.0.0.tar.gz Ok..."
tar -zkxf $INSTALL_PATH/Utils/src/u-boot-1.3.4_ipnc_dm36x_2.0.0.tar.gz -C $INSTALL_PATH/ipnc_psp
[ $? ] && echo "Decompress u-boot-1.3.4_ipnc_dm36x_2.0.0.tar.gz Ok..."
ls $INSTALL_PATH/Application/src/ipnc_app_dm36x_* | xargs -i tar -zkxf {} -C $INSTALL_PATH/ipnc_rdk
[ $? ] && echo "Decompress ipnc_app_dm36x_* Ok..."
ls $INSTALL_PATH/Utils/filesys/* | xargs -i tar -zkxf {} -C $INSTALL_PATH/ipnc_rdk/target
[ $? ] && echo "Decompress filesys_ipnc_dm36x.tar.gz squashfs.tar.gz Ok..."
echo "Decompress Successed..."
cd - >/dev/null
chmod 777 -R $INSTALL_PATH/ipnc_rdk
cd $INSTALL_PATH/ipnc_rdk >/dev/null
sed -i 's/^id:5/id:3/g' target/filesys/etc/inittab
sed -i 's/\(cpu_mips [<=>]\{1,2\} \)150/\1145/g' ipnc_app/sys_server/src/checkPlatform.c
sed -in -e '/config %config:/,+2c\ \
config: scripts_basic outputmakefile FORCE \
$(Q)mkdir -p include/linux include/config \
$(Q)$(MAKE) $(build)=scripts/kconfig $@ \
%config: scripts_basic outputmakefile FORCE \
$(Q)mkdir -p include/linux include/config \
$(Q)$(MAKE) $(build)=scripts/kconfig $@' \
-e '/\/ %\/: prepare scripts FORCE/,+2c\ \
/: prepare scripts FORCE \
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \\\
$(build)=$(build-dir) \
%/: prepare scripts FORCE \
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \\\
$(build)=$(build-dir)' ../ipnc_psp/ti-davinci/Makefile
sed -i -e "s#\(MVTOOL_DIR.*:= \).*#\1$MVTOOL_DIR#" -e "s#\(IPNC_INSTALL_DIR.*:= \).*#\1$INSTALL_PATH#" Rules.make
sed -i '/^squashfs/{n;/.*/d;};' Makefile
read -p "If you want to clean some *tar.gz which are no need any more? (Y[y]/N[n]): " Yn
if [ "$Yn" == "Y" ] || [ "$Yn" == "y" ]; then
clean_package
fi
echo "export PATH=/opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin:/opt/mv_pro_5.0/montavista/pro/bin:/opt/mv_pro_5.0/montavista/common/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
echo -e "Enter $INSTALL_PATH/ipnc_rdk successed.\nyou can use \"make sysall\" to rebuild entire System."\
"\nand use \"make squashfs\" to copy File system to tftp folder."\
"\nother options you can refer to Users_Guide_IPNC_DM36x.pdf"
echo "======================================================"
fi
完!
2012年5月
畢業那兩年在做嵌入式應用開發,主要是單片機和arm linux上的應用開發,後來又做了兩年arm linux驅動開發,15年到現在在做pc端及嵌入式端開發,包括伺服器系統裁剪、底層架構實作、硬體加速等。喜歡技術分享、交流!聯系方式: [email protected]、[email protected]