做了一个简易的git 代码自动部署脚本

项目是THINKPHP写的 用了 oschina git 进行版本管理。

公网服务器是CentOS。每次用FTP上传很麻烦。

所以想到了在服务器上安装一个GIT进行 pull代码。因为我的远程服务器数据库和本地不一样,所以代码pull后还需要修改 几个config.php数据库配置文件。

所以想再git 代码更新后,要自动执行config.php文件的替换或者修改。

其中看到这里讨论http://www.v2ex.com/t/81173  git hook

然后看了下比较麻烦。也看不懂。

所以就自己写了一个SH脚本 效果非常不错。分享出来。

首先再服务器中建立一个文件夹,把项目代码clone下来。

git clone https://caomenglong@git.oschina.net/yfsoft/GR_Operate.git

代码仓库地址:

~/codes/ec.abc.com/GR_Operate

项目部署目录

/www/web/abc/public_html

test.sh

#!/bin/sh
a="Please input your git account password"
echo $a
cd ~/codes/ec.abc.com/GR_Operate
git pull
cd /www/web/abc/public_html
rm -rf *
cp -r ~/codes/ec.abc.com/GR_Operate/* /www/web/abc/public_html
rm -rf /www/web/abc/public_html/Application/Common/Conf/config.php
rm -rf /www/web/abc/public_html/Application/User/Conf/config.php
cp /root/codes/ec.abc.com/needcopy/common_config.php /www/web/abc/public_html/Application/Common/Conf/config.php
cp /root/codes/ec.abc.com/needcopy/user_config.php /www/web/abc/public_html/Application/User/Conf/config.php
chown -R www *
chown -R :www *
echo "git pull success and cpoy codes to www folder done "
echo "SUCCESS!!"

原理很简单。先进入git目录 执行 git pull 更新代码

然后进入网站WWW目录删除所有的代码。

然后复制git目录下的代码到www目录下。

删除2个config.php文件,复制修改好的文件到相应目录下。

最后修改所有的文件和文件夹加入 用户权限和用户组权限。


使用方法很简单

./test.sh


转载于:https://my.oschina.net/caomenglong/blog/472665

Git指令的Shell脚本,能够快速便捷地管理Git库,包括添加修改、提交修改、显示库状态、推送到远程库、从远程库更新到本地、版本恢复等操作。 使用方法: 1. 在Linux系统中,将本文件放在Git库目录下,利用Shell运行本文件; 2.在windows系统中,需下载安装与操作系统相对应的Git软件,并将本文件放在Git库目录下,双击即可运行。 运行示例: Please choose the first letter of options. [Add|Commit|Diff|Fetch|Exit|Help|Log|Push|User|Reset|Status]? h A: Add all changes to repository. C: Commit all changes to repository. D: Show differences between current version with HEAD->. E: Exit shell script. F: Fetch origin/master and merge. L: Show latest two-weeks logs of repository. P: Push commissions to origin/master. U: User command mode(Press ‘Enter’ to exit). R: Reset current version according version_id. S: Show status of repository. Please choose the first letter of options. [Add|Commit|Diff|Fetch|Exit|Help|Log|Push|User|Reset|Status]? s On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: Git.sh modified: PyNote/PyNote_2.md no changes added to commit (use "git add" and/or "git commit -a") Please choose the first letter of options. [Add|Commit|Diff|Fetch|Exit|Help|Log|Push|User|Reset|Status]? a On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) modified: Git.sh modified: PyNote/PyNote_2.md
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值