mirror of
https://github.com/dunwu/linux-tutorial.git
synced 2024-04-15 19:55:24 +08:00
✨ 添加开发常用脚本
This commit is contained in:
parent
0198e10b70
commit
a8fc56f7da
@ -1,39 +1,70 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
# 启动退出开关:当执行命令返回非0(0表示成功)状态码时,脚本退出执行。
|
||||||
# 次脚本适用于 Centos/RedHat
|
# 次脚本适用于 Centos/RedHat
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
init() {
|
|
||||||
echo "${IP} 机器环境部署开始" |tee ${DEPLOY_LOG_PATH}
|
|
||||||
touch ${DEPLOY_LOG_PATH}
|
|
||||||
chmod 777 ${DEPLOY_LOG_PATH}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 获取当前机器 IP
|
# 获取当前机器 IP
|
||||||
IP="127.0.0.1"
|
IP=""
|
||||||
getDeviceIp() {
|
getDeviceIp() {
|
||||||
IP=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`
|
IP=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`
|
||||||
if [ "$IP" == "" ]; then
|
if [ "$IP" == "" ]
|
||||||
IP=`ifconfig ens32 | grep "inet"|grep "broadcast" | awk '{ print $2}' | awk -F: '{print $1}'`
|
then
|
||||||
|
IP=`ifconfig ens32 | grep "inet"|grep "broadcast" | awk '{ print $2}' | awk -F: '{print $1}'`
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${IP} 机器环境部署开始" |tee ${DEPLOY_LOG_PATH}
|
||||||
|
if [ "$IP" == "" ]
|
||||||
|
then
|
||||||
|
IP=`echo $1`
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${IP}" == "" ]
|
||||||
|
then
|
||||||
|
echo " "
|
||||||
|
echo " 请输入服务器IP地址................ "
|
||||||
|
echo " "
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
touch ${DEPLOY_LOG_PATH}
|
||||||
|
chmod 777 ${DEPLOY_LOG_PATH}
|
||||||
installGit() {
|
installGit() {
|
||||||
echo "安装 git" |tee ${DEPLOY_LOG_PATH}
|
echo "安装 git" |tee ${DEPLOY_LOG_PATH}
|
||||||
|
yum install -y git-core
|
||||||
yum install -y git
|
yum install -y git
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyXyzdeploy() {
|
||||||
|
echo "克隆 xyzdeploy 项目到本地" | tee ${DEPLOY_LOG_PATH}
|
||||||
|
rm -rf ${SOFTWARE_ROOT}*
|
||||||
|
rm -rf ${XYZDEPLOY_ROOT}
|
||||||
|
git clone ssh://git@git.xyz.cn:10022/dream/xyzdeploy.git ${XYZDEPLOY_ROOT}
|
||||||
|
chmod -R 755 ${XYZDEPLOY_ROOT}/*
|
||||||
|
cp -rf ${XYZDEPLOY_ROOT}/software ${SOFTWARE_ROOT}
|
||||||
|
cp -rf ${XYZDEPLOY_ROOT}/config/ /home/xyz/
|
||||||
|
cp -rf ${XYZDEPLOY_ROOT}/script/ /home/xyz/
|
||||||
|
|
||||||
|
sed -i 's/127.0.0.1/'"${IP}"'/g' /home/xyz/config/nginx/vmhosts/*.conf
|
||||||
|
}
|
||||||
|
|
||||||
initEnviromentConfig() {
|
initEnviromentConfig() {
|
||||||
echo "修改环境配置文件 profile 和 hosts" | tee ${DEPLOY_LOG_PATH}
|
echo "修改环境配置文件 profile 和 hosts" | tee ${DEPLOY_LOG_PATH}
|
||||||
if [ ! -f /etc/profile.bak ]
|
if [ ! -f /etc/profile.bak ]
|
||||||
then
|
then
|
||||||
cp /etc/profile /etc/profile.bak
|
cp -f /etc/profile /etc/profile.bak
|
||||||
fi
|
fi
|
||||||
cd ${TMP_PATH}
|
cp -f ${XYZDEPLOY_ROOT}/config/enviroment/profile /etc/profile
|
||||||
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://github.com/dunwu/linux-notes/blob/master/codes/deploy/profile
|
|
||||||
cat ${TMP_PATH}/profile >> /etc/profile
|
|
||||||
rm -rf ${TMP_PATH}/profile
|
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
|
|
||||||
|
if [ ! -f /etc/hosts.bak ]
|
||||||
|
then
|
||||||
|
cp -f /etc/hosts /etc/hosts.bak
|
||||||
|
fi
|
||||||
|
cp -f ${XYZDEPLOY_ROOT}/config/enviroment/hosts /etc/hosts
|
||||||
|
sed -i 's/0.0.0.0/'"${IP}"'/g' /etc/hosts
|
||||||
}
|
}
|
||||||
|
|
||||||
installJava() {
|
installJava() {
|
||||||
@ -79,13 +110,19 @@ installNginx() {
|
|||||||
installNodejsAndNvm() {
|
installNodejsAndNvm() {
|
||||||
echo "安装 Nvm 和 Nodejs" | tee ${DEPLOY_LOG_PATH}
|
echo "安装 Nvm 和 Nodejs" | tee ${DEPLOY_LOG_PATH}
|
||||||
rm -rf /home/admin/.nvm
|
rm -rf /home/admin/.nvm
|
||||||
|
|
||||||
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm
|
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm
|
||||||
source ~/.nvm/nvm.sh
|
source ~/.nvm/nvm.sh
|
||||||
|
|
||||||
|
# 使用 nvm 安装 Node 指定版本
|
||||||
nvm install 0.10.48
|
nvm install 0.10.48
|
||||||
}
|
}
|
||||||
|
|
||||||
|
installNtp() {
|
||||||
|
yum install -y ntp
|
||||||
|
vi /etc/crontab
|
||||||
|
echo "*/30 * * * * /usr/local/bin/ntpdate 192.168.16.182" | tee /etc/crontab
|
||||||
|
}
|
||||||
|
|
||||||
shutdownFirewall() {
|
shutdownFirewall() {
|
||||||
echo "************************关闭防火墙************************" |tee -a /home/depoly.log
|
echo "************************关闭防火墙************************" |tee -a /home/depoly.log
|
||||||
/etc/init.d/iptables stop
|
/etc/init.d/iptables stop
|
||||||
@ -93,22 +130,28 @@ shutdownFirewall() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPrivilegeForUserIns() {
|
setPrivilegeForUserIns() {
|
||||||
userdel zp
|
userdel INS
|
||||||
groupdel coder
|
groupdel INS
|
||||||
groupadd coder
|
groupadd INS
|
||||||
useradd -g coder zp
|
useradd -g INS INS
|
||||||
chown -R coder.zp /home/zp
|
mkdir -p /search/statistics
|
||||||
chown -R coder.zp /opt/
|
mkdir -p /home/mic
|
||||||
chown -R coder.zp /tmp/
|
mkdir -p /home/INS/logs
|
||||||
|
chown -R INS.INS /home/mic
|
||||||
|
chown -R INS.INS /search/
|
||||||
|
chown -R INS.INS /home/INS/
|
||||||
|
chown -R INS.INS /opt/
|
||||||
|
chown -R INS.INS /tmp/
|
||||||
}
|
}
|
||||||
##############################__MAIN__########################################
|
##############################__MAIN__########################################
|
||||||
DEPLOY_LOG_PATH=/home/zp/deploy.log
|
DEPLOY_LOG_PATH=/home/zp/log/deploy.log
|
||||||
TMP_PATH=/home/zp/
|
XYZDEPLOY_ROOT=/home/xyz/source/xyzdeploy
|
||||||
SOFTWARE_PATH=/usr/lib
|
SOFTWARE_ROOT=/opt/software
|
||||||
|
|
||||||
init
|
init
|
||||||
getDeviceIp
|
getDeviceIp
|
||||||
installGit
|
installGit
|
||||||
|
copyXyzdeploy
|
||||||
initEnviromentConfig
|
initEnviromentConfig
|
||||||
installJava
|
installJava
|
||||||
installGcc
|
installGcc
|
||||||
@ -118,5 +161,6 @@ installPcre
|
|||||||
installNginx
|
installNginx
|
||||||
installMaven
|
installMaven
|
||||||
installNodejsAndNvm
|
installNodejsAndNvm
|
||||||
|
installNtp
|
||||||
shutdownFirewall
|
shutdownFirewall
|
||||||
setPrivilegeForUserIns
|
setPrivilegeForUserIns
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# zp 源码根目录
|
|
||||||
SOURCE_PATH=/home/zp/source
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# 检查脚本参数,如必要参数未传入,退出脚本。
|
# 检查脚本参数,如必要参数未传入,退出脚本。
|
||||||
#
|
#
|
||||||
checkInput() {
|
checkInput() {
|
||||||
if [ "${repository}" == "" ] || [ "${branch}" == "" ];
|
if [ "${repository}" == "" ] || [ "${branch}" == "" ]; then
|
||||||
then
|
echo "请输入脚本参数:repository branch [source] [target]"
|
||||||
echo "请输入脚本参数:repository branch target"
|
echo " repository: git 仓储(必填)。"
|
||||||
echo " repository: git 仓储(必填)。如 apollo"
|
echo " branch: git 分支(必填)。如 master/develop"
|
||||||
echo " branch: git 分支(必填)。如 develop, master"
|
echo " source: 代码存放目录。默认为/home/zp/source。"
|
||||||
echo " target: 代码存放目录。默认为脚本所在目录。"
|
echo " target: 代码存放目录。默认为脚本所在目录。"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -23,8 +20,8 @@ checkInput() {
|
|||||||
gitok=false
|
gitok=false
|
||||||
isGitExist() {
|
isGitExist() {
|
||||||
cd ${SOURCE_PATH}
|
cd ${SOURCE_PATH}
|
||||||
if [ -d "./${repository}/${target}" ]; then
|
if [ -d "${SOURCE_PATH}/${repository}/${target}" ]; then
|
||||||
cd ./${repository}/${target}
|
cd ${SOURCE_PATH}/${repository}/${target}
|
||||||
#(1)删除git状态零时文件
|
#(1)删除git状态零时文件
|
||||||
if [ -f "gitstatus.tmp" ]; then
|
if [ -f "gitstatus.tmp" ]; then
|
||||||
rm -rf gitstatus.tmp
|
rm -rf gitstatus.tmp
|
||||||
@ -46,8 +43,11 @@ isGitExist() {
|
|||||||
# 如果 git 版本库存在(根据 ${gitok} 值),执行 fetch 操作;反之,执行 clone 操作。
|
# 如果 git 版本库存在(根据 ${gitok} 值),执行 fetch 操作;反之,执行 clone 操作。
|
||||||
#
|
#
|
||||||
doFetchOrClone() {
|
doFetchOrClone() {
|
||||||
|
if [ ! -d "${SOURCE_PATH}" ]; then
|
||||||
|
mkdir -p ${SOURCE_PATH}
|
||||||
|
fi
|
||||||
if ${gitok}; then
|
if ${gitok}; then
|
||||||
cd ${target}
|
cd ${SOURCE_PATH}/${repository}/${target}
|
||||||
git reset --hard
|
git reset --hard
|
||||||
git clean -ffdx
|
git clean -ffdx
|
||||||
git fetch
|
git fetch
|
||||||
@ -55,9 +55,9 @@ doFetchOrClone() {
|
|||||||
else
|
else
|
||||||
#删除所有内容,便于重新进行git clone
|
#删除所有内容,便于重新进行git clone
|
||||||
rm -rf ${repository}
|
rm -rf ${repository}
|
||||||
git clone --no-checkout ${repository} ${target}
|
git clone --no-checkout git@github.com:${ACCOUNT}/${repository}.git ${SOURCE_PATH}/${repository}/${target}
|
||||||
echo "git clone ${repository} remote repository 到本地成功"
|
echo "git clone ${repository} remote repository 到本地成功"
|
||||||
cd ${target}
|
cd ${SOURCE_PATH}/${repository}/${target}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,9 +81,19 @@ doCheckout() {
|
|||||||
|
|
||||||
##############################__MAIN__########################################
|
##############################__MAIN__########################################
|
||||||
export LANG="zh_CN.UTF-8"
|
export LANG="zh_CN.UTF-8"
|
||||||
|
ACCOUNT=dunwu
|
||||||
|
SOURCE_PATH=/home/zp/source
|
||||||
|
|
||||||
|
# 必填输入参数
|
||||||
repository=`echo $1`
|
repository=`echo $1`
|
||||||
branch=`echo $2`
|
branch=`echo $2`
|
||||||
target=`echo $3`
|
|
||||||
|
# 可选输入参数
|
||||||
|
source=`echo $3`
|
||||||
|
target=`echo $4`
|
||||||
|
if [ "${source}" != "" ]; then
|
||||||
|
SOURCE_PATH=${source}
|
||||||
|
fi
|
||||||
|
|
||||||
# 0. 检查传入的参数
|
# 0. 检查传入的参数
|
||||||
checkInput
|
checkInput
|
Loading…
Reference in New Issue
Block a user