shell脚本 给代码加上apache lisence2(al2)头
来源:互联网 发布:打车软件推广方案 编辑:程序博客网 时间:2024/04/29 22:08
给定一个代码包,将其中未加上apache lisence2(al2)头的文件,全加上 al2头。
1> 文件中已经有al2头的文件,直接退出。
查找文件内容中有行内容包括“licenses/LICENSE-2.0”“Apache Software Foundation”;行开头内容包括“^#Licensedto the Apache Software”的文件。
2>文件中没有al2头的文件。其文件的开头如果有几个空行,则将文件空行删除。使得文件的第一行为"#!/bin/bash"或者 "#!/bin/python2"
3>对符合文件的添加al2头。
sed -i是直接修改文件,-n 可以取消屏幕的输出信息。
//add_license.sh:对一个文件操作
#!/bin/bashset -e
set -o xtrace
file=$1
# for file has blank lines at the head, remove those blank lines.
sed -i '/./,/^$/!d' $file
# for file has a license head,exit
#if [[ ` cat $file | grep -iHn "license" | wc -l` -gt 0 ]]; then
# exit 0
#fi
# for files already had al2 head, exit.
if [[ `cat $file | grep "licenses/LICENSE-2.0" | wc -l` -gt 0 ]]; then
if [[ `cat $file | grep "Unless required by applicable law" | wc -l` -gt 0 ]]; then
if [[ `cat $file | grep "Copyright" | wc -l` -gt 0 ]]; then
exit 0
fi
fi
fi
# for files already have MIT Licese, exit.
if [[ ` cat $file | grep "licensed under the MIT" | wc -l` -gt 0 ]]; then
exit 0
fi
# for files already have BSD License head,exit.
if [[ `cat $file | grep "BSD License" | wc -l` -gt 0 ]]; then
exit 0
fi
# for files already has Horizon Apache license
if [[ `cat $file | grep "base Horizon JavaScript object" | wc -l` -gt 0 ]];then
exit 0
fi
# for ".html" file
if [ "${file##*.}"x = "html"x ];then
sed -i '1 i\\n<!-- Copyright 2014 Intel Corporation, All Rights Reserved.\n\n Licensed under the Apache License, Version 2.0 (the"License");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n --> \n' $file
exit 0
fi
# for ".css" ".js" file
if [ "${file##*.}"x = "css"x ]||[ "${file##*.}"x = "js"x ];then
sed -i '1 i\\n/* Copyright 2014 Intel Corporation, All Rights Reserved.\n\n Licensed under the Apache License, Version 2.0 (the"License");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n */\n' $file
exit 0
fi
# for ".py" ".sh" file has the "# vim" "bin", we add al2 head behind the 1st line.
if [[ `sed -n 1p $file| grep -E "(bin|^# vim: tabstop)"| wc -l ` -gt 0 ]]; then
sed -i '1 a\\n# Copyright 2014 Intel Corporation, All Rights Reserved.\n\n# Licensed under the Apache License, Version 2.0 (the"License");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied. See the License for the\n# specific language governing permissions and limitations\n# under the License.\n' $file
exit 0
fi
sed -i '1 i\\n# Copyright 2014 Intel Corporation, All Rights Reserved.\n\n# Licensed under the Apache License, Version 2.0 (the"License");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied. See the License for the\n# specific language governing permissions and limitations\n# under the License.\n' $file
set +o xtrace
//multi_add.sh:对多个文件批量操作
set -e
TOPDIR=$(cd $(dirname "$0")&& pwd)
cp -rf $TOPDIR/add_license.sh /usr/local/bin/
# enter the code directory
code=$1
cd $code
# for all the files except the directory file, do add_license
for n in `find . -name "*.py" -o -name "*.sh" -o -name "*.css" -o -name "*.js" -o -name "*.html"`; do
if [[ ! -d $n ]]; then
add_license.sh $n
fi
done
# deal with __init__.py
for n in `find . -name "__init__.py"`; do
cnt=`cat $n | wc -l`
if [[ $cnt -eq 0 ]]; then
echo "" > $n
sed -i '1 i\\n# Copyright 2014 Intel Corporation, All Rights Reserved.\n\n# Licensed under the Apache License, Version 2.0 (the"License");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied. See the License for the\n# specific language governing permissions and limitations\n# under the License.\n' $n
fi
done
//处理空的__init__.py文件: init.sh
set -e
TOPDIR=$(cd $(dirname "$0")&& pwd)
cp -rf $TOPDIR/add_license.sh /usr/local/bin/
# enter the code directory
code=$1
cd $code
# deal with __init__.py
for n in `find . -name "__init__.py"`; do
cnt=`cat $n | wc -l`
if [[ $cnt -eq 0 ]]; then
echo "" > $n
add_license.sh $n
fi
done
- shell脚本 给代码加上apache lisence2(al2)头
- 给shell脚本中加上执行日志
- 给xml加上头
- 给网站加上gzip (适用xampp/apache)
- 给图像数据加上BMP文件头
- 给RGB加上BMP文件头
- 给RGB加上BMP文件头
- Shell脚本文件头介绍
- shell 第一次给了脚本
- 写shell脚本自动生成shell脚本头注释信息
- 务必在判断字符串时,给shell变量加上引号
- Linux shell 脚本攻略shell代码(小试牛刀)
- 给层加上最大化,最小化和关闭按钮(经典代码)适合做浮动层类。
- [cnblogs镜像]页面定制CSS代码初探(五):给每篇文章最后加上'<完>'
- shell脚本-头文件名大小写纠正
- SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码
- SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码
- FFmpeg给mp4视频加上旋转90度的代码
- leetcode-Binary Tree Preorder Traversal
- 1-2 温度
- Android播放器框架分析之AwesomePlayer
- bzoj 1191: [HNOI2006]超级英雄Hero
- MediaCodec Java API 与 StageFright (2014-09-17 22:28:54)
- shell脚本 给代码加上apache lisence2(al2)头
- ubuntu系统使用之4:安装jdk6
- c++非虚函数的编译执行
- android之媒体硬解OMX的实现
- WPF 设置WebBrowser控件不弹脚本错误提示框
- Android学习笔记__1__Android体系架构
- IStorage的解释
- redis五种数据类型的使用
- 模板函数