updatefile.sh - Linux下代码更新脚本

下面写的是一个关于文件上传的代码shell脚本
该篇文章主要有以下几个方面的考虑:
1.文章主要用于在Linux下代码包批量上传;
2.将被覆盖的代码备份做备份,用于后续做问题查看或者代码的回退(回退需要对应的脚本,暂未编写);
3.当次上传的代码,也做备份,用于做后续问题跟踪;

以下为更新脚本
#!/bin/sh
updatePackages=$(ls -rt /home/weblogic/apps/updatefile | awk '{print $1}')
updatedir="/home/weblogic/apps/updatefile"
webAppsdir="/home/weblogic/apps"
beforeUpdateWarBak="/home/weblogic/apps/updateBeforeWarBak"
dir="/home/weblogic/apps/updatefile"
webapps=("bfmcp" "bfmmarket")
function ergodic(){
	lsdir=$(ls "$1" | awk '{print $1}')
 	for file in $lsdir
 	do
		if [ -d "$1/$file" ]
		then  
			ergodic "$1/$file" "$2"
		else
			echo "the directory is ___:$1"
			if [[ $file =~ "list_source.txt" ]]
			then 	echo "The file not need to update ---:$file"
			else 
				updatedir=$1
				echo "Update direcotry is -----------:$updatedir"
				bfmdir=${updatedir##*bfmmarketn}
				pdir=${updatedir##*updatefile/}
				pdirs=${pdir%%bfmmarketn*}
				echo "bfm war bak directory is ------:$beforeUpdateWarBak/$pdirs$2$bfmdir"
				echo "bfm war directory is ----------:$webAppsdir/$2$bfmdir"
				echo "Update file is ----------------:$1/$file"

				if [ -e "$beforeUpdateWarBak/$pdirs$2$bfmdir" ]
				then 	echo "bfm war bak directory is exist -------:$beforeUpdateWarBak/$pdirs$2$bfmdir"
				else	
					echo "bfm war bak is not exist,make directory is ----------------:$beforeUpdateWarBak/$pdirs$2$bfmdir"
					mkdir -p "$beforeUpdateWarBak/$pdirs$2$bfmdir"
				fi
				
				echo "search the war file is or not exist ------: $webAppsdir/$2$bfmdir/$file"
				if [ -e "$webAppsdir/$2$bfmdir/$file" ]
				then 
					echo "war file is exist,copy to the file is ---:$beforeUpdateWarBak/$pdirs$2$bfmdir"
					cp -rf $webAppsdir/$2$bfmdir/$file $beforeUpdateWarBak/$pdirs$2$bfmdir 
				else 
					echo "war file is not exist,don't need to copy the file to war bak---:$webAppsdir/$2$bfmdir/$file"
				fi

				echo "search the bfm war directory is or not exist ----:$webAppsdir/$2$bfmdir"
				if [ -e "$webAppsdir/$2$bfmdir" ]
				then	echo "bfm war directory is exist,don't need to make the file ------:$webAppsdir/$2$bfmdir"
				else 
					echo "bfm war directory is exist is not exist,need to make the file:$webAppsdir/$2$bfmdir"
					mkdir -p "$webAppsdir/$2$bfmdir"
				fi
				echo "update file to bfm war direcotry ---------:$1/$file to $webAppsdir/$2$bfmdir"
				cp -rf $1/$file $webAppsdir/$2$bfmdir
			fi
		fi
 	done
}

for updatePackage in $updatePackages
do
	echo "$updatePackage"
	if [[ $updatePackage =~ "All" ]]
	then
		echo "Now update package is ----: $updatePackage"
		for warName in ${webapps[@]}
			do
				echo "Now update package is :$updatePackage and the update war name is :$warName"
				ergodic "$dir/$updatePackage" $warName
			done
	else
		warName=$(ls $updatedir | awk -F '--' '{print $2}')
		if [[ $warName =~ "bfm" ]]
		then 
			ergodic "$dir/$updatePackage" "$warName"
		else
			echo "$warName"
		fi
	fi
	  
	if [ -e "$webAppsdir/updatePackageBak/$updatePackage" ]
        then
                echo "updatePackage is exist,need to delete the file ---:  $webAppsdir/updatePackageBak "
                rm -r "$webAppsdir/updatePackageBak/$updatePackage"
        else
		echo "no action"
        fi
        mv "$dir/$updatePackage" "$webAppsdir/updatePackageBak/"
done

 

要使用Java代码更新Github文件,你需要使用Github API来实现。下面是一个简单的Java代码示例,演示如何使用Github API更新文件。 ``` import org.apache.commons.codec.binary.Base64; import org.eclipse.egit.github.core.Commit; import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.RepositoryContents; import org.eclipse.egit.github.core.service.ContentsService; import org.eclipse.egit.github.core.service.RepositoryService; import org.eclipse.egit.github.core.util.EncodingUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; public class GithubApiExample { private static final String REPO_OWNER = "your_github_username"; private static final String REPO_NAME = "your_github_repository_name"; private static final String FILE_PATH = "path_to_your_file_in_repository"; private static final String ACCESS_TOKEN = "your_github_personal_access_token"; public static void main(String[] args) throws IOException { RepositoryService repositoryService = new RepositoryService(); repositoryService.getClient().setOAuth2Token(ACCESS_TOKEN); Repository repository = repositoryService.getRepository(REPO_OWNER, REPO_NAME); ContentsService contentsService = new ContentsService(); contentsService.getClient().setOAuth2Token(ACCESS_TOKEN); RepositoryContents file = contentsService.getContents(repository, FILE_PATH); String decodedContent = new String(Base64.decodeBase64(file.getContent()), StandardCharsets.UTF_8); String newContent = "Hello, Github API!"; Commit commit = new Commit(); commit.setMessage("Update file via Github API"); String encodedContent = EncodingUtils.toBase64(newContent.getBytes()); contentsService.updateFile(repository, FILE_PATH, commit, encodedContent, file.getSha()); } } ``` 在这个示例中,我们使用了Github API的Java库,Eclipse EGit。这个库提供了对Github API的访问。 首先,我们需要获取访问Github API所需的访问令牌。然后,我们使用RepositoryService和ContentsService连接到Github API。 接下来,我们获取要更新的文件的内容。我们使用Base64编码将内容解码为字符串。 然后,我们创建一个新的字符串,并将其编码为Base64格式。最后,我们使用ContentsService的updateFile方法更新文件。我们提供了文件的路径、提交信息、新的内容和文件的SHA哈希值。 这是一个简单的Java代码示例,演示如何使用Github API更新文件。请注意,这个示例假定你已经安装了Eclipse EGit库,并且已经获取了Github API的访问令牌。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值