summaryrefslogtreecommitdiff
path: root/git-maintenance/get.sh
blob: 7bff0abab49daa19ff6b2ab250d69eb2cbbdcfae (plain)
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
#!/usr/bin/env bash

PASS="$(ls "/run/media/"*/*"/key.fsojp.aes256" | head -n 1)"
PUBKEY=1KwpZECcrGWnM3AFVSbv3Xr5qguV4yG2sV

URLPFX="https://bico.media/$PUBKEY"
if [ "$1" != "" ]
then
	REPONAME="$1"
fi
if [ "$REPONAME" = "" ]
then
	REPONAME="$(git rev-parse --show-toplevel 2>/dev/null)"
fi
if [ "$REPONAME" = "" ]
then
	REPONAME=for-slow-organization-job-private
fi

echo ""
echo "This script is expected to be kept in sync with:"
echo "  ${URLPFX}/get.sh"
echo ""

# 2. mkdir -p .git/encrypted and git init
mkdir -p "$REPONAME"
cd "$REPONAME"
if ! [ -d ".git" ]; then git init; fi

git config gc.auto 0

pushd .git
# prevent recreation of existing data
mkdir -p encrypted
mkdir -p objects/pack.bak
mv -f objects/pack/* objects/pack.bak/

# 3. download .git/encrypted with wget
curl -sfI "$URLPFX"/refs.aes>/dev/null && wget "$URLPFX"/refs.aes -O encrypted/refs.aes || echo "==== BROKEN REMOTE refs.aes PLEASE RE-STORE OR RECOVER ===="
openssl aes-256-cbc -salt -pbkdf2 -pass "file:$PASS" -d -in encrypted/refs.aes | tar -Jxvf -

for encpack in $(<encrypted/list.txt)
do
	wget "$URLPFX"/"$encpack" -O .git/encrypted/"$encpack"
	openssl aes-256-cbc -salt -pbkdf2 -pass "file:$PASS" -d -in .git/encrypted/"$encpack" | tar -Jxvf -
done

for pack in objects/pack/*.pack
do
	git index-pack "$pack"
done
popd

git checkout

echo DONE