Skip to content

Commit 1751745

Browse files
committed
Clone to vendor/repo local path; striped deploy tokens from console output
1 parent c84091b commit 1751745

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
## Why mirror repositories?
88
- You can pipe multiple services. For example, use Bitbucket private repositories
99
as a primary storage and self-hosted Gitlab instance as a purely CI/CD tool.
10-
- Better safe than sorry. Mirroring repos is a single backup alternative for SaaS.
10+
- Better safe than sorry. Mirroring repos is the only backup option for SaaS.
1111

1212
## How to use
1313

server.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
set -eux
3+
set -eu
44

55
# Extract the protocol (includes trailing "://").
66
DEST_PROTO="$(echo $DEST_REPO | sed -nr 's,^(.*://).*,\1,p')"
@@ -40,19 +40,23 @@ SRC_URL="$(echo ${SRC_URL/$SRC_PORT/})"
4040
SRC_PATH="$(echo $SRC_URL | sed -nr 's,[^/:]*([/:].*),\1,p')"
4141
# Remove the path from the URL.
4242
SRC_HOST="$(echo ${SRC_URL/$SRC_PATH/})"
43-
# name that can be used for the folder name
44-
SRC_PROJECT="$(echo $SRC_PATH | sed -nr 's,.*/(.*)\.git,\1,p')"
43+
# name that can be used for the folder name e.g vendor/repo
44+
SRC_PROJECT="$(echo $SRC_PATH | sed -nr 's,:(.*)\.git,\1,p')"
4545

4646

47+
printf "\nConfiguring ssh client to use deploy keys\n"
4748
mkdir -p ~/.ssh
48-
4949
eval `ssh-agent -s`
5050
echo "$SRC_DEPLOY_KEY" | base64 -d | ssh-add -
5151
echo "$DEST_DEPLOY_KEY" | base64 -d | ssh-add -
52+
53+
printf "\n\nChecking access to $SRC_HOST\n"
5254
ssh -o StrictHostKeyChecking=no -T "$SRC_USER$SRC_HOST" -p "$SRC_PORT"
55+
printf "\n\nChecking access to $DEST_HOST\n"
5356
ssh -o StrictHostKeyChecking=no -T "$DEST_USER$DEST_HOST" -p "$DEST_PORT"
5457

5558
if [[ ! -d /storage/"$SRC_PROJECT" ]]; then
59+
printf "\nCloning $SRC_REPO\n"
5660
cd /storage
5761
git clone --bare "$SRC_REPO" "$SRC_PROJECT"
5862
cd /storage/"$SRC_PROJECT"
@@ -61,4 +65,6 @@ fi
6165

6266
cd /storage/"$SRC_PROJECT"
6367

68+
printf "\nStarting netcat server on port 8080\n"
69+
6470
while true; do nc -l -p 8080 -e sh -c 'echo -e "HTTP/1.0 200 OK\r\nDate: $(date)\r\nContent-Length: 2\r\n\r\nOK"; sh /usr/local/bin/mirror.sh;'; done

0 commit comments

Comments
 (0)