Skip to content

Commit

Permalink
Clone to vendor/repo local path; striped deploy tokens from console o…
Browse files Browse the repository at this point in the history
…utput
  • Loading branch information
karser committed Feb 15, 2020
1 parent c84091b commit 1751745
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Why mirror repositories?
- You can pipe multiple services. For example, use Bitbucket private repositories
as a primary storage and self-hosted Gitlab instance as a purely CI/CD tool.
- Better safe than sorry. Mirroring repos is a single backup alternative for SaaS.
- Better safe than sorry. Mirroring repos is the only backup option for SaaS.

## How to use

Expand Down
14 changes: 10 additions & 4 deletions server.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -eux
set -eu

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


printf "\nConfiguring ssh client to use deploy keys\n"
mkdir -p ~/.ssh

eval `ssh-agent -s`
echo "$SRC_DEPLOY_KEY" | base64 -d | ssh-add -
echo "$DEST_DEPLOY_KEY" | base64 -d | ssh-add -

printf "\n\nChecking access to $SRC_HOST\n"
ssh -o StrictHostKeyChecking=no -T "$SRC_USER$SRC_HOST" -p "$SRC_PORT"
printf "\n\nChecking access to $DEST_HOST\n"
ssh -o StrictHostKeyChecking=no -T "$DEST_USER$DEST_HOST" -p "$DEST_PORT"

if [[ ! -d /storage/"$SRC_PROJECT" ]]; then
printf "\nCloning $SRC_REPO\n"
cd /storage
git clone --bare "$SRC_REPO" "$SRC_PROJECT"
cd /storage/"$SRC_PROJECT"
Expand All @@ -61,4 +65,6 @@ fi

cd /storage/"$SRC_PROJECT"

printf "\nStarting netcat server on port 8080\n"

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 comments on commit 1751745

Please sign in to comment.