-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·43 lines (32 loc) · 1.15 KB
/
entrypoint.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
#!/bin/sh
set -e -o pipefail
sshtmp="${RUNNER_TEMP}/ssh"
mkdir -p "${sshtmp}"
if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
printf "Saving SSH_PRIVATE_KEY\n" >&2
printf "%s\n" "${SSH_PRIVATE_KEY}" | sed 's/\\n/\n/g' > "${sshtmp}/src_rsa"
printf "%s\n" "${SSH_PRIVATE_KEY}" | sed 's/\\n/\n/g' > "${sshtmp}/dst_rsa"
chmod 600 "${sshtmp}/src_rsa"
chmod 600 "${sshtmp}/dst_rsa"
fi
if [[ -n "${UPSTREAM_SSH_PRIVATE_KEY}" ]]; then
printf "Saving UPSTREAM_SSH_PRIVATE_KEY\n" >&2
printf "%s\n" "${UPSTREAM_SSH_PRIVATE_KEY}" | sed 's/\\n/\n/g' > "${sshtmp}/src_rsa"
chmod 600 "${sshtmp}/src_rsa"
fi
if [[ -n "${DESTINATION_SSH_PRIVATE_KEY}" ]]; then
printf "Saving DESTINATION_SSH_PRIVATE_KEY\n" >&2
printf "%s\n" "${DESTINATION_SSH_PRIVATE_KEY}" | sed 's/\\n/\n/g' > "${sshtmp}/dst_rsa"
chmod 600 "${sshtmp}/dst_rsa"
fi
set -u
# Github action changes $HOME to /github at runtime
# therefore we always copy the SSH key to $HOME (aka. ~)
if ! ls "${HOME}"/.ssh > /dev/null 2>&1; then
mkdir --parents "${HOME}"/.ssh
fi
mv "${sshtmp}"/* "${HOME}"/.ssh || true
rmdir "${sshtmp}"
DEST_REPO=$1
UPSTREAM_REPO=$2
/git-mirror.sh "${DEST_REPO}" "${UPSTREAM_REPO}"