refactor and use --mirror for clone/push
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/init.sh
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euf -o pipefail
|
||||
|
||||
curp="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
bb_projects() {
|
||||
# get all projects
|
||||
curl --silent \
|
||||
-u ${BB_ADMIN_USERNAME}:${SRC_TOKEN} \
|
||||
"${BB_SERVER_URL}/rest/api/1.0/projects/" |
|
||||
jq -r '.values[] | .key' |
|
||||
tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
bb_repos() {
|
||||
[ -z "$1" ] && return
|
||||
# by project
|
||||
curl --silent \
|
||||
-u ${BB_ADMIN_USERNAME}:${SRC_TOKEN} \
|
||||
"${BB_SERVER_URL}/rest/api/1.0/projects/$1/repos/" |
|
||||
jq -r '.values[].name' |
|
||||
tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
# unset all GITEA_* variables
|
||||
unset "${!GITEA_@}"
|
||||
|
||||
[ -f "$curp/init.sh" ] && source "$curp/init.sh"
|
||||
|
||||
[ -z "${SRC_TOKEN}" ] && {
|
||||
echo "SRC_TOKEN is empty" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
: ${BB_ADMIN_USERNAME:=$USER}
|
||||
: ${BB_ADMIN_PASSWORD:=}
|
||||
|
||||
ARGS=()
|
||||
pos_arg_flag=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [ "${pos_arg_flag}" -eq "1" ]; then
|
||||
ARGS+=("$1")
|
||||
shift 1
|
||||
continue
|
||||
fi
|
||||
case "$1" in
|
||||
--url | -u)
|
||||
BB_SERVER_URL="$2"
|
||||
shift 2
|
||||
;;
|
||||
--token | -t)
|
||||
SRC_TOKEN="$2"
|
||||
shift 2
|
||||
;;
|
||||
--admin | -a)
|
||||
BB_ADMIN_USERNAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--password | -p)
|
||||
BB_ADMIN_PASSWORD="$2"
|
||||
shift 2
|
||||
;;
|
||||
--pushurl | -s)
|
||||
BB_SERVER_PUSH_URL="$2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
pos_arg_flag=1
|
||||
shift 1
|
||||
;;
|
||||
--*=*)
|
||||
set -- "$(cat - <<<"$1" | cut -d '=' -f1)" "$(cat - <<<"$1" | cut -d '=' -f2-)" "${@:3}"
|
||||
;;
|
||||
*)
|
||||
ARGS+=("$1")
|
||||
shift 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -z "${BB_SERVER_PUSH_URL}" ] &&
|
||||
BB_SERVER_PUSH_URL="$(echo "${BB_SERVER_URL}" | perl -pe "s#(https?://)#\${1}${BB_ADMIN_USERNAME}:${BB_ADMIN_PASSWORD}@#")/scm/"
|
||||
|
||||
# mirror all remote repos and get changes
|
||||
for prj in $(bb projects); do
|
||||
for repo in $(bb repo "$prj"); do
|
||||
if [ -d "$curp/$prj/$repo" ]; then
|
||||
(
|
||||
cd "$curp/$prj/$repo"
|
||||
git remote update
|
||||
)
|
||||
else
|
||||
git clone --mirror "${BB_SERVER_PUSH_URL}/$prj/$repo" "$prj/$repo"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# migrate all repos to gitea
|
||||
"$curp/../migrate.sh" "$@"
|
||||
Reference in New Issue
Block a user