This repository has been archived by the owner on May 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
update.sh
executable file
·128 lines (103 loc) · 2.58 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Latest-laravel 更新脚本
# @author Carlos <anzhengchao@gmail.com>
# @link http://github.com/overtrue
# latest-laravel
SCRIPT_DIR=/root/latest-laravel/scripts
ROOT_DIR=${SCRIPT_DIR}/../
#filename
MASTER_FILE="laravel-master.tar.gz"
DEVELOP_FILE="laravel-develop.tar.gz"
# 更新并安装
latest_and_install()
{
cd $ROOT_DIR/
if [[ -d "laravel" ]]; then
rm -rf laravel
fi
echo ""
echo "*** 切换分支:$1 ***"
echo "branch:$1"
git clone https://github.com/laravel/laravel --depth=1
cd laravel && git checkout $1 && composer install
# 替换掉google字体
if [[ -f "resources/views/welcome.blade.php" ]]; then
sed -i "s/<link href='\/\/fonts.googleapis.com.*?>//" resources/views/welcome.blade.php
fi
cp .env.example .env
return 0
}
# 清理git仓库
clean_repo()
{
cd $ROOT_DIR
echo "*** 清理文件 ***"
git pull && \
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.tar.gz' --prune-empty --tag-name-filter cat -- --all && \
git push origin --force --all && \
git push origin --force --tags && \
rm -rf .git/refs/original/ && \
git reflog expire --expire=now --all && \
git gc --prune=now
return 0
}
# 打包
make_zip()
{
latest_and_install $1
if [[ $? -eq 0 ]]; then
echo "*** 开始打包:$2 ***"
cd $ROOT_DIR && \
rm -f $2 && \
tar -zcf $2 $(find laravel/ -type f)
cd ../ && rm -rf laravel
echo "*** 打包完毕:$2 ***"
fi
}
# 提交到latest-laravel
commit_zip()
{
cd $ROOT_DIR
echo "当前目录:`pwd`"
git add *.gz && \
git commit -am "update@$(date +%Y-%m-%d_%H%M%S)" && \
git pull && \
git push
}
# 检查错误并提交
check_and_commit()
{
if [[ $? != 0 ]]; then
echo "*** 错误:$? ***"
exit
else
commit_zip
fi
}
# 报告错误(issue)
report_error()
{
cd $SCRIPT_DIR
`node reporter.js` && rm -rf output
}
clean_repo
composer selfupdate
# master
master_output=$(make_zip "master" $MASTER_FILE)
echo $master_output
if [[ $? != 0 || "stat -c %s laravel-master.tar.gz" < 3000000 ]]; then
echo "$master_output" 2>&1 | tee $SCRIPT_DIR/output
fi
# develop
develop_output=$(make_zip "develop" $DEVELOP_FILE)
echo develop_output
if [[ $? != 0 || "stat -c %s laravel-develop.tar.gz" < 3000000 ]]; then
echo "$develop_output" 2>&1 | tee $SCRIPT_DIR/output
fi
check_and_commit
if [[ -f "$SCRIPT_DIR/output" ]]; then
report_error
echo "*** 上报错误完成! ***"
rm -rf $SCRIPT_DIR/output
fi
date