-
Notifications
You must be signed in to change notification settings - Fork 75
/
automate.sh
executable file
·77 lines (70 loc) · 2.63 KB
/
automate.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
#!/bin/bash -e
function git_push() {
for d in $(ls -1); do
if [ -d "$d" ] && [ -f "$d/.git" ] ; then
cd "$d"
echo "In ${d}, git commit and push"
git commit -am "update doc"
git push origin
cd ..
fi
done
git commit -am "update doc"
git push origin
}
function git_pull() {
for d in $(ls -1); do
if [ -d "$d" ] && [ -f "$d/.git" ] ; then
cd "$d"
echo "In ${d}, git commit and push"
git pull origin
cd ..
fi
done
git pull origin
}
function refresh_wordpress() {
local max_days=${MAX_DAYS:-"7"}
echo "Use emacs to update README.org"
for d in "problems" "followup" "review" "posts"; do
# for d in "series" "review"; do
cd "$d"
for f in $(find . -name 'README.org' -mtime -${max_days} | grep -v '^README.org$'); do
echo "Update $f"
dirname=$(basename $(dirname $f))
(cd "$dirname" && /Applications/Emacs.app/Contents/MacOS/Emacs-x86_64-10_10 --batch -l ../../emacs-update.el)
done
cd ..
done
}
function refresh_link() {
echo "refresh link"
cd problems
for f in $(ls -1t */README.org); do
dirname=$(basename $(dirname $f))
if ! grep "github.com\/dennyzhang\/code.dennyzhang.com.*$dirname" $f 1>/dev/null 2>&1; then
echo "Update github fork link for $f"
sed -ie "s/github.com\/dennyzhang\/code.dennyzhang.com.*\">/github.com\/dennyzhang\/code.dennyzhang.com\/tree\/master\/problems\/$dirname\">/g" $f
rm -rf $dirname/README.orge
fi
if ! grep "https:\/\/code.dennyzhang.com.*$dirname" $f 1>/dev/null 2>&1; then
echo "Update blog url for $f"
sed -ie "s/https:\/\/code.dennyzhang.com\/example/https:\/\/code.dennyzhang.com\/$dirname/g" $f
rm -rf $dirname/README.orge
fi
if ! grep "Github:.*tree\/master/problems/.*$dirname" $f 1>/dev/null 2>&1; then
echo "Update GitHub url for $f"
sed -ie "s/tree\/master\/.*code.dennyzhang.com/tree\/master\/problems\/$dirname][code.dennyzhang.com/g" $f
rm -rf $dirname/README.orge
fi
if ! grep -i lintcode.com $f 1>/dev/null 2>&1; then
if ! grep "leetcode.com.*$dirname" $f 1>/dev/null 2>&1; then
echo "Update Leetcode url for $f"
sed -ie "s/https:\/\/leetcode.com\/problems\/.*/https:\/\/leetcode.com\/problems\/$dirname\/description\/][leetcode.com]]/g" $f
rm -rf $dirname/README.orge
fi
fi
done
}
action=${1?}
eval "$action"