Skip to content

Commit c9015eb

Browse files
authored
Merge pull request #114 from jsburckhardt/feat/tmux-install-from-releases
feat(tmux): install from GitHub releases instead of apt
2 parents 7dba0e3 + d58e029 commit c9015eb

4 files changed

Lines changed: 55 additions & 7 deletions

File tree

src/tmux/devcontainer-feature.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "tmux",
33
"id": "tmux",
4-
"version": "1.0.0",
4+
"version": "2.0.0",
55
"description": "tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal.",
66
"options": {
77
"version": {
88
"type": "string",
9-
"default": "os-provided",
10-
"description": "Version of tmux to install (installs the version provided by the OS package manager)"
9+
"default": "latest",
10+
"description": "Version of tmux to install from GitHub releases (e.g. '3.6a', 'latest')"
1111
}
1212
}
1313
}

src/tmux/install.sh

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/usr/bin/env bash
22

3+
# Variables
4+
REPO_OWNER="tmux"
5+
REPO_NAME="tmux"
6+
BINARY_NAME="tmux"
7+
TMUX_VERSION="${VERSION:-"latest"}"
8+
GITHUB_API_REPO_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases"
9+
310
set -e
411

512
if [ "$(id -u)" -ne 0 ]; then
@@ -21,9 +28,48 @@ check_packages() {
2128
fi
2229
}
2330

24-
# Install tmux
31+
# Make sure we have required dependencies
32+
check_packages curl jq ca-certificates build-essential pkg-config libevent-dev libncurses-dev bison tar
33+
34+
# Function to get the latest version from GitHub API
35+
get_latest_version() {
36+
curl -s "${GITHUB_API_REPO_URL}/latest" | jq -r ".tag_name"
37+
}
38+
39+
# Check if a version is passed as an argument
40+
if [ -z "$TMUX_VERSION" ] || [ "$TMUX_VERSION" == "latest" ]; then
41+
TMUX_VERSION=$(get_latest_version)
42+
echo "No version provided or 'latest' specified, installing the latest version: $TMUX_VERSION"
43+
else
44+
echo "Installing version from environment variable: $TMUX_VERSION"
45+
fi
46+
47+
# Construct the download URL
48+
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${TMUX_VERSION}/tmux-${TMUX_VERSION}.tar.gz"
49+
50+
# Create a temporary directory for the download
51+
TMP_DIR=$(mktemp -d)
52+
cd "$TMP_DIR" || exit
53+
54+
echo "Downloading tmux from $DOWNLOAD_URL"
55+
curl -sSL "$DOWNLOAD_URL" -o "tmux.tar.gz"
56+
57+
# Extract the tarball
58+
echo "Extracting tmux..."
59+
tar -xzf "tmux.tar.gz"
60+
61+
# Build from source
62+
cd "tmux-${TMUX_VERSION}" || exit
63+
echo "Configuring tmux..."
64+
./configure --prefix=/usr/local
65+
echo "Building tmux..."
66+
make -j"$(nproc)"
2567
echo "Installing tmux..."
26-
check_packages tmux
68+
make install
69+
70+
# Cleanup
71+
cd / || exit
72+
rm -rf "$TMP_DIR"
2773

2874
# Clean up
2975
rm -rf /var/lib/apt/lists/*

test/_global/scenarios.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180
"tmux-specific-version": {
181181
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
182182
"features": {
183-
"tmux": {}
183+
"tmux": {
184+
"version": "3.6a"
185+
}
184186
}
185187
},
186188
"hurl-specific-version": {

test/_global/tmux-specific-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -e
44
source dev-container-features-test-lib
5-
check "tmux is installed" /bin/bash -c "tmux -V"
5+
check "tmux with specific version" /bin/bash -c "tmux -V | grep '3.6a'"
66

77
reportResults

0 commit comments

Comments
 (0)