Repository navigation
Expand file tree
/
Copy pathpush.sh
More file actions
112 lines (99 loc) · 3.9 KB
/
Copy pathpush.sh
File metadata and controls
112 lines (99 loc) · 3.9 KB
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
#!/bin/bash
# 这个脚本是在开发者本地工作站使用的
GITHUB_TOKEN="github-token.ignore"
get_ssh_agent_pid() {
ps -ef | grep ssh-agent | awk '{print $2}'
}
git_push_all() {
# 开始推送
for remote in $(git remote); do
echo "[INFO] Start pushing to '$(git remote get-url $remote)' ..."
#if [[ -n $(git branch --no-color | grep dev) ]]; then
# # 推送(除master以外的)特别分支
# git push -f -u $remote dev
#else
# git push $remote :dev
#fi
# git push -f $remote && git push -f --tags $remote ||\
# echo "[ERROR] Fail git push $remote!" 1>&2
git push -fq $remote &>/dev/null &
done
# case $do_upload_pdf_file in
# [Yy]* )
# git tag -d $RELEASE_TAG # 删除标签
# export RELEASE_TITLE="Release $RELEASE_TAG"
# export RELEASE_NOTES="Daily update"
# cat $GITHUB_TOKEN | awk 'match($0,/^\w+/){print $1}' | gh auth login -p ssh --with-token &&\
# echo "[INFO] Login successfully" &&\
# gh release create "$RELEASE_TAG" "$OUTPUT_FILE#$OUTPUT_FILE" --latest \
# --title "$RELEASE_TITLE" \
# --notes "$RELEASE_NOTES" \
# -R "$REPO" &&\
# gh auth logout ||\
# echo "[ERROR] Fail to upload release $RELEASE_TAG!" 1>&2 && exit 1
# for remote in $(git remote); do
# echo "[INFO] Remove temporary tag from '$(git remote get-url $remote)' ..."
# git push $remote ":$RELEASE_TAG"
# done
# ;;
# esac
# # 向 Github 推送发行版 PDF 文件
# export REPO="KaiserKatze/mathematical-notes" # Github 仓库
# export RELEASE_TAG=${RELEASE_TAG:-$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)} # 自动生成 git 标签
# case $do_upload_pdf_file in
# [Yy]* )
# git tag $RELEASE_TAG # 打标签
# ;;
# esac
}
kill_ssh_agents() {
pid_ssh_agent=($(get_ssh_agent_pid)) # 获取 SSH Agent 进程的 PID,并保存到数组中
echo "[INFO] 正在运行的 SSH Agent 进程共计${#pid_ssh_agent[@]}个."
echo "[INFO] 上次正常运行的 SSH Agent 信息:(SSH_AUTH_SOCK='$SSH_AUTH_SOCK',SSH_AGENT_PID='$SSH_AGENT_PID')"
if [[ -z "$SSH_AGENT_PID" || ! "$SSH_AGENT_PID" =~ ^[0-9]+$ ]]; then
# 如果 SSH_AGENT_PID 为空,或者 SSH_AGENT_PID 不是纯数字
for pid in "${pid_ssh_agent[@]}"; do
kill -9 "$pid" && echo "杀死 SSH Agent 进程(pid=$pid)." # 杀死已存在的 SSH Agent 进程
done
pid_ssh_agent=$(get_ssh_agent_pid) # 重新获取 SSH Agent 进程的 PID
if [ -z "$pid_ssh_agent" ]; then # 验证是否已经把 SSH Agent 进程清理干净
echo "[INFO] 成功创建 SSH Agent:" # 如果一个 SSH Agent 都没有,就创建一个
eval $(ssh-agent)
fi
# 准备 SSH 密匙
ssh-add
if [ $? -ne 0 ]; then
echo "[ERROR] 没有启动 SSH Agent 后台程序,或者无法添加 SSH 密匙!" 1>&2
exit 1
fi
else
# 如果已有正在运行的 ssh-agent
# 清除其他非正常运行的 ssh-agent
for ((i = 0; i < ${#pid_ssh_agent[@]}; i++)); do
if [ "$SSH_AGENT_PID" -ne "${pid_ssh_agent[i]}" ]; then
kill -9 "${pid_ssh_agent[i]}" && echo "杀死 SSH Agent 进程(pid=${pid_ssh_agent[i]})." # 杀死已存在的 SSH Agent 进程
fi
done
fi
}
kill_ssh_agents
# 在后台执行推送
for remote in $(git remote); do
echo "[INFO] Start pushing to '$(git remote get-url $remote)' ..."
git push -f $remote
done
# # 在本地重命名 texlive 输出的 PDF 文件
# SOURCE_FILE="math.pdf"
# OUTPUT_FILE="数学笔记.pdf"
# if [[ ! -f "$OUTPUT_FILE" || $(stat --printf="%s" $SOURCE_FILE) -ge $(( $(stat --printf="%s" $OUTPUT_FILE) * 8 / 10 )) ]]; then
# cp "$SOURCE_FILE" "$OUTPUT_FILE" &>/dev/null && echo "[INFO] 已生成最新版'数学笔记.pdf'文件." || echo "[ERROR] 生成最新版'数学笔记.pdf'失败!"
# # 如果没有 Github token 文件,那么不上传 PDF 文件
# if [[ ! -f "$GITHUB_TOKEN" ]]; then
# do_upload_pdf_file="n"
# else
# read -p "是否向 Github 上传 PDF 文件?(Y/n) " do_upload_pdf_file
# fi
# else
# do_upload_pdf_file="n"
# fi
./copy.sh