-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
93 lines (77 loc) · 1.82 KB
/
install.sh
File metadata and controls
93 lines (77 loc) · 1.82 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
set -e
REPO="Bikz/goodcommit"
BIN_NAME="goodcommit"
INSTALL_DIR="$HOME/.local/bin"
for cmd in curl tar mktemp; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "error: $cmd is required" >&2
exit 1
fi
done
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
darwin)
OS="apple-darwin"
;;
linux)
OS="unknown-linux-gnu"
;;
*)
echo "error: unsupported OS: $OS" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64)
ARCH="x86_64"
;;
arm64|aarch64)
ARCH="aarch64"
;;
*)
echo "error: unsupported arch: $ARCH" >&2
exit 1
;;
esac
TARGET="${ARCH}-${OS}"
ASSET="${BIN_NAME}-${TARGET}.tar.gz"
URL="https://github.com/${REPO}/releases/latest/download/${ASSET}"
mkdir -p "$INSTALL_DIR"
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
printf "Downloading %s...\n" "$URL"
if ! curl -fL "$URL" -o "$TMP_DIR/$ASSET"; then
echo "error: failed to download release asset" >&2
echo "You can build from source with: cargo build --release" >&2
exit 1
fi
tar -xzf "$TMP_DIR/$ASSET" -C "$TMP_DIR"
if [ ! -f "$TMP_DIR/$BIN_NAME" ]; then
echo "error: missing binary in release archive" >&2
exit 1
fi
cp "$TMP_DIR/$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"
chmod 755 "$INSTALL_DIR/$BIN_NAME"
cat > "$INSTALL_DIR/g" <<'SH'
#!/bin/sh
exec goodcommit "$@"
SH
cat > "$INSTALL_DIR/g." <<'SH'
#!/bin/sh
for arg in "$@"; do
case "$arg" in
--stage-all|--no-stage|--interactive) exec goodcommit "$@" ;;
esac
done
exec goodcommit --stage-all "$@"
SH
chmod +x "$INSTALL_DIR/g" "$INSTALL_DIR/g."
echo "installed $BIN_NAME to $INSTALL_DIR"
echo "aliases installed: g, g."
echo "next: run 'goodcommit setup' to configure your provider"
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*) echo "note: add $INSTALL_DIR to your PATH to use g or goodcommit directly" ;;
esac