update scripts
parent
c1e96a7134
commit
e1773d60e6
|
@ -1,20 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 控制台颜色
|
||||
BLACK="\033[1;30m"
|
||||
RED="\033[1;31m"
|
||||
GREEN="\033[1;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
BLUE="\033[1;34m"
|
||||
PURPLE="\033[1;35m"
|
||||
CYAN="\033[1;36m"
|
||||
RESET="$(tput sgr0)"
|
||||
# ---------------------------------------------------------------------------------
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# CentOS 常用软件一键安装脚本
|
||||
# @author Zhang Peng
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------ libs
|
||||
# 装载其它库
|
||||
LINUX_SCRIPTS_DIR=$(cd `dirname $0`; pwd)
|
||||
|
||||
if [[ ! -x ${LINUX_SCRIPTS_DIR}/lib/utils.sh ]]; then
|
||||
logError "必要脚本库 ${LINUX_SCRIPTS_DIR}/lib/utils.sh 不存在!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source ${LINUX_SCRIPTS_DIR}/lib/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ functions
|
||||
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
printf "${BLUE}\n"
|
||||
printf "${C_B_BLUE}\n"
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 欢迎使用 Dunwu Shell 运维脚本
|
||||
|
@ -22,18 +30,18 @@ printHeadInfo() {
|
|||
# @author: Zhang Peng
|
||||
###################################################################################
|
||||
EOF
|
||||
printf "${RESET}\n"
|
||||
printf "${C_RESET}\n"
|
||||
}
|
||||
|
||||
# 打印尾部信息
|
||||
printFootInfo() {
|
||||
printf "${BLUE}\n"
|
||||
printf "${C_B_BLUE}\n"
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 脚本执行结束,感谢使用!
|
||||
###################################################################################
|
||||
EOF
|
||||
printf "${RESET}\n"
|
||||
printf "${C_RESET}\n"
|
||||
}
|
||||
|
||||
# 检查操作系统环境
|
||||
|
@ -41,13 +49,13 @@ checkOsVersion() {
|
|||
if (($1 == 1)); then
|
||||
platform=`uname -i`
|
||||
if [[ ${platform} != "x86_64" ]]; then
|
||||
printf "\n${RED}脚本仅支持 64 位操作系统!${RESET}\n"
|
||||
logError "脚本仅支持 64 位操作系统!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'`
|
||||
if [[ ${version} != 7 ]]; then
|
||||
printf "\n${RED}脚本仅支持 CentOS 7!${RESET}\n"
|
||||
logError "脚本仅支持 CentOS 7!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
@ -70,7 +78,7 @@ selectAndExecTask() {
|
|||
printFootInfo
|
||||
exit 0 ;;
|
||||
*)
|
||||
printf "\n${RED}输入项不支持!${RESET}\n"
|
||||
logWarn "输入项不支持!"
|
||||
selectAndExecTask ;;
|
||||
esac
|
||||
break
|
||||
|
@ -78,6 +86,7 @@ selectAndExecTask() {
|
|||
}
|
||||
|
||||
|
||||
######################################## MAIN ########################################
|
||||
# ------------------------------------------------------------------------------ main
|
||||
|
||||
checkOsVersion 1
|
||||
selectAndExecTask
|
||||
|
|
|
@ -1,30 +1,38 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 控制台颜色
|
||||
BLACK="\033[1;30m"
|
||||
RED="\033[1;31m"
|
||||
GREEN="\033[1;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
BLUE="\033[1;34m"
|
||||
PURPLE="\033[1;35m"
|
||||
CYAN="\033[1;36m"
|
||||
RESET="$(tput sgr0)"
|
||||
# ---------------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
# CentOS 常用软件一键安装脚本
|
||||
# @author Zhang Peng
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
printf "${BLUE}\n"
|
||||
# ------------------------------------------------------------------------------ libs
|
||||
# 装载其它库
|
||||
LINUX_SCRIPTS_DIR=$(cd `dirname $0`; pwd)
|
||||
|
||||
if [[ ! -x ${LINUX_SCRIPTS_DIR}/lib/utils.sh ]]; then
|
||||
logError "必要脚本库 ${LINUX_SCRIPTS_DIR}/lib/utils.sh 不存在!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source ${LINUX_SCRIPTS_DIR}/lib/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ functions
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
printf "${C_B_BLUE}\n"
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 欢迎使用 Dunwu Shell 软件安装脚本
|
||||
# 欢迎使用 CentOS 常用软件一键安装脚本
|
||||
# 适用于 Linux CentOS 环境
|
||||
# @author: Zhang Peng
|
||||
###################################################################################
|
||||
EOF
|
||||
printf "${RESET}\n"
|
||||
printf "${C_RESET}\n"
|
||||
}
|
||||
|
||||
# print menu
|
||||
printMenu() {
|
||||
printf "${PURPLE}"
|
||||
printf "${C_B_MAGENTA}"
|
||||
menus=( docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8 zookeeper zsh exit )
|
||||
for i in "${!menus[@]}"; do
|
||||
index=`expr ${i} + 1`
|
||||
|
@ -35,7 +43,7 @@ printMenu() {
|
|||
fi
|
||||
done
|
||||
|
||||
printf "\n\n${BLUE}请选择需要安装的软件:${RESET}"
|
||||
printf "\n\n${C_B_BLUE}请选择需要安装的软件:${C_RESET}"
|
||||
}
|
||||
|
||||
# exec shell to install soft
|
||||
|
@ -46,22 +54,24 @@ main() {
|
|||
no=`expr ${index} - 1`
|
||||
len=${#menus[*]}
|
||||
if [[ ${index} -gt ${len} ]]; then
|
||||
printf "${RED}输入项不支持!\n${RESET}"
|
||||
exit -1
|
||||
logWarn "输入项不支持!"
|
||||
exit 1
|
||||
fi
|
||||
key=${menus[$no]}
|
||||
if [[ ${key} == 'exit' ]]; then
|
||||
printf "${GREEN}退出 Dunwu 软件安装脚本。\n${RESET}"
|
||||
logInfo "退出软件安装脚本。"
|
||||
exit 0
|
||||
fi
|
||||
sh soft/${key}-install.sh
|
||||
printf "\n"
|
||||
main
|
||||
else
|
||||
printf "${RED}输入项不支持!\n${RESET}"
|
||||
exit -1
|
||||
logWarn "输入项不支持!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
# ------------------------------------------------------------------------------ main
|
||||
|
||||
printHeadInfo
|
||||
main
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 控制台颜色
|
||||
BLACK="\033[1;30m"
|
||||
RED="\033[1;31m"
|
||||
GREEN="\033[1;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
BLUE="\033[1;34m"
|
||||
PURPLE="\033[1;35m"
|
||||
CYAN="\033[1;36m"
|
||||
RESET="$(tput sgr0)"
|
||||
# ---------------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
# CentOS 环境初始化脚本
|
||||
# @author Zhang Peng
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
printf "${BLUE}\n"
|
||||
# ------------------------------------------------------------------------------ libs
|
||||
# 装载其它库
|
||||
LINUX_SCRIPTS_DIR=$(cd `dirname $0`; pwd)
|
||||
|
||||
if [[ ! -x ${LINUX_SCRIPTS_DIR}/lib/utils.sh ]]; then
|
||||
logError "必要脚本库 ${LINUX_SCRIPTS_DIR}/lib/utils.sh 不存在!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source ${LINUX_SCRIPTS_DIR}/lib/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ functions
|
||||
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
printf "${C_B_BLUE}\n"
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 欢迎使用 Dunwu Shell 环境初始化脚本(设置环境配置、安装基本的命令工具)
|
||||
|
@ -20,7 +28,8 @@ cat << EOF
|
|||
# @author: Zhang Peng
|
||||
###################################################################################
|
||||
EOF
|
||||
printf "${RESET}\n"
|
||||
printf "${C_RESET}\n"
|
||||
}
|
||||
|
||||
menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" )
|
||||
main() {
|
||||
|
@ -29,33 +38,34 @@ main() {
|
|||
do
|
||||
case ${item} in
|
||||
"替换yum镜像")
|
||||
sh ${path}/sys/change-yum-repo.sh
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/change-yum-repo.sh
|
||||
main ;;
|
||||
"安装基本的命令工具")
|
||||
sh ${path}/sys/install-tools.sh
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/install-tools.sh
|
||||
main ;;
|
||||
"安装常用libs")
|
||||
sh ${path}/sys/install-libs.sh
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/install-libs.sh
|
||||
main ;;
|
||||
"系统配置")
|
||||
sh ${path}/sys/sys-settings.sh ${path}/sys
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/sys-settings.sh ${LINUX_SCRIPTS_DIR}/sys
|
||||
main ;;
|
||||
"全部执行")
|
||||
sh ${path}/sys/change-yum-repo.sh
|
||||
sh ${path}/sys/install-tools.sh
|
||||
sh ${path}/sys/install-libs.sh
|
||||
sh ${path}/sys/sys-settings.sh ${path}/sys
|
||||
printf "${GREEN}执行完毕,退出。${RESET}\n" ;;
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/change-yum-repo.sh
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/install-tools.sh
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/install-libs.sh
|
||||
sh ${LINUX_SCRIPTS_DIR}/sys/sys-settings.sh ${LINUX_SCRIPTS_DIR}/sys
|
||||
logInfo "执行完毕,退出" ;;
|
||||
"退出")
|
||||
exit 0 ;;
|
||||
*)
|
||||
printf "${RED}输入项不支持!${RESET}\n"
|
||||
logWarn "输入项不支持!"
|
||||
main ;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
path=$(pwd)
|
||||
# ------------------------------------------------------------------------------ main
|
||||
|
||||
printHeadInfo
|
||||
main
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 构建 Docker 镜像 脚本
|
||||
# @author Zhang Peng
|
||||
# @since 2020/1/14
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# 装载其它库
|
||||
LINUX_SCRIPTS_LIB_DIR=`dirname ${BASH_SOURCE[0]}`
|
||||
source ${LINUX_SCRIPTS_LIB_DIR}/utils.sh
|
||||
|
||||
dockerBuild() {
|
||||
if [[ ! $1 ]] || [[ ! $2 ]] || [[ ! $3 ]]; then
|
||||
logError "you must input following params in order:"
|
||||
echo -e "${C_B_RED}"
|
||||
echo " (1) source"
|
||||
echo " (2) repository"
|
||||
echo " (3) tag"
|
||||
echo -e "\nEg. dockerBuild /home/workspace dunwu/dockerApp 0.0.1"
|
||||
echo -e "${C_RESET}"
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
local source=$1
|
||||
local repository=$2
|
||||
local tag=$3
|
||||
|
||||
dockerCheck ${source}
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
cd ${source}
|
||||
callAndLog docker build -t ${repository}:${tag} .
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
logError "docker build -t ${repository}:${tag} failed"
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
cd -
|
||||
}
|
||||
|
||||
dockerPush() {
|
||||
if [[ ! $1 ]] || [[ ! $2 ]]; then
|
||||
logError "you must input following params in order:"
|
||||
echo -e "${C_B_RED}"
|
||||
echo " (1) repository"
|
||||
echo " (2) tag"
|
||||
echo -e "\nEg. dockerBuild dunwu/dockerApp 0.0.1"
|
||||
echo -e "${C_RESET}"
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
local repository=$1
|
||||
local tag=$2
|
||||
|
||||
# 如果 docker 镜像已存在,则删除镜像
|
||||
local dockerHashId=$(docker image ls | grep ${repository} | grep ${tag} | awk '{print $3}')
|
||||
if [[ ! ${dockerHashId} ]]; then
|
||||
logInfo "try to delete existed image: ${repository}:${tag}"
|
||||
callAndLog docker rmi ${dockerHashId}
|
||||
fi
|
||||
|
||||
logInfo "try to push new image: ${repository}:${tag}"
|
||||
callAndLog docker push ${repository}:${tag}
|
||||
}
|
||||
|
||||
# 判断指定路径下是否为 docker 工程
|
||||
# @param $1: 第一个参数为 docker 项目路径
|
||||
dockerCheck() {
|
||||
local source=$1
|
||||
if [[ -d "${source}" ]]; then
|
||||
cd ${source}
|
||||
if [[ -f "${source}/Dockerfile" ]]; then
|
||||
return ${YES}
|
||||
else
|
||||
logError "Dockerfile is not exists"
|
||||
return ${NO}
|
||||
fi
|
||||
cd -
|
||||
return ${YES}
|
||||
else
|
||||
logError "${source} is not valid docker project"
|
||||
return ${NO}
|
||||
fi
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 常用变量库
|
||||
# @author Zhang Peng
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------ 颜色状态
|
||||
|
||||
# Regular Color
|
||||
C_BLACK="\033[0;30m"
|
||||
C_RED="\033[0;31m"
|
||||
C_GREEN="\033[0;32m"
|
||||
C_YELLOW="\033[0;33m"
|
||||
C_BLUE="\033[0;34m"
|
||||
C_MAGENTA="\033[0;35m"
|
||||
C_CYAN="\033[0;36m"
|
||||
C_WHITE="\033[0;37m"
|
||||
|
||||
# Bold Color
|
||||
C_B_BLACK="\033[1;30m"
|
||||
C_B_RED="\033[1;31m"
|
||||
C_B_GREEN="\033[1;32m"
|
||||
C_B_YELLOW="\033[1;33m"
|
||||
C_B_BLUE="\033[1;34m"
|
||||
C_B_MAGENTA="\033[1;35m"
|
||||
C_B_CYAN="\033[1;36m"
|
||||
C_B_WHITE="\033[1;37m"
|
||||
|
||||
# Underline Color
|
||||
C_U_BLACK="\033[4;30m"
|
||||
C_U_RED="\033[4;31m"
|
||||
C_U_GREEN="\033[4;32m"
|
||||
C_U_YELLOW="\033[4;33m"
|
||||
C_U_BLUE="\033[4;34m"
|
||||
C_U_MAGENTA="\033[4;35m"
|
||||
C_U_CYAN="\033[4;36m"
|
||||
C_U_WHITE="\033[4;37m"
|
||||
|
||||
# Background Color
|
||||
C_BG_BLACK="\033[40m"
|
||||
C_BG_RED="\033[41m"
|
||||
C_BG_GREEN="\033[42m"
|
||||
C_BG_YELLOW="\033[43m"
|
||||
C_BG_BLUE="\033[44m"
|
||||
C_BG_MAGENTA="\033[45m"
|
||||
C_BG_CYAN="\033[46m"
|
||||
C_BG_WHITE="\033[47m"
|
||||
|
||||
# Reset Color
|
||||
C_RESET="$(tput sgr0)"
|
||||
|
||||
# ------------------------------------------------------------------------------ 常用状态值
|
||||
|
||||
YES=0
|
||||
NO=1
|
||||
SUCCEED=0
|
||||
FAILED=1
|
||||
|
||||
# 显示打印日志的时间
|
||||
DATE=`date "+%Y-%m-%d %H:%M:%S"`
|
||||
# 那个用户在操作
|
||||
USER=$(whoami)
|
||||
|
||||
# ------------------------------------------------------------------------------ log
|
||||
|
||||
logInfo() {
|
||||
#($0脚本本身,$@将参数作为整体传输调用)
|
||||
echo "[${DATE}] [${USER}] [INFO] [$0] [$@] execute succeed." >> /var/log/shell.log
|
||||
}
|
||||
|
||||
logWarn() {
|
||||
#($0脚本本身,$@将参数作为整体传输调用)
|
||||
echo "[${DATE}] [${USER}] [WARN] [$0] [$@] execute succeed." >> /var/log/shell.log
|
||||
}
|
||||
|
||||
logError() {
|
||||
#($0脚本本身,$@将参数作为整体传输调用)
|
||||
echo "[${DATE}] [${USER}] [ERROR] [$0] [$@] execute failed." >> /var/log/shell.log
|
||||
}
|
||||
|
||||
printInfo() {
|
||||
echo -e "${C_B_GREEN}[INFO] $@${C_RESET}"
|
||||
}
|
||||
|
||||
printWarn() {
|
||||
echo -e "${C_B_YELLOW}[WARN] $@${C_RESET}"
|
||||
}
|
||||
|
||||
printError() {
|
||||
echo -e "${C_B_RED}[ERROR] $@${C_RESET}"
|
||||
}
|
||||
|
||||
callAndLog () {
|
||||
$*
|
||||
if [[ $? -eq ${SUCCEED} ]]; then
|
||||
logInfo "$@ succeed"
|
||||
echo -e "${C_B_GREEN}[INFO] [$0] [$@] execute succeed.${C_RESET}"
|
||||
else
|
||||
logError "$@ failed"
|
||||
echo -e "${C_B_RED}[ERROR] [$0] [$@] execute failed.${C_RESET}"
|
||||
fi
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# 装载其它库
|
||||
ROOT=`dirname ${BASH_SOURCE[0]}`
|
||||
source ${ROOT}/env.sh
|
||||
source ${ROOT}/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ 文件操作函数
|
||||
|
||||
|
|
|
@ -6,11 +6,27 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
|
||||
# 装载其它库
|
||||
ROOT=`dirname ${BASH_SOURCE[0]}`
|
||||
source ${ROOT}/env.sh
|
||||
LINUX_SCRIPTS_LIB_DIR=`dirname ${BASH_SOURCE[0]}`
|
||||
|
||||
if [[ ! -x ${LINUX_SCRIPTS_LIB_DIR}/utils.sh ]]; then
|
||||
logError "必要脚本库 ${LINUX_SCRIPTS_LIB_DIR}/utils.sh 不存在!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source ${LINUX_SCRIPTS_LIB_DIR}/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ git 操作函数
|
||||
|
||||
GIT_LOCAL_BRANCH=
|
||||
getGitLocalBranch() {
|
||||
GIT_LOCAL_BRANCH=$(git symbolic-ref -q --short HEAD)
|
||||
}
|
||||
|
||||
GIT_ORIGIN_BRANCH=
|
||||
getGitOriginBranch() {
|
||||
GIT_ORIGIN_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}")
|
||||
}
|
||||
|
||||
# 检查指定的路径是不是一个 git 项目
|
||||
checkGit() {
|
||||
local source=$1
|
||||
|
@ -21,9 +37,7 @@ checkGit() {
|
|||
rm -rf gitstatus.tmp
|
||||
fi
|
||||
|
||||
# (2)判断是否存在 .git 目录
|
||||
if [[ -d "./.git" ]]; then
|
||||
# (3)判断git是否可用
|
||||
# (2)判断git是否可用
|
||||
git status &> gitstatus.tmp
|
||||
local gitStatus=false
|
||||
grep -iwq 'not a git repository' gitstatus.tmp && gitStatus=false || gitStatus=true
|
||||
|
@ -33,12 +47,11 @@ checkGit() {
|
|||
else
|
||||
return ${NO}
|
||||
fi
|
||||
fi
|
||||
|
||||
return ${NO}
|
||||
fi
|
||||
|
||||
printf "${C_B_YELLOW}${source} is invalid dir.${C_RESET}\n"
|
||||
logError "${source} is invalid dir."
|
||||
return ${NO}
|
||||
}
|
||||
|
||||
|
@ -54,18 +67,18 @@ cloneOrPullGit() {
|
|||
local root=$5
|
||||
|
||||
if [[ ! ${repository} ]] || [[ ! ${group} ]] || [[ ! ${project} ]] || [[ ! ${branch} ]] || [[ ! ${root} ]]; then
|
||||
printf "${C_B_YELLOW}Please input root, group, project, branch.${C_RESET}\n"
|
||||
logError "Please input root, group, project, branch."
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
if [[ ! -d "${root}" ]]; then
|
||||
printf "${C_B_YELLOW}${root} is not directory.${C_RESET}\n"
|
||||
logError "${root} is not directory."
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
local source=${root}/${group}/${project}
|
||||
printf "${C_B_MAGENTA}project directory is ${source}.${C_RESET}\n"
|
||||
printf "${C_B_MAGENTA}git url is ${repository}:${group}/${project}.git.${C_RESET}\n"
|
||||
logInfo "project directory is ${source}."
|
||||
logInfo "git url is ${repository}:${group}/${project}.git."
|
||||
mkdir -p ${root}/${group}
|
||||
|
||||
checkGit ${source}
|
||||
|
@ -75,44 +88,46 @@ cloneOrPullGit() {
|
|||
|
||||
git checkout -f ${branch}
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
printf "${C_B_RED}<<<< git checkout ${branch} failed.${C_RESET}\n"
|
||||
logError "<<<< git checkout ${branch} failed."
|
||||
return ${FAILED}
|
||||
fi
|
||||
printf "${C_B_GREEN}git checkout ${branch} succeed.${C_RESET}\n"
|
||||
logInfo "git checkout ${branch} succeed."
|
||||
|
||||
git reset --hard
|
||||
getGitOriginBranch
|
||||
git fetch --all
|
||||
git reset --hard ${GIT_ORIGIN_BRANCH}
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
printf "${C_B_RED}<<<< git reset --hard failed.${C_RESET}\n"
|
||||
logError "<<<< git reset --hard ${GIT_ORIGIN_BRANCH} failed."
|
||||
return ${FAILED}
|
||||
fi
|
||||
printf "${C_B_GREEN}git reset --hard succeed.${C_RESET}\n"
|
||||
logInfo "git reset --hard ${GIT_ORIGIN_BRANCH} succeed."
|
||||
|
||||
git pull
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
printf "${C_B_RED}<<<< git pull failed.${C_RESET}\n"
|
||||
logError "<<<< git pull failed."
|
||||
return ${FAILED}
|
||||
fi
|
||||
printf "${C_B_GREEN}git pull succeed.${C_RESET}\n"
|
||||
logInfo "git pull succeed."
|
||||
else
|
||||
# 如果 ${source} 不是 git 项目,执行 clone 操作
|
||||
|
||||
git clone "${repository}:${group}/${project}.git" ${source}
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
printf "${C_B_RED}<<<< git clone ${project} failed.${C_RESET}\n"
|
||||
logError "<<<< git clone ${project} failed."
|
||||
return ${FAILED}
|
||||
fi
|
||||
printf "${C_B_GREEN}git clone ${project} succeed.${C_RESET}\n"
|
||||
logInfo "git clone ${project} succeed."
|
||||
|
||||
cd ${source} || return ${FAILED}
|
||||
|
||||
git checkout -f ${branch}
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
printf "${C_B_RED}<<<< git checkout ${branch} failed.${C_RESET}\n"
|
||||
logError "<<<< git checkout ${branch} failed."
|
||||
return ${FAILED}
|
||||
fi
|
||||
printf "${C_B_GREEN}git checkout ${branch} succeed.${C_RESET}\n"
|
||||
logInfo "git checkout ${branch} succeed."
|
||||
fi
|
||||
|
||||
printf "${C_B_GREEN}Clone or pull git project [$2/$3:$4] succeed.${C_RESET}\n"
|
||||
logInfo "Clone or pull git project [$2/$3:$4] succeed."
|
||||
return ${SUCCEED}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# ------------------------------------------------------------------------------ env preparation
|
||||
# load libs
|
||||
CURRENT_PATH=`dirname ${BASH_SOURCE[0]}`
|
||||
source ${CURRENT_PATH}/env.sh
|
||||
source ${CURRENT_PATH}/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ functions
|
||||
|
||||
|
|
|
@ -6,31 +6,52 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
|
||||
# 装载其它库
|
||||
ROOT=`dirname ${BASH_SOURCE[0]}`
|
||||
source ${ROOT}/env.sh
|
||||
LINUX_SCRIPTS_LIB_DIR=`dirname ${BASH_SOURCE[0]}`
|
||||
|
||||
mavenBuild() {
|
||||
if [[ ! -x ${LINUX_SCRIPTS_LIB_DIR}/utils.sh ]]; then
|
||||
echo "必要脚本库 ${LINUX_SCRIPTS_LIB_DIR}/utils.sh 不存在!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source ${LINUX_SCRIPTS_LIB_DIR}/utils.sh
|
||||
|
||||
# 执行 maven 操作
|
||||
# @param $1: 第一个参数为 maven 项目路径
|
||||
# @param $2: 第二个参数为 maven 操作,如 package、install、deploy
|
||||
# @param $3: 第三个参数为 maven profile 【非必填】
|
||||
mavenOperation() {
|
||||
local source=$1
|
||||
mavenCheck $1
|
||||
local lifecycle=$2
|
||||
local profile=$3
|
||||
|
||||
mavenCheck ${source}
|
||||
if [[ "${SUCCEED}" != "$?" ]]; then
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
if [[ -d "${source}" ]]; then
|
||||
cd ${source}
|
||||
if [[ -f "${source}/settings.xml" ]]; then
|
||||
callAndLog "mvn clean install -B -U -s ${source}/settings.xml -Dmaven.test.skip=true"
|
||||
else
|
||||
callAndLog "mvn clean install -DskipTests=true -B -U"
|
||||
fi
|
||||
cd -
|
||||
return ${SUCCEED}
|
||||
else
|
||||
printf "${C_B_RED}please input valid maven project path.${C_RESET}\n"
|
||||
if [[ ! "${lifecycle}" ]]; then
|
||||
logError "please input maven lifecycle"
|
||||
return ${FAILED}
|
||||
fi
|
||||
|
||||
local mvnCli="mvn clean ${lifecycle} -DskipTests=true -B -U"
|
||||
|
||||
if [[ ${profile} ]]; then
|
||||
mvnCli="${mvnCli} -P${profile}"
|
||||
fi
|
||||
|
||||
cd ${source}
|
||||
if [[ -f "${source}/settings.xml" ]]; then
|
||||
mvnCli="${mvnCli} -s ${source}/settings.xml"
|
||||
fi
|
||||
|
||||
callAndLog "${mvnCli}"
|
||||
cd -
|
||||
return ${SUCCEED}
|
||||
}
|
||||
|
||||
# 判断指定路径下是否为 maven 工程
|
||||
# @param $1: 第一个参数为 maven 项目路径
|
||||
mavenCheck() {
|
||||
local source=$1
|
||||
if [[ -d "${source}" ]]; then
|
||||
|
@ -38,29 +59,13 @@ mavenCheck() {
|
|||
if [[ -f "${source}/pom.xml" ]]; then
|
||||
return ${YES}
|
||||
else
|
||||
printf "${C_B_RED}pom.xml is not exists.${C_RESET}\n"
|
||||
logError "pom.xml is not exists"
|
||||
return ${NO}
|
||||
fi
|
||||
cd -
|
||||
return ${YES}
|
||||
else
|
||||
printf "${C_B_RED}please input valid maven project path.${C_RESET}\n"
|
||||
logError "please input valid maven project path"
|
||||
return ${NO}
|
||||
fi
|
||||
}
|
||||
|
||||
##################################### MAIN #####################################
|
||||
printf "\n${C_B_GREEN}>>>> maven build begin.${C_RESET}\n\n"
|
||||
|
||||
printf "${C_B_MAGENTA}Current path is ${ROOT}.${C_RESET}\n"
|
||||
|
||||
mavenBuild ${ROOT}/..
|
||||
r1=$?
|
||||
|
||||
if [[ "${r1}" == "${SUCCEED}" ]]; then
|
||||
printf "\n${C_B_GREEN}<<<< maven build succeed.${C_RESET}\n\n"
|
||||
exit ${SUCCEED}
|
||||
else
|
||||
printf "\n${C_B_RED}<<<< maven build failed.${C_RESET}\n\n"
|
||||
exit ${FAILED}
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Shell Utils
|
||||
# @author Zhang Peng
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------ 颜色状态
|
||||
|
||||
# Regular Color
|
||||
export C_BLACK="\033[0;30m"
|
||||
export C_RED="\033[0;31m"
|
||||
export C_GREEN="\033[0;32m"
|
||||
export C_YELLOW="\033[0;33m"
|
||||
export C_BLUE="\033[0;34m"
|
||||
export C_MAGENTA="\033[0;35m"
|
||||
export C_CYAN="\033[0;36m"
|
||||
export C_WHITE="\033[0;37m"
|
||||
|
||||
# Bold Color
|
||||
export C_B_BLACK="\033[1;30m"
|
||||
export C_B_RED="\033[1;31m"
|
||||
export C_B_GREEN="\033[1;32m"
|
||||
export C_B_YELLOW="\033[1;33m"
|
||||
export C_B_BLUE="\033[1;34m"
|
||||
export C_B_MAGENTA="\033[1;35m"
|
||||
export C_B_CYAN="\033[1;36m"
|
||||
export C_B_WHITE="\033[1;37m"
|
||||
|
||||
# Underline Color
|
||||
export C_U_BLACK="\033[4;30m"
|
||||
export C_U_RED="\033[4;31m"
|
||||
export C_U_GREEN="\033[4;32m"
|
||||
export C_U_YELLOW="\033[4;33m"
|
||||
export C_U_BLUE="\033[4;34m"
|
||||
export C_U_MAGENTA="\033[4;35m"
|
||||
export C_U_CYAN="\033[4;36m"
|
||||
export C_U_WHITE="\033[4;37m"
|
||||
|
||||
# Background Color
|
||||
export C_BG_BLACK="\033[40m"
|
||||
export C_BG_RED="\033[41m"
|
||||
export C_BG_GREEN="\033[42m"
|
||||
export C_BG_YELLOW="\033[43m"
|
||||
export C_BG_BLUE="\033[44m"
|
||||
export C_BG_MAGENTA="\033[45m"
|
||||
export C_BG_CYAN="\033[46m"
|
||||
export C_BG_WHITE="\033[47m"
|
||||
|
||||
# Reset Color
|
||||
export C_RESET="$(tput sgr0)"
|
||||
|
||||
# ------------------------------------------------------------------------------ 常用状态值
|
||||
|
||||
export YES=0
|
||||
export NO=1
|
||||
export SUCCEED=0
|
||||
export FAILED=1
|
||||
|
||||
# ------------------------------------------------------------------------------ 常用状态值
|
||||
|
||||
# 显示打印日志的时间
|
||||
DATE=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
# 那个用户在操作
|
||||
USER=$(whoami)
|
||||
# 日志路径
|
||||
LOG_DIR=/var/log/dunwu
|
||||
LOG_PATH=${LOG_DIR}/shell.log
|
||||
|
||||
createLogFileIfNotExists() {
|
||||
if [[ ! -f "${LOG_PATH}" ]]; then
|
||||
sudo mkdir -p "${LOG_DIR}"
|
||||
touch "${LOG_PATH}"
|
||||
fi
|
||||
}
|
||||
|
||||
logInfo() {
|
||||
echo -e "${C_B_GREEN}[INFO] $@${C_RESET}"
|
||||
createLogFileIfNotExists
|
||||
echo "[${DATE}] [${USER}] [INFO] [$0] [$@] execute succeed." >> "${LOG_PATH}"
|
||||
}
|
||||
|
||||
logWarn() {
|
||||
echo -e "${C_B_YELLOW}[WARN] $@${C_RESET}"
|
||||
createLogFileIfNotExists
|
||||
echo "[${DATE}] [${USER}] [WARN] [$0] [$@] execute succeed." >> "${LOG_PATH}"
|
||||
}
|
||||
|
||||
logError() {
|
||||
echo -e "${C_B_RED}[ERROR] $@${C_RESET}"
|
||||
createLogFileIfNotExists
|
||||
echo "[${DATE}] [${USER}] [ERROR] [$0] [$@] execute failed." >> "${LOG_PATH}"
|
||||
}
|
||||
|
||||
printInfo() {
|
||||
echo -e "${C_B_GREEN}[INFO] $@${C_RESET}"
|
||||
}
|
||||
|
||||
printWarn() {
|
||||
echo -e "${C_B_YELLOW}[WARN] $@${C_RESET}"
|
||||
}
|
||||
|
||||
printError() {
|
||||
echo -e "${C_B_RED}[ERROR] $@${C_RESET}"
|
||||
}
|
||||
|
||||
callAndLog () {
|
||||
$*
|
||||
if [[ $? -eq ${SUCCEED} ]]; then
|
||||
logInfo "$@ succeed"
|
||||
echo -e "${C_B_GREEN}[INFO] [$0] [$@] execute succeed.${C_RESET}"
|
||||
return ${SUCCEED}
|
||||
else
|
||||
logError "$@ failed"
|
||||
echo -e "${C_B_RED}[ERROR] [$0] [$@] execute failed.${C_RESET}"
|
||||
return ${FAILED}
|
||||
fi
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# 装载其它库
|
||||
source ../lib/env.sh
|
||||
source ../lib/utils.sh
|
||||
|
||||
# ------------------------------------------------------------------------------ 颜色变量测试
|
||||
printf "${C_B_YELLOW}测试彩色打印:${C_RESET}\n"
|
||||
|
@ -11,7 +11,7 @@ printf "${C_RED}Hello.${C_RESET}\n"
|
|||
printf "${C_GREEN}Hello.${C_RESET}\n"
|
||||
printf "${C_YELLOW}Hello.${C_RESET}\n"
|
||||
printf "${C_BLUE}Hello.${C_RESET}\n"
|
||||
printf "${C_PURPLE}Hello.${C_RESET}\n"
|
||||
printf "${C_MAGENTA}Hello.${C_RESET}\n"
|
||||
printf "${C_CYAN}Hello.${C_RESET}\n"
|
||||
|
||||
printf "${C_B_BLACK}Hello.${C_RESET}\n"
|
||||
|
@ -19,7 +19,7 @@ printf "${C_B_RED}Hello.${C_RESET}\n"
|
|||
printf "${C_B_GREEN}Hello.${C_RESET}\n"
|
||||
printf "${C_B_YELLOW}Hello.${C_RESET}\n"
|
||||
printf "${C_B_BLUE}Hello.${C_RESET}\n"
|
||||
printf "${C_B_PURPLE}Hello.${C_RESET}\n"
|
||||
printf "${C_B_MAGENTA}Hello.${C_RESET}\n"
|
||||
printf "${C_B_CYAN}Hello.${C_RESET}\n"
|
||||
|
||||
printf "${C_U_BLACK}Hello.${C_RESET}\n"
|
||||
|
@ -27,7 +27,7 @@ printf "${C_U_RED}Hello.${C_RESET}\n"
|
|||
printf "${C_U_GREEN}Hello.${C_RESET}\n"
|
||||
printf "${C_U_YELLOW}Hello.${C_RESET}\n"
|
||||
printf "${C_U_BLUE}Hello.${C_RESET}\n"
|
||||
printf "${C_U_PURPLE}Hello.${C_RESET}\n"
|
||||
printf "${C_U_MAGENTA}Hello.${C_RESET}\n"
|
||||
printf "${C_U_CYAN}Hello.${C_RESET}\n"
|
||||
|
||||
printf "${C_BG_BLACK}Hello.${C_RESET}\n"
|
||||
|
@ -35,6 +35,6 @@ printf "${C_BG_RED}Hello.${C_RESET}\n"
|
|||
printf "${C_BG_GREEN}Hello.${C_RESET}\n"
|
||||
printf "${C_BG_YELLOW}Hello.${C_RESET}\n"
|
||||
printf "${C_BG_BLUE}Hello.${C_RESET}\n"
|
||||
printf "${C_BG_PURPLE}Hello.${C_RESET}\n"
|
||||
printf "${C_BG_MAGENTA}Hello.${C_RESET}\n"
|
||||
printf "${C_BG_CYAN}Hello.${C_RESET}\n"
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source ../lib/utils.sh
|
||||
source ../lib/git.sh
|
||||
|
||||
##################################### MAIN #####################################
|
||||
|
@ -9,13 +10,18 @@ else
|
|||
DIR=$(pwd)
|
||||
fi
|
||||
|
||||
printf "${C_B_BLUE}Current path is: ${DIR} ${C_RESET}\n"
|
||||
printInfo "Current path is: ${DIR}."
|
||||
|
||||
# 判断是否为 git 项目
|
||||
checkGit ${DIR}
|
||||
if [[ "${YES}" == "$?" ]]; then
|
||||
printf "${C_B_GREEN}${DIR} is git project.${C_RESET}\n"
|
||||
exit ${YES}
|
||||
printInfo "${DIR} is git project."
|
||||
else
|
||||
printf "${C_B_RED}${DIR} is not git project.${C_RESET}\n"
|
||||
exit ${NO}
|
||||
printError "${DIR} is not git project."
|
||||
fi
|
||||
|
||||
# 获取 git 分支
|
||||
getGitLocalBranch
|
||||
printInfo "git local branch: ${GIT_LOCAL_BRANCH}"
|
||||
getGitOriginBranch
|
||||
printInfo "git origin branch: ${GIT_ORIGIN_BRANCH}"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source ../lib/env.sh
|
||||
source ../lib/utils.sh
|
||||
source ../lib/git.sh
|
||||
|
||||
doCloneOrPullGit() {
|
||||
|
|
Loading…
Reference in New Issue