Reworked the checkinstall script.
This commit is contained in:
parent
ff89f12574
commit
f62027aa40
|
|
@ -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"
|
||||||
|
os:
|
||||||
editPreset: 'nvim-remote'
|
editPreset: 'nvim-remote'
|
||||||
edit: "nvr --remote-send '<C-space><cmd>q<CR><Esc><cmd>lua vim.cmd(\"e \" .. {{filename}})<CR>'"
|
edit: 'if command -v nvr >/dev/null 2>&1; then nvr --remote-wait "{{filename}}"; else nvim "{{filename}}"; fi'
|
||||||
editAtLine: "nvr --remote-send '<C-space><cmd>q<CR><Esc><cmd>lua vim.cmd(\"e \" .. {{filename}})<CR>{{line}}G'"
|
editAtLine: 'if command -v nvr >/dev/null 2>&1; then nvr --remote-wait +{{line}} "{{filename}}"; else nvim +{{line}} "{{filename}}"; fi'
|
||||||
|
EOF
|
||||||
|
|
||||||
# hyperlinks from pager https://github.com/jesseduffield/lazygit/pull/3825
|
# Git Paging (Delta)
|
||||||
git:
|
cat <<EOF >"${EXTRAS_DIR}/30-pager-delta.yml"
|
||||||
|
git:
|
||||||
paging:
|
paging:
|
||||||
colorArg: always
|
colorArg: always
|
||||||
pager: delta --paging=never --line-numbers --hyperlinks --hyperlinks-file-link-format="lazygit-edit://{path}:{line}"
|
pager: delta --dark --paging=never --line-numbers --hyperlinks
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Create an alias for lazygit using the theme
|
# The Zsh Alias
|
||||||
mkdir -p ${DEST}/.zsh_aliases.d
|
# This dynamically finds all .yml files and builds the LG_CONFIG_FILE string
|
||||||
cat <<-EOF | tee ${DEST}/.zsh_aliases.d/005_lazygit.zsh
|
cat <<'EOF' >"${ALIASES_D}/005_lazygit.zsh"
|
||||||
# This will instruct lazygit to open both config files, merge them, and then boot.
|
_gen_lg_config() {
|
||||||
# You can add more config files, delimited by a comma, to this list
|
local base="$HOME/.config/lazygit"
|
||||||
|
if [[ -d "$base" ]]; then
|
||||||
CONFIG="${LAZYGIT_HOME}/config.yml,${LAZYGIT_HOME}/themes/${THEME_NAME}.yml"
|
local files=($(find "$base" -name "*.yml" | sort))
|
||||||
alias lazygit='LG_CONFIG_FILE="\${CONFIG}" lazygit'
|
echo "${(j:,:)files}"
|
||||||
alias lzg='LG_CONFIG_FILE="\${CONFIG}" lazygit'
|
fi
|
||||||
|
}
|
||||||
|
alias lg="LG_CONFIG_FILE=\$(_gen_lg_config) lazygit"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Checkinstall lazygit to produce a deb package
|
# --- Fix Permissions ---
|
||||||
cd /var/tmp || exit
|
if [[ "$TARGET_DIR" != "/etc/skel" ]]; then
|
||||||
|
chown -R "$REAL_USER:$REAL_USER" "$CONFIG_ROOT" "$ALIASES_D"
|
||||||
|
fi
|
||||||
|
|
||||||
GITHUB_USER=jesseduffield
|
# --- Build the .deb Package ---
|
||||||
PROJECT=lazygit
|
echo "📦 Fetching latest Lazygit binary..."
|
||||||
ARCH=$(dpkg --print-architecture)
|
API_JSON=$(curl -sL "https://api.github.com/repos/${GITHUB_USER}/${PROJECT}/releases/latest")
|
||||||
# RELEASE=$(lastversion --format="tag" "${GITHUB_USER}/${PROJECT}") #$(lastversion --form "${PROJECT}")
|
GIT_TAG=$(echo "$API_JSON" | grep -Po '"tag_name": *"\K[^"]*')
|
||||||
LATEST_URL="https://api.github.com/repos/${GITHUB_USER}/${PROJECT}/releases/latest"
|
VERSION="${GIT_TAG#v}"
|
||||||
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"
|
# Architecture Mapping
|
||||||
# xdg-open ${RSS_FEED}
|
OS_NAME=$(uname -s)
|
||||||
echo ${RSS_FEED}
|
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
|
||||||
|
|
||||||
# make a containing directory
|
# Download Binary
|
||||||
mkdir -p /var/tmp/${PROJECT}-"${RELEASE}"
|
BUILD_DIR=$(mktemp -d)
|
||||||
cd /var/tmp/${PROJECT}-"${RELEASE}" || exit
|
cd "$BUILD_DIR"
|
||||||
|
URL="https://github.com/${GITHUB_USER}/${PROJECT}/releases/download/${GIT_TAG}/lazygit_${VERSION}_${OS_NAME}_${LG_ARCH}.tar.gz"
|
||||||
|
|
||||||
cat >./description-pak <<-EOF
|
curl -Lo lazygit.tar.gz "$URL"
|
||||||
A simple terminal UI for git commands
|
tar -xf lazygit.tar.gz lazygit
|
||||||
|
|
||||||
|
# Build Script for Checkinstall
|
||||||
|
cat <<EOF >install.sh
|
||||||
|
#!/bin/bash
|
||||||
|
install -Dm755 lazygit /usr/local/bin/lazygit
|
||||||
EOF
|
EOF
|
||||||
|
chmod +x install.sh
|
||||||
|
|
||||||
cat >./checkinstall_it.sh <<-EOF
|
echo "🛠️ Running Checkinstall..."
|
||||||
|
sudo checkinstall -y \
|
||||||
echo "ENTERING CHECKINSTALL"
|
--pkgname="${PROJECT}" \
|
||||||
|
--pkgversion="${VERSION}" \
|
||||||
BASE_URL='https://raw.githubusercontent.com/'
|
--pkgrelease="1" \
|
||||||
BASE_USER=${GITHUB_USER}
|
--pkggroup="utils" \
|
||||||
BASE_REPO=${PROJECT}
|
--maintainer="${MAINTAINER}" \
|
||||||
LICENSE_URL="${BASE_URL}/${BASE_USER}/${BASE_REPO}"/master/LICENSE
|
--provides="lazygit" \
|
||||||
# wget -c ${LICENSE_URL}
|
--requires="git,curl" \
|
||||||
|
--nodoc --deldesc=yes --default \
|
||||||
# VERSION=$(date +%Y-%m-%d_)git
|
|
||||||
VERSION=${RELEASE}
|
|
||||||
RELEASE="1"
|
|
||||||
LICENSE=MIT
|
|
||||||
|
|
||||||
# make a new temporary directory for this use
|
|
||||||
BASE_TMP_DIR=~/tmptmp/checkinstall_tmp
|
|
||||||
mkdir -p \${BASE_TMP_DIR}
|
|
||||||
|
|
||||||
# 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
|
bash ./install.sh
|
||||||
EOF
|
|
||||||
|
|
||||||
cat >./install.sh <<-EOF
|
echo "✅ Deployment complete. System-wide package installed."
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue