shell脚本 给代码加上apache lisence2(al2)头

这是一个shell脚本,用于检查并批量为代码文件添加Apache License 2.0(AL2)头部。如果文件已有MIT、BSD或特定的Horizon Apache许可头,则脚本会跳过该文件。对于不同类型的文件(如.html, .css, .js, .py, .sh),脚本会插入相应的AL2头。如果文件为空,脚本会先添加一个空行,然后再添加AL2头。" 117261425,10966026,Java后台开发面试实战:阿里、腾讯、头条面试解析,"['Java', '后端开发', '面试', '技术面试']
摘要由CSDN通过智能技术生成

给定一个代码包,将其中未加上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/bash

set -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" |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值