Reworked the checkinstall script.

This commit is contained in:
cyteen 2026-03-11 01:58:12 +00:00
parent ff89f12574
commit f62027aa40
1 changed files with 95 additions and 123 deletions

View File

@ -1,147 +1,119 @@
#!/usr/bin/env bash
set -euo pipefail
DEST=${1:-/etc/skel}
# =============================================================================
# Lazygit Universal Deployer & Packager
# 1. Configures modular YAML settings (Themes, Delta Pager, NVIM)
# 2. Deploys to /etc/skel or current $USER
# 3. Builds a .deb package for system-wide installation
# =============================================================================
# download a specific theme for lazygit from the Catppuccin repository and set
# up an alias for lazygit that uses this theme.
# catppuccin - https://github.com/catppuccin/lazygit
# see: https://github.com/catppuccin/lazygit/README.md
BASE_THEME_URL="https://raw.githubusercontent.com/catppuccin/lazygit/main/themes-mergable"
# --- Settings ---
GITHUB_USER="jesseduffield"
PROJECT="lazygit"
BASE_THEME="mocha" # frappe, latte, macchiato, mocha
THEME_ACCENT="blue" # blue, peach, green, etc.
MAINTAINER="${SUDO_USER:-$USER}@$(hostname)"
# frappe, latte, macchiato, mocha
BASE_THEME="macchiato"
# --- Determine Target Directory ---
TARGET_DIR="${1:-/etc/skel}"
TARGET_DIR="${TARGET_DIR%/}"
REAL_USER="${SUDO_USER:-$USER}"
REAL_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
# blue, flamingo, green, lavender, maroon, mauve, peach, pink, red, rosewater,
# sapphire, sky, teal, yellow
THEME_ACCENT="peach"
THEME_NAME="${BASE_THEME}-${THEME_ACCENT}"
echo "🎯 Target: $TARGET_DIR | User: $REAL_USER"
URL="${BASE_THEME_URL}/${BASE_THEME}/${THEME_ACCENT}.yml"
# --- Prep Directories ---
CONFIG_ROOT="${TARGET_DIR}/.config/lazygit"
EXTRAS_DIR="${CONFIG_ROOT}/extras"
ALIASES_D="${TARGET_DIR}/.zsh_aliases.d"
LAZYGIT_HOME="${DEST}/.config/lazygit"
mkdir -p ${LAZYGIT_HOME}/themes
mkdir -p "$EXTRAS_DIR" "$ALIASES_D"
wget -c -O ${LAZYGIT_HOME}/themes/${THEME_NAME}.yml ${URL} ||
{
echo "Failed to download theme configuration"
exit 1
}
# --- Generate Modular Configs ---
# user configuration
mkdir -p ${LAZYGIT_HOME}
cat <<-EOF | tee ${LAZYGIT_HOME}/config.yml
# Interactive rebase onto another branch - https://github.com/jesseduffield/lazygit/issues/2517
customCommands:
- key: "I"
command: "GIT_EDITOR=\"sed -i '1s/^/break \\n /'\" git rebase --interactive --autostash --keep-empty --empty=keep --no-autosquash {{.SelectedLocalBranch.Name}}"
context: "localBranches"
# Theme (Catppuccin)
THEME_URL="https://raw.githubusercontent.com/catppuccin/lazygit/main/themes-mergable/${BASE_THEME}/${THEME_ACCENT}.yml"
curl -sL "$THEME_URL" -o "${EXTRAS_DIR}/00-theme.yml" || echo "⚠️ Theme download failed, skipping..."
# Default editor - https://www.reddit.com/r/neovim/comments/15v6mxy/comment/jwutoh2/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
os:
editPreset: 'nvim-remote'
edit: "nvr --remote-send '<C-space><cmd>q<CR><Esc><cmd>lua vim.cmd(\"e \" .. {{filename}})<CR>'"
editAtLine: "nvr --remote-send '<C-space><cmd>q<CR><Esc><cmd>lua vim.cmd(\"e \" .. {{filename}})<CR>{{line}}G'"
# hyperlinks from pager https://github.com/jesseduffield/lazygit/pull/3825
git:
paging:
colorArg: always
pager: delta --paging=never --line-numbers --hyperlinks --hyperlinks-file-link-format="lazygit-edit://{path}:{line}"
# Editor (NVIM Remote)
cat <<EOF >"${EXTRAS_DIR}/10-editor.yml"
os:
editPreset: 'nvim-remote'
edit: 'if command -v nvr >/dev/null 2>&1; then nvr --remote-wait "{{filename}}"; else nvim "{{filename}}"; fi'
editAtLine: 'if command -v nvr >/dev/null 2>&1; then nvr --remote-wait +{{line}} "{{filename}}"; else nvim +{{line}} "{{filename}}"; fi'
EOF
# Create an alias for lazygit using the theme
mkdir -p ${DEST}/.zsh_aliases.d
cat <<-EOF | tee ${DEST}/.zsh_aliases.d/005_lazygit.zsh
# This will instruct lazygit to open both config files, merge them, and then boot.
# You can add more config files, delimited by a comma, to this list
CONFIG="${LAZYGIT_HOME}/config.yml,${LAZYGIT_HOME}/themes/${THEME_NAME}.yml"
alias lazygit='LG_CONFIG_FILE="\${CONFIG}" lazygit'
alias lzg='LG_CONFIG_FILE="\${CONFIG}" lazygit'
# Git Paging (Delta)
cat <<EOF >"${EXTRAS_DIR}/30-pager-delta.yml"
git:
paging:
colorArg: always
pager: delta --dark --paging=never --line-numbers --hyperlinks
EOF
# Checkinstall lazygit to produce a deb package
cd /var/tmp || exit
GITHUB_USER=jesseduffield
PROJECT=lazygit
ARCH=$(dpkg --print-architecture)
# RELEASE=$(lastversion --format="tag" "${GITHUB_USER}/${PROJECT}") #$(lastversion --form "${PROJECT}")
LATEST_URL="https://api.github.com/repos/${GITHUB_USER}/${PROJECT}/releases/latest"
RELEASE=$(curl -L -s -H 'Accept: application/json' "${LATEST_URL}" | grep -Po '"tag_name": "v\K[^"]*')
GIT_TAG=$(curl -L -s -H 'Accept: application/json' "${LATEST_URL}" | jq -r .tag_name)
# DOWNLOAD_DIR=/tmp
RSS_FEED="https://github.com/${USER}/${PROJECT}/releases.atom"
# xdg-open ${RSS_FEED}
echo ${RSS_FEED}
# make a containing directory
mkdir -p /var/tmp/${PROJECT}-"${RELEASE}"
cd /var/tmp/${PROJECT}-"${RELEASE}" || exit
cat >./description-pak <<-EOF
A simple terminal UI for git commands
# The Zsh Alias
# This dynamically finds all .yml files and builds the LG_CONFIG_FILE string
cat <<'EOF' >"${ALIASES_D}/005_lazygit.zsh"
_gen_lg_config() {
local base="$HOME/.config/lazygit"
if [[ -d "$base" ]]; then
local files=($(find "$base" -name "*.yml" | sort))
echo "${(j:,:)files}"
fi
}
alias lg="LG_CONFIG_FILE=\$(_gen_lg_config) lazygit"
EOF
cat >./checkinstall_it.sh <<-EOF
# --- Fix Permissions ---
if [[ "$TARGET_DIR" != "/etc/skel" ]]; then
chown -R "$REAL_USER:$REAL_USER" "$CONFIG_ROOT" "$ALIASES_D"
fi
echo "ENTERING CHECKINSTALL"
# --- Build the .deb Package ---
echo "📦 Fetching latest Lazygit binary..."
API_JSON=$(curl -sL "https://api.github.com/repos/${GITHUB_USER}/${PROJECT}/releases/latest")
GIT_TAG=$(echo "$API_JSON" | grep -Po '"tag_name": *"\K[^"]*')
VERSION="${GIT_TAG#v}"
BASE_URL='https://raw.githubusercontent.com/'
BASE_USER=${GITHUB_USER}
BASE_REPO=${PROJECT}
LICENSE_URL="${BASE_URL}/${BASE_USER}/${BASE_REPO}"/master/LICENSE
# wget -c ${LICENSE_URL}
# Architecture Mapping
OS_NAME=$(uname -s)
OS_NAME=${OS_NAME,,}
ARCH_RAW=$(uname -m)
case "$ARCH_RAW" in
i386 | i686) LG_ARCH="x86" ;;
x86_64) LG_ARCH="x86_64" ;;
armv6*) LG_ARCH="armv6" ;;
armv7*) LG_ARCH="armv7" ;;
aarch64) LG_ARCH="arm64" ;;
*) LG_ARCH="$ARCH_RAW" ;;
esac
# VERSION=$(date +%Y-%m-%d_)git
VERSION=${RELEASE}
RELEASE="1"
LICENSE=MIT
# Download Binary
BUILD_DIR=$(mktemp -d)
cd "$BUILD_DIR"
URL="https://github.com/${GITHUB_USER}/${PROJECT}/releases/download/${GIT_TAG}/lazygit_${VERSION}_${OS_NAME}_${LG_ARCH}.tar.gz"
# make a new temporary directory for this use
BASE_TMP_DIR=~/tmptmp/checkinstall_tmp
mkdir -p \${BASE_TMP_DIR}
curl -Lo lazygit.tar.gz "$URL"
tar -xf lazygit.tar.gz lazygit
# do your work
checkinstall -y --fstrans \
--exclude=/root/.sudo_as_admin_successful \
--pkgname=\${PROJECT} \
--pkgversion=\${VERSION}\
--pkgrelease="\${RELEASE}" \
--pkgarch=${ARCH} \
--pkggroup=development \
--pkglicense=MIT \
--pkgsource=${LATEST_URL} \
--maintainer=cyteen@ring-zero.co.uk \
--requires=vim,git \
-D \
bash ./install.sh
# Build Script for Checkinstall
cat <<EOF >install.sh
#!/bin/bash
install -Dm755 lazygit /usr/local/bin/lazygit
EOF
chmod +x install.sh
cat >./install.sh <<-EOF
#!/bin/bash
echo "🛠️ Running Checkinstall..."
sudo checkinstall -y \
--pkgname="${PROJECT}" \
--pkgversion="${VERSION}" \
--pkgrelease="1" \
--pkggroup="utils" \
--maintainer="${MAINTAINER}" \
--provides="lazygit" \
--requires="git,curl" \
--nodoc --deldesc=yes --default \
bash ./install.sh
# allow specifying different destination directory
DIR="${DIR:-"$HOME/.local/bin"}"
# map different architecture variations to the available binaries
ARCH=$(uname -m)
case \$ARCH in
i386|i686) ARCH=x86 ;;
armv6*) ARCH=armv6 ;;
armv7*) ARCH=armv7 ;;
aarch64*) ARCH=arm64 ;;
esac
GITHUB_FILE="${PROJECT}_${RELEASE}_$(uname -s)_\${ARCH}.tar.gz"
GITHUB_URL="https://github.com/${GITHUB_USER}/${PROJECT}/releases/download/${GIT_TAG}/\${GITHUB_FILE}"
curl -Lo ${PROJECT}.tar.gz \$GITHUB_URL
tar xf ${PROJECT}.tar.gz ${PROJECT}
install -Dm 755 ${PROJECT} -t /usr/local/bin
EOF
bash ./checkinstall_it.sh
echo "✅ Deployment complete. System-wide package installed."