浏览代码

Update gitUpload.sh

MoeClub 1 年之前
父节点
当前提交
5397bb3d87
共有 1 个文件被更改,包括 28 次插入5 次删除
  1. 28 5
      gitUpload.sh

+ 28 - 5
gitUpload.sh

@@ -3,25 +3,48 @@
 target="${1:-}"
 repo="${2:-}"
 branch="${3:-main}"
+clone="${4:-}"
+pause="${5:-0}"
 
 [ -n "${target}" ] && [ -n "${repo}" ] || exit 1
 [ -e "${target}" ] || exit 1
 tmp=$(mktemp -d)
+trap "rm -rf ${tmp}" EXIT
 cd "$tmp"
 
+function createRepo(){
+  rn="${1:-}"
+  [ -n "$rn" ] || return 0
+  resp=`curl -X POST -sSL "${rn%github.com*}api.github.com/user/repos" -d "{\"name\":\"${rn##*/}\"}"`
+  echo "$resp" |grep '"status":' && return 1 || return 0
+}
+
+# init
+git config --global init.defaultBranch "$branch"
+git config --global pull.rebase true
+git config --global user.name "remote"
+git config --global user.email "remote@user"
+
 git init
 git checkout -b "$branch"
 git remote rm origin >/dev/null 2>&1
+git remote rm clone >/dev/null 2>&1
 git remote add origin "$repo"
+[ -n "$clone" ] && {
+  git remote add clone "$clone"
+  createRepo "$clone"
+}
 
 git pull origin "$branch"
-[ -f "${target}" ] && cp -rf "${target}" "${tmp}"
-[ -d "${target}" ] && cp -rf "${target%/}/." "${tmp}"
+[ -n "${target}" ] && {
+  [ -f "${target}" ] && cp -rf "${target}" "${tmp}"
+  [ -d "${target}" ] && cp -rf "${target%/}/." "${tmp}"
+}
+
+[ "$pause" != "0" ] && read -p "Pause <${tmp}> ..."
 
 git add .
 git commit -m `date +'%Y%m%d%H%M%S'`
 
 # git config http.postBuffer 524288000
-git push origin "$branch" -f
-
-
+[ -n "$clone" ] && git push clone "$branch" -f || git push origin "$branch" -f