aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/setup-img
blob: 879f3833bc9240a297967aba30433cde8310e292 (plain) (blame)
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
#!/bin/zsh
set -eax

__filename="$(realpath "$0")"
__dirname="$(dirname "${__filename})"
if [[ -f "$__dirname/.env" ]]; then
  source "$__dirname/.env"
fi

IMG="${IMG:-"docker.io/memdmp/cgit:${TAG:-"local-build"}"}"
SSH_DIR="${SSH_DIR:-"$HOME/.ssh"}"
SSH_KEY="${SSH_KEY:-"$(ls "$SSH_DIR/id_*.pub" | head -n 1)"}"
if [[ -f "$SSH_KEY" ]]; then
  SSH_KEY="$(cat "$SSH_KEY")"
elif [[ -f "$SSH_DIR/$SSH_KEY.pub" ]]; then
  SSH_KEY="$(cat "$SSH_DIR/$SSH_KEY.pub")"
elif [[ -f "$SSH_DIR/id_$SSH_KEY.pub" ]]; then
  SSH_KEY="$(cat "$SSH_DIR/id_$SSH_KEY.pub")"
elif [[ -f "$SSH_DIR/$SSH_KEY" ]]; then
  SSH_KEY="$(cat "$SSH_DIR/$SSH_KEY")"
elif [[ -f "$SSH_DIR/id_$SSH_KEY" ]]; then
  SSH_KEY="$(cat "$SSH_DIR/id_$SSH_KEY")"
fi

mkdir -p cgit/{ssh,git}
! podman container exists cgit >/dev/null 2>/dev/null || podman container rm cgit
! podman network exists cgit >/dev/null 2>/dev/null || podman network rm cgit
podman network create cgit
podman create \
  --name cgit \
  --network cgit \
  -v "$(pwd)/cgit/ssh:/etc/ssh:rw" \
  -v "$(pwd)/cgit/git:/var/lib/git:rw" \
  -p 127.0.0.1:18080:80 \
  -p 127.0.0.1:12222:22 \
  -e "SSH_KEY=${SSH_KEY}" \
  "$IMG" "$@"
podman start -ia cgit