From 270bff96fc4fc9622ed4cfc5966db2b6c0d62171 Mon Sep 17 00:00:00 2001 From: Daniel Braun <7925710+braun-daniel@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:18:43 +0000 Subject: [PATCH] Major changes; --- src/asciidoc/devcontainer-feature.json | 33 +--------- src/asciidoc/install.sh | 91 +++----------------------- src/fzf/install.sh | 42 ++++++------ src/spaceship/install.sh | 8 ++- test/fzf/test.sh | 13 ++++ 5 files changed, 52 insertions(+), 135 deletions(-) diff --git a/src/asciidoc/devcontainer-feature.json b/src/asciidoc/devcontainer-feature.json index 628762f..7db533b 100644 --- a/src/asciidoc/devcontainer-feature.json +++ b/src/asciidoc/devcontainer-feature.json @@ -1,37 +1,8 @@ { "name": "AsciiDoc", "id": "asciidoc", - "version": "1.1.0", - "description": "Installs AsciiDoctor, Asciidoctor PDF and AsciiDoctor Diagram.", - "options": { - "asciidoctorVersion": { - "type": "string", - "default": "latest", - "proposals": [ - "latest", - "2.0.23" - ], - "description": "Version of AsciiDoctor to install. Use 'latest' for the most recent version." - }, - "asciidoctorPdfVersion": { - "type": "string", - "default": "latest", - "proposals": [ - "latest", - "2.3" - ], - "description": "Version of Asciidoctor PDF to install. Use 'latest' for the most recent version." - }, - "asciidoctorDiagramVersion": { - "type": "string", - "default": "latest", - "proposals": [ - "latest", - "2.3.1" - ], - "description": "Version of Asciidoctor Diagram to install. Use 'latest' for the most recent version." - } - }, + "version": "1.2.0", + "description": "Installs asciidoctor, asciidoctor-pdf, asciidoctor-diagram and asciidoctor-kroki via. gem.", "installsAfter": [ "ghcr.io/devcontainers/features/common-utils" ] diff --git a/src/asciidoc/install.sh b/src/asciidoc/install.sh index fe6b003..6807f1b 100644 --- a/src/asciidoc/install.sh +++ b/src/asciidoc/install.sh @@ -1,88 +1,17 @@ #!/usr/bin/env bash -# This script installs AsciiDoc and all necessary tools for a DevContainer feature. +# This script installs AsciiDoctor and related tools for a DevContainer feature. # Exit script on any error set -e -# Default version for AsciiDoctor (if not specified) -ASCIIDOCTOR_VERSION="${ASCIIDOCTOR_VERSION:-latest}" +# Update package lists and install Ruby +echo "Updating package lists and installing Ruby..." +apt-get update -y && apt-get install -y ruby -# Default version for AsciiDoctor PDF (if not specified) -ASCIIDOCTOR_PDF_VERSION="${ASCIIDOCTOR_PDF_VERSION:-latest}" +# Install RubyGems +echo "Installing AsciiDoctor and related gems..." +gem install asciidoctor asciidoctor-pdf asciidoctor-diagram asciidoctor-kroki -# Default version for AsciiDoctor Diagram (if not specified) -ASCIIDOCTOR_DIAGRAM_VERSION="${ASCIIDOCTOR_DIAGRAM_VERSION:-latest}" - -# Function to install system dependencies -install_dependencies() { - echo "Updating package lists..." - apt-get update -y - - echo "Installing essential dependencies..." - apt-get install -y \ - ruby -} - -# Function to install AsciiDoctor (optional faster alternative) -install_asciidoctor() { - if [ "$ASCIIDOCTOR_VERSION" = "latest" ]; then - echo "Installing the latest version of AsciiDoctor via RubyGems..." - gem install asciidoctor - else - echo "Installing AsciiDoctor (version $ASCIIDOCTOR_VERSION) via RubyGems..." - gem install asciidoctor -v "$ASCIIDOCTOR_VERSION" - fi -} - -# Function to install AsciiDoctor PDF (optional faster alternative) -install_asciidoctor_pdf() { - if [ "$ASCIIDOCTOR_PDF_VERSION" = "latest" ]; then - echo "Installing the latest version of AsciiDoctor PDF via RubyGems..." - gem install asciidoctor-pdf - else - echo "Installing AsciiDoctor PDF (version $ASCIIDOCTOR_PDF_VERSION) via RubyGems..." - gem install asciidoctor-pdf -v "$ASCIIDOCTOR_PDF_VERSION" - fi -} - -# Function to install AsciiDoctor Diagram (optional faster alternative) -install_asciidoctor_diagram() { - if [ "$ASCIIDOCTOR_DIAGRAM_VERSION" = "latest" ]; then - echo "Installing the latest version of AsciiDoctor Diagram via RubyGems..." - gem install asciidoctor-diagram - else - echo "Installing AsciiDoctor Diagram (version $ASCIIDOCTOR_DIAGRAM_VERSION) via RubyGems..." - gem install asciidoctor-diagram -v "$ASCIIDOCTOR_DIAGRAM_VERSION" - fi -} - -# Function to clean up after installation -cleanup() { - echo "Cleaning up unnecessary packages and cache..." - apt-get autoremove -y - apt-get clean - rm -rf /var/lib/apt/lists/* -} - -# Main installation process -install_dependencies -install_asciidoctor -install_asciidoctor_pdf -install_asciidoctor_diagram -cleanup - -# Verification of the installations -echo "Verifying installation..." -if command -v asciidoctor >/dev/null 2>&1; then - echo "AsciiDoctor installed successfully." -else - echo "Error: AsciiDoctor installation failed." >&2 - exit 1 -fi - -if command -v asciidoctor-pdf >/dev/null 2>&1; then - echo "AsciiDoctor PDF installed successfully." -else - echo "Error: AsciiDoctor PDF installation failed." >&2 - exit 1 -fi \ No newline at end of file +# Clean up unnecessary packages and cache +echo "Cleaning up unnecessary packages and cache..." +apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/src/fzf/install.sh b/src/fzf/install.sh index 687edae..91b4a07 100644 --- a/src/fzf/install.sh +++ b/src/fzf/install.sh @@ -4,40 +4,38 @@ # Exit script on any error set -e -# Update package lists and install fzf -echo "Updating package lists and installing fzf..." -apt-get update -y && apt-get install -y fzf - -# Clean up unnecessary packages and cache -echo "Cleaning up unnecessary packages and cache..." -apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* - -# Verify the installation -echo "Verifying installation..." -if command -v fzf --version >/dev/null 2>&1; then - echo "fzf installed successfully." -else - echo "Error: fzf installation failed." >&2 - exit 1 -fi +# Determine the remote user (typically non-root, like vscode or devuser) +REMOTE_USER="${_REMOTE_USER:-root}" + +# Clone the fzf repository into the remote user's home directory +echo "Cloning fzf repository..." +git clone --depth 1 https://github.com/junegunn/fzf.git "$REMOTE_USER_HOME/.fzf" + +# Run the fzf install script +echo "Running fzf install script..." +"$REMOTE_USER_HOME/.fzf/install" + +# Home directory of the remote user +USER_HOME="/home/${REMOTE_USER}" # Set up fzf key bindings and fuzzy completion for bash if [ -n "$BASH_VERSION" ]; then echo "Setting up fzf key bindings and fuzzy completion for bash..." - echo 'eval "$(fzf --bash)"' >> ~/.bashrc - source ~/.bashrc + echo 'eval "$(fzf --bash)"' >> "${USER_HOME}/.bashrc" + chown "${REMOTE_USER}:${REMOTE_USER}" "${USER_HOME}/.bashrc" fi # Set up fzf key bindings and fuzzy completion for zsh if [ -n "$ZSH_VERSION" ]; then echo "Setting up fzf key bindings and fuzzy completion for zsh..." - echo 'source <(fzf --zsh)' >> ~/.zshrc - source ~/.zshrc + echo 'source <(fzf --zsh)' >> "${USER_HOME}/.zshrc" + chown "${REMOTE_USER}:${REMOTE_USER}" "${USER_HOME}/.zshrc" fi # Set up fzf key bindings for fish if [ -n "$FISH_VERSION" ]; then echo "Setting up fzf key bindings for fish..." - echo 'fzf --fish | source' >> ~/.config/fish/config.fish - source ~/.config/fish/config.fish + mkdir -p "${USER_HOME}/.config/fish" + echo 'fzf --fish | source' >> "${USER_HOME}/.config/fish/config.fish" + chown -R "${REMOTE_USER}:${REMOTE_USER}" "${USER_HOME}/.config/fish" fi \ No newline at end of file diff --git a/src/spaceship/install.sh b/src/spaceship/install.sh index 510d89b..395a769 100644 --- a/src/spaceship/install.sh +++ b/src/spaceship/install.sh @@ -4,6 +4,12 @@ # Exit script on any error set -e +# Check if zsh is installed +if ! command -v zsh > /dev/null; then + echo "Zsh is not installed. Please install zsh before running this script." + exit 1 +fi + # Ensure the DevContainer user's home directory is used DEVCONTAINER_HOME="${HOME}" @@ -14,4 +20,4 @@ mkdir -p "$DEVCONTAINER_HOME/.zsh" git clone --depth=1 https://github.com/spaceship-prompt/spaceship-prompt.git "$DEVCONTAINER_HOME/.zsh/spaceship" # Make sure the spaceship-prompt is permanently sourced in the .zshrc file -echo 'source "$HOME/.zsh/spaceship/spaceship.zsh"' >> "$DEVCONTAINER_HOME/.zshrc" \ No newline at end of file +echo 'source "$DEVCONTAINER_HOME/.zsh/spaceship/spaceship.zsh"' >> "$DEVCONTAINER_HOME/.zshrc" \ No newline at end of file diff --git a/test/fzf/test.sh b/test/fzf/test.sh index 6fdf25f..4bd6b68 100644 --- a/test/fzf/test.sh +++ b/test/fzf/test.sh @@ -8,5 +8,18 @@ source dev-container-features-test-lib # Definition specific tests check "check for fzf" fzf --version +# Depending on the shell (bash, zsh, fish), check if the config was added to the profiles +if [ -n "$BASH_VERSION" ]; then + check "check for fzf key bindings and fuzzy completion for bash" grep -q 'eval "$(fzf --bash)"' "${USER_HOME}/.bashrc" +fi + +if [ -n "$ZSH_VERSION" ]; then + check "check for fzf key bindings and fuzzy completion for zsh" grep -q 'source <(fzf --zsh)' "${USER_HOME}/.zshrc" +fi + +if [ -n "$FISH_VERSION" ]; then + check "check for fzf key bindings for fish" grep -q 'fzf --fish | source' "${USER_HOME}/.config/fish/config.fish" +fi + # Report result reportResults \ No newline at end of file