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 #!/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 # --- Settings ---
# up an alias for lazygit that uses this theme. GITHUB_USER="jesseduffield"
# catppuccin - https://github.com/catppuccin/lazygit PROJECT="lazygit"
# see: https://github.com/catppuccin/lazygit/README.md BASE_THEME="mocha" # frappe, latte, macchiato, mocha
BASE_THEME_URL="https://raw.githubusercontent.com/catppuccin/lazygit/main/themes-mergable" THEME_ACCENT="blue" # blue, peach, green, etc.
MAINTAINER="${SUDO_USER:-$USER}@$(hostname)"
# frappe, latte, macchiato, mocha # --- Determine Target Directory ---
BASE_THEME="macchiato" 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, echo "🎯 Target: $TARGET_DIR | User: $REAL_USER"
# sapphire, sky, teal, yellow
THEME_ACCENT="peach"
THEME_NAME="${BASE_THEME}-${THEME_ACCENT}"
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 "$EXTRAS_DIR" "$ALIASES_D"
mkdir -p ${LAZYGIT_HOME}/themes
wget -c -O ${LAZYGIT_HOME}/themes/${THEME_NAME}.yml ${URL} || # --- Generate Modular Configs ---
{
echo "Failed to download theme configuration"
exit 1
}
# user configuration # Theme (Catppuccin)
mkdir -p ${LAZYGIT_HOME} THEME_URL="https://raw.githubusercontent.com/catppuccin/lazygit/main/themes-mergable/${BASE_THEME}/${THEME_ACCENT}.yml"
cat <<-EOF | tee ${LAZYGIT_HOME}/config.yml curl -sL "$THEME_URL" -o "${EXTRAS_DIR}/00-theme.yml" || echo "⚠️ Theme download failed, skipping..."
# 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"
# 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 # Editor (NVIM Remote)
os: cat <<EOF >"${EXTRAS_DIR}/10-editor.yml"
editPreset: 'nvim-remote' os:
edit: "nvr --remote-send '<C-space><cmd>q<CR><Esc><cmd>lua vim.cmd(\"e \" .. {{filename}})<CR>'" editPreset: 'nvim-remote'
editAtLine: "nvr --remote-send '<C-space><cmd>q<CR><Esc><cmd>lua vim.cmd(\"e \" .. {{filename}})<CR>{{line}}G'" 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'
# 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}"
EOF EOF
# Create an alias for lazygit using the theme # Git Paging (Delta)
mkdir -p ${DEST}/.zsh_aliases.d cat <<EOF >"${EXTRAS_DIR}/30-pager-delta.yml"
cat <<-EOF | tee ${DEST}/.zsh_aliases.d/005_lazygit.zsh git:
# This will instruct lazygit to open both config files, merge them, and then boot. paging:
# You can add more config files, delimited by a comma, to this list colorArg: always
pager: delta --dark --paging=never --line-numbers --hyperlinks
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'
EOF EOF
# Checkinstall lazygit to produce a deb package # The Zsh Alias
cd /var/tmp || exit # This dynamically finds all .yml files and builds the LG_CONFIG_FILE string
cat <<'EOF' >"${ALIASES_D}/005_lazygit.zsh"
GITHUB_USER=jesseduffield _gen_lg_config() {
PROJECT=lazygit local base="$HOME/.config/lazygit"
ARCH=$(dpkg --print-architecture) if [[ -d "$base" ]]; then
# RELEASE=$(lastversion --format="tag" "${GITHUB_USER}/${PROJECT}") #$(lastversion --form "${PROJECT}") local files=($(find "$base" -name "*.yml" | sort))
LATEST_URL="https://api.github.com/repos/${GITHUB_USER}/${PROJECT}/releases/latest" echo "${(j:,:)files}"
RELEASE=$(curl -L -s -H 'Accept: application/json' "${LATEST_URL}" | grep -Po '"tag_name": "v\K[^"]*') fi
GIT_TAG=$(curl -L -s -H 'Accept: application/json' "${LATEST_URL}" | jq -r .tag_name) }
# DOWNLOAD_DIR=/tmp alias lg="LG_CONFIG_FILE=\$(_gen_lg_config) lazygit"
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
EOF 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/' # Architecture Mapping
BASE_USER=${GITHUB_USER} OS_NAME=$(uname -s)
BASE_REPO=${PROJECT} OS_NAME=${OS_NAME,,}
LICENSE_URL="${BASE_URL}/${BASE_USER}/${BASE_REPO}"/master/LICENSE ARCH_RAW=$(uname -m)
# wget -c ${LICENSE_URL} 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 # Download Binary
VERSION=${RELEASE} BUILD_DIR=$(mktemp -d)
RELEASE="1" cd "$BUILD_DIR"
LICENSE=MIT 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 curl -Lo lazygit.tar.gz "$URL"
BASE_TMP_DIR=~/tmptmp/checkinstall_tmp tar -xf lazygit.tar.gz lazygit
mkdir -p \${BASE_TMP_DIR}
# do your work # Build Script for Checkinstall
checkinstall -y --fstrans \ cat <<EOF >install.sh
--exclude=/root/.sudo_as_admin_successful \ #!/bin/bash
--pkgname=\${PROJECT} \ install -Dm755 lazygit /usr/local/bin/lazygit
--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
EOF EOF
chmod +x install.sh
cat >./install.sh <<-EOF echo "🛠️ Running Checkinstall..."
#!/bin/bash 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 echo "✅ Deployment complete. System-wide package installed."
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