-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·71 lines (60 loc) · 1.56 KB
/
install.sh
File metadata and controls
executable file
·71 lines (60 loc) · 1.56 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
set -eu
REPO="ghcr.io/frinknet/metabuild"
IMAGE="${REPO##*/}"
PREFIX="${HOME}/bin"
VER="${1:-latest}"
mkdir -p "$PREFIX"
case ":$PATH:" in
*:"$PREFIX") ;;
"$PREFIX":*) ;;
*) printf '\nexport PATH="%s:$PATH"\n' "$PREFIX" >> "$HOME/.bashrc" || true ;;
esac
# Record old local alias ID (if any)
OLD_ID="$(docker image inspect -f '{{.Id}}' "$IMAGE:latest" 2>/dev/null || true)"
# Pull new image
if ! docker image pull "$REPO:$VER"; then
echo "could not pull docker image $REPO:$VER" >&2
exit 1
fi
# Retag to a stable local alias
docker image tag "$REPO:$VER" "$IMAGE:latest"
# Remove the previous image ID if it changed (skips if referenced)
NEW_ID="$(docker image inspect -f '{{.Id}}' "$IMAGE:latest")"
if [ -n "${OLD_ID:-}" ] && [ "$OLD_ID" != "$NEW_ID" ]; then
docker image rm "$OLD_ID" >/dev/null 2>&1 || true
fi
# Opportunistic cleanup of danglers
docker image prune -f >/dev/null 2>&1 || true
# Create a shell wrapper
WRAP="$PREFIX/$IMAGE"
cat > "$WRAP" <<EOF
#!/bin/sh
set -eu
IMAGE="$IMAGE:latest"
VERSION="$VER"
if [ "\${1:-}" = "update" ]; then
curl -fsSL "https://github.com/${REPO#*/}/raw/main/install.sh" | exec sh -s -- "\${2:-\$VERSION}"
elif [ -t 0 ]; then
docker run --rm -it \
-u "\$(id -u):\$(id -g)" \
-v "\$(pwd):/build" \
-e PRJ="\${PWD##*/}" \
"\$IMAGE" "\$@"
else
docker run --rm -i \
-u "\$(id -u):\$(id -g)" \
-v "\$(pwd):/build" \
-e PRJ="\${PWD##*/}" \
"\$IMAGE" "\$@"
fi
echo
EOF
chmod +x "$WRAP"
echo
echo "✓ installed: $WRAP"
echo
"$WRAP" version
echo
echo "Run 'metabuild init' to get started."
echo