forked from spwhitton/git-remote-gcrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·98 lines (84 loc) · 2.89 KB
/
install.sh
File metadata and controls
executable file
·98 lines (84 loc) · 2.89 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
94
95
96
97
98
#!/bin/sh
set -e
# Auto-detect Termux: if /usr/local doesn't exist but $PREFIX does (Android/Termux)
if [ -z "${prefix:-}" ]; then
if [ -d "${_USR_LOCAL:-/usr/local}" ]; then
prefix=/usr/local
elif [ -n "${PREFIX:-}" ] && [ -d "$PREFIX" ]; then
# Termux sets $PREFIX to /data/data/com.termux/files/usr
prefix="$PREFIX"
echo "Detected Termux environment, using prefix=$prefix"
else
prefix=/usr/local
fi
fi
: "${DESTDIR:=}"
verbose() { echo "$@" >&2 && "$@"; }
install_v() {
# Install $1 into $2/ with mode $3
if ! verbose install -d "$2"; then
echo "Error: Failed to create directory $2" >&2
exit 1
fi
if ! verbose install -m "$3" "$1" "$2"; then
echo "Error: Failed to install $1 into $2" >&2
exit 1
fi
}
# --- VERSION DETECTION ---
: "${OS_RELEASE_FILE:=/etc/os-release}"
if [ -f "$OS_RELEASE_FILE" ]; then
# shellcheck disable=SC1091,SC1090
. "$OS_RELEASE_FILE"
OS_IDENTIFIER=$ID # Linux
elif command -v uname >/dev/null; then
# Fallback for macOS/BSD (darwin)
OS_IDENTIFIER=$(uname -s | tr '[:upper:]' '[:lower:]')
else
OS_IDENTIFIER="unknown_OS"
fi
# Get base version then append OS identifier
if [ -d .git ] && command -v git >/dev/null; then
VERSION=$(git describe --tags --always --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo "dev")
else
if [ ! -f debian/changelog ]; then
echo "Error: debian/changelog not found (and not a git repo)" >&2
exit 1
fi
VERSION=$(grep ^git-remote-gcrypt debian/changelog | head -n 1 | awk '{print $2}' | tr -d '()')
fi
VERSION="$VERSION ($OS_IDENTIFIER)"
echo "Detected version: $VERSION"
# Setup temporary build area
BUILD_DIR="./.build_tmp"
mkdir -p "$BUILD_DIR"
trap 'rm -rf "$BUILD_DIR"' EXIT
# Placeholder injection
sed "s|@@DEV_VERSION@@|$VERSION|g" git-remote-gcrypt >"$BUILD_DIR/git-remote-gcrypt"
# --- GENERATION ---
verbose ./completions/gen_docs.sh
# --- INSTALLATION ---
# This is where the 'Permission denied' happens if not sudo
install_v "$BUILD_DIR/git-remote-gcrypt" "$DESTDIR$prefix/bin" 755
if command -v rst2man >/dev/null; then
rst2man='rst2man'
elif command -v rst2man.py >/dev/null; then # it is installed as rst2man.py on macOS
rst2man='rst2man.py'
fi
if [ -n "$rst2man" ]; then
# Update trap to clean up manpage too
trap 'rm -rf "$BUILD_DIR"; rm -f git-remote-gcrypt.1.gz' EXIT
verbose "$rst2man" ./README.rst | gzip -9 >git-remote-gcrypt.1.gz
install_v git-remote-gcrypt.1.gz "$DESTDIR$prefix/share/man/man1" 644
else
echo "'rst2man' not found, man page not installed" >&2
fi
# Install shell completions
# Bash
install_v completions/bash/git-remote-gcrypt "$DESTDIR$prefix/share/bash-completion/completions" 644
# Zsh
install_v completions/zsh/_git-remote-gcrypt "$DESTDIR$prefix/share/zsh/site-functions" 644
# Fish
install_v completions/fish/git-remote-gcrypt.fish "$DESTDIR$prefix/share/fish/vendor_completions.d" 644
echo "Installation complete!"
echo "Completions installed to $DESTDIR$prefix/share/"