#!/bin/bash################################################################################# Filename:upgrade_ Project.SH# Summary: Project Upgrade Script # LICENSE:GPL # Version:1.0# Author:jet bi# Email:1207501666@qq. com# Date: ./ ,/ ,# Note: #1requires project support for SVN upgrade mode and is equipped with svn#2need restart_tomcat.sh to exist #3. Use description # Upgrade:./upgrade_project.SH-P Project Path-T Tomcat path # rollback:./upgrade_project.SH-r version number-p Project path-T Tomcat path ###################################################################### ######### #project_path=""# project Path project_version=""# project Version Tomcat_path=""# tomcat Path Restart_script="/local/script/restart_tomcat.sh"# Restart script path Log_file="/local/script/logs/upgrade.log"# log file path # Get parameters and assign values to variables whileGetopts'p:r:t:'OPT; Do Case${OPT}inchp) Project_path=${optarg};; R) Project_version=${optarg};; T) Tomcat_path=${optarg};; Esac Done# Check if the project path and Tomcat path are setEcho${project_path:?"- P option:missing Project Path"} >/dev/NULLEcho${tomcat_path:?"- t option:missing Tomcat Path"} >/dev/NULL# See if there is a Tomcat restart scriptif[!-e ${restart_script}]; Then Echo "Can ' t find/local/script/restart_tomcat.sh"Exit1fi# See if you have permission to execute scriptsif[!-x ${restart_script}]; Then chmodu+x ${restart_script}fi# Determine if the project directory is legalif[[!-D ${project_path}]; Then Echo "${project_path} is not a directory!"Exit2fi# See if there is a log directory, there is no createif[[!-E $ (dirname${log_file})]; Then Echo "No Directory of Upgrade.log: $ (dirname ${log_file})" mkdir$(dirname${log_file}) # Exit3fi# start the upgradeEcho---------------------------------------------------------------------------->>${log_file}Echo "upgrade_title:$ (Date +%y-%m-%d" "%h:%m:%s) svn up ${project_path}">>${log_file}Echo-E"upgrade_content:\c">>${log_file}if[${project_version}]; ThenSVN up-R ${optarg} ${project_path} >> ${log_file}2>&1&&${restart_script} ${tomcat_path}Elsesvn up ${project_path}>> ${log_file}2>&1&&${restart_script} ${tomcat_path}fiEcho---------------------------------------------------------------------------->>${log_file}exit0
Bash shell-Generic Project Upgrade script