#!/bin/bash tomcat_project_path=" /server/tomcat" tomcat_cp_path="/root/tools/apache-tomcat-8.5.30/*" title=" ############################################ <欢迎进入项目创建系统> ############################################ " # 需要将替换的选项如 #/bin/setclasspath.sh 设置为 java_home_bak= calalina_home_bak #/conf/server.xml 设置为 <Server port=xxxx <Connector port=xxxx <Context docBase=xxxx #java目录 /server/java/jdk1.8.0_161 #tomcat目录 /server/tomcat/项目名字 #webroot目录 /www/名字/webroot tomcat_ver="" jdk_ver=" 1:jdk1.6 2:jdk1.7 3:jdk1.8" jdk_path=" /server/java" jdk_list=("'$jdk_path/jdk1.6.0_31'" "'$jdk_path/jdk1.7.0_79'" "'$jdk_path/jdk1.8.0_161'") webroot_path=" /www" test_setclasspath="/root/setclasspath.sh" function login(){ while true;do echo -e $title read -p "输入项目名称:" project read -p "输入Sever端口名:" sport read -p "输入Connector端口号:" cport while true;do jdk=("1:jdk1.6" "2:jdk1.7" "3:jdk1.8") for i in ${jdk[*]} do echo -e $i done read -p "选择JDK版本:" num if [[ $num -gt 0 ]] && [[ $num -lt 4 ]];then echo "ok" jdk_version=${jdk_list[$(($num-1))]} jdk_easy=${jdk[$(($num-1))]} echo -e "所选版本为$jdk_easy" break else: echo "no ok" fi done read -p "输入项目存放路径名字:" wname #webroot存放路径 用于修改server.xml文件 tomcat_webroot_path="$webroot_path/$wname/webroot" echo -e " 项目名:$project JDK版本:$jdk_easy Tomcat项目存放:$tomcat_project_path/$project Server端口号:$sport Connector端口号:$cport 项目代码存放路径:$tomcat_webroot_path" read -p "1:确认|2:取消" num if [[ $num == "1" ]] then tomcatlist if [[ $flag == "tru" ]];then echo -e " " echo "##########################################" #echo "项目名称:$project" #echo "jdk路径:$jdk_version" #jdk目录 #echo "tomcat代码存放路径:$tomcat_webroot_path" #echo "tomcat项目路径:$tomcat_project_path/$project" #echo "Server端口号:$sport" #echo "Connector端口号:$cport" echo -e " 项目名:$project JDK版本:$jdk_easy Tomcat项目存放:$tomcat_webroot_path Server端口号:$sport Connector端口号:$cport 项目代码存放路径:$tomcat_webroot_path" mkdir -p $tomcat_project_path/$project cd $tomcat_project_path/$project cp -ra $tomcat_cp_path $tomcat_project_path/$project sed -i "s#java_home_bak=#JAVA_HOME=$jdk_version#g" bin/setclasspath.sh >/dev/null sed -i "s#catalina_home_bak=#CATALINA_HOME='$tomcat_project_path/$project'#g" bin/setclasspath.sh >/dev/null sed -i "s#<Server port=xxxx#<Server port='$sport'#g" conf/server.xml >/dev/null sed -i "s#<Connector port=xxxx#<Connector port='$cport'#g" conf/server.xml >/dev/null sed -i "s#<Context docBase=xxxx#<Context docBase='$tomcat_webroot_path'#g" conf/server.xml >/dev/null echo -e " 项目创建成功!!!" echo "##########################################" echo -e " " fi elif [[ $num == "2" ]] then echo "2" else echo "输入有误,请重新输入" fi done } function tomcatlist(){ flag="tru" for i in $(ls $tomcat_project_path) do if [[ $project == "$i" ]] then echo "项目$i已存在,无法创建,请重新输入" flag="fal" break fi done } login
使用图