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
| #!/usr/bin/env bash
# Get the repos absolute path recursively email="xxx@hotmail.com" pwd="xxx" cid="c65e97ab88de932e7c23e9d4b563e5c99b5926a06e26d2e8af26885bd5a6b1da" csr="729aeae125864b5577a82629296ce7e389aab8bee5384c25a9fa2c2572064374" username="xxx-backup"
get_repo_paths() { find . -type d -name ".git" }
get_token() { curl -q -X POST --data-urlencode "grant_type=password" --data-urlencode "username=${email}" --data-urlencode "password=${pwd}" --data-urlencode "client_id=${cid}" --data-urlencode "client_secret=${csr}" --data-urlencode "scope=projects user_info issues notes" https://gitee.com/oauth/token | jq -r ".access_token" }
push() { cd "$1" local datetime=`date +%y%m%d` local git_path="${PWD}" local local_path="${git_path%/.git*}" local repo_name="${local_path##*/}" local remote_path="git@gitee.com:${username}/${repo_name}.git" local http_path="https://gitee.com/${username}/${repo_name}.git"
cd "${local_path}"
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" echo "> \`${repo_name}'" echo " Local path : $PWD" echo " Remote path: $remote_path" echo " Http path: $http_path" echo " Token: ${access_token}" echo " RepoName: ${repo_name}" echo "= = = = = = = = = = = = = = = = = = = = = = = = = = =" echo ""
curl -X POST -s\ --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/user/repos'\ -d '{"access_token":"'${access_token}'","name":"'${repo_name}'","has_issues":"true","has_wiki":"true","can_comment":"true", "private":"true"}'
git config user.email "xxx@hotmail.com" git config user.name "xxx"
git remote rm backup git remote add backup "$remote_path"
git push backup return_status=$?
echo "= = = = = = = = = = = = = = = = = = = = = = = = = = ="
return $return_status }
die() { echo "> Fatal error!!!" exit 1 }
main() { access_token=$(get_token)
get_repo_paths | while read p; do push "${p}" || die done }
main
|