-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·153 lines (126 loc) · 4.49 KB
/
install.sh
File metadata and controls
executable file
·153 lines (126 loc) · 4.49 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
# git-absorb DevContainer Feature
# Copyright (c) 2025 helpers4
# Licensed under LGPL-3.0 - see LICENSE file for details
#
# Installs git-absorb: automatically absorb staged changes into their logical commits
set -e
# Feature options
GIT_ABSORB_VERSION="${VERSION:-"latest"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
# Determine the appropriate non-root user
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
USERNAME=root
fi
# Clean up function
cleanup() {
rm -rf /var/lib/apt/lists/*
rm -f /tmp/git-absorb.tar.gz
}
trap cleanup EXIT
# Ensure apt is in non-interactive mode
export DEBIAN_FRONTEND=noninteractive
echo "🔧 Installing git-absorb feature..."
echo "Username: $USERNAME"
echo "git-absorb version: $GIT_ABSORB_VERSION"
# Update apt if needed
apt_get_update() {
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
# Check and install packages
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
fi
}
# Install dependencies
echo "🔧 Installing dependencies..."
check_packages curl ca-certificates tar
# Ensure git is installed
if ! command -v git > /dev/null 2>&1; then
check_packages git
fi
# Detect architecture
architecture="$(uname -m)"
case $architecture in
x86_64) architecture="x86_64-unknown-linux-musl";;
aarch64 | armv8*) architecture="aarch64-unknown-linux-musl";;
*) echo "(!) Architecture $architecture unsupported"; exit 1 ;;
esac
# Install git-absorb
echo "🎯 Installing git-absorb..."
if [ "${GIT_ABSORB_VERSION}" = "latest" ]; then
echo " 📦 Fetching latest version..."
GIT_ABSORB_VERSION=$(curl -s "https://api.github.com/repos/tummychow/git-absorb/releases/latest" | grep -o '"tag_name": "[^"]*"' | cut -d'"' -f4)
if [ -z "${GIT_ABSORB_VERSION}" ]; then
echo "(!) Failed to fetch latest version"
exit 1
fi
fi
# Extract version number for file names (remove 'v' prefix if present)
if [ "${GIT_ABSORB_VERSION::1}" = 'v' ]; then
VERSION_NUMBER="${GIT_ABSORB_VERSION:1}"
else
VERSION_NUMBER="${GIT_ABSORB_VERSION}"
fi
echo " 📦 Downloading git-absorb ${GIT_ABSORB_VERSION}..."
# Download from GitHub releases (use original tag name for URL path)
DOWNLOAD_URL="https://github.com/tummychow/git-absorb/releases/download/${GIT_ABSORB_VERSION}/git-absorb-${VERSION_NUMBER}-${architecture}.tar.gz"
if ! curl -fL "${DOWNLOAD_URL}" -o /tmp/git-absorb.tar.gz; then
echo "(!) Failed to download git-absorb from ${DOWNLOAD_URL}"
echo "(!) Available releases: https://github.com/tummychow/git-absorb/releases"
exit 1
fi
# Extract and install
echo " 📦 Installing git-absorb..."
cd /tmp
tar -xzf git-absorb.tar.gz
# Find the binary (might be in a subdirectory)
BINARY_PATH=$(find /tmp -name "git-absorb" -type f -executable 2>/dev/null | head -1)
if [ -z "${BINARY_PATH}" ]; then
echo "(!) Could not find git-absorb binary in downloaded archive"
ls -la /tmp/
exit 1
fi
# Install to /usr/local/bin
cp "${BINARY_PATH}" /usr/local/bin/git-absorb
chmod +x /usr/local/bin/git-absorb
# Verify installation
if ! /usr/local/bin/git-absorb --version > /dev/null 2>&1; then
echo "(!) git-absorb installation verification failed"
exit 1
fi
# Get installed version for confirmation
INSTALLED_VERSION="$(/usr/local/bin/git-absorb --version 2>&1 | grep -o '[0-9.]*' | head -1 || echo 'unknown')"
echo " ✅ git-absorb ${INSTALLED_VERSION} installed successfully"
echo
echo "🎉 git-absorb installation complete!"
echo
echo "📋 Usage:"
echo " git add <files> # Stage your changes"
echo " git absorb # Automatically absorb into logical commits"
echo " git absorb --dry-run # Preview what would be absorbed"
echo
echo "🚀 Ready to use:"
echo " git absorb --help"
echo