ambevar-dotfiles/.pkggen

75 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env zsh
################################################################################
## Package List Generator
## 2013-01-09
################################################################################
## This script used to save the file list. of my home config. However this is
## quiet cumbersome to maintain, especially in sync with a VCS. Since VCS can do
## the same job much more easily, I do not feel the need anymore to use this
## script for backup purpose. Still it remains useful to create package lists
## for pacman, FreeBSD, TeX Live, and so on.
## Git can create a bundle with:
##
## git bundle create --all
##
## and can list files with:
##
## git ls-files
##
## Getting a .tar archive is still quiet easy with Git:
##
## tar cvJf archive.tar.xz $(cd $HOME && git ls-files)
## This script should be compatible with ksh, bash and zsh. Issue with sh
## however: we use arrays. Therefore we do not comply with POSIX and use some
## extended syntax for file input -- the <(...) syntax. We used to write the
## file list in an array which is not support by POSIX neither.
## Note for zsh: because of the Ksh-style arrays (index starting at 0), you
## cannot use array index to append elements to arrays -- otherwise the
## KSH_ARRAYS option for zsh must be used.
## Variables
OLDPATH="$(pwd)"
cd "$HOME"
SCRIPTPATH="$(readlink -f $(dirname "$0"))"
HOST=$(hostname)
## Arch Linux
if [ -e "/usr/bin/pacman" ]; then
ARCH_PKG_OFFICIAL="$HOME/.pkg-arch-official"
ARCH_PKG_EXPLICIT="$HOME/.pkg-arch-explicit"
ARCH_PKG_AUR="$HOME/.pkg-arch-aur"
PKG_LOCAL='pacman -Qq | sort'
PKG_FOREIGN='pacman -Qmq | sort'
PKG_EXPLICIT='pacman -Qeq | sort'
comm -3 <(eval "${PKG_LOCAL}") <(eval "${PKG_FOREIGN}") >"${ARCH_PKG_OFFICIAL}-${HOST}"
eval "${PKG_EXPLICIT}" >"${ARCH_PKG_EXPLICIT}-${HOST}"
eval "${PKG_FOREIGN}" >"${ARCH_PKG_AUR}-${HOST}"
fi
## FreeBSD
if [ "$(uname)" = "FreeBSD" ]; then
pkg_info | cut -f1 -d' ' >"$HOME/.pkg-freebsd-${HOST}"
fi
## TeXlive
if type tlmgr >/dev/null 2>&1; then
HOST=$(hostname)
## We use <TAB> in the sed expressions.
TEXLIVE_BASIC="$(tlmgr info collection-basic --list | sed -n '/^ /{s/ //g;p;}' | sort)"
TEXLIVE_ALL="$(tlmgr info --only-installed | grep -v 'x86_64\|amd64' | cut -d' ' -f2 | cut -f1 -d':' | sort)"
comm -3 <(echo "$TEXLIVE_BASIC") <(echo "$TEXLIVE_ALL") | sed 's/ //g' | \
grep -vi 'collection-basic\|scheme-minimal\|texlive-common\|texlive-docindex\|texlive-en' >"$HOME/.pkg-texlive-$(uname)-${HOST}"
fi
## Cleaning
cd "${OLDPATH}"