Cleanup skel

This commit is contained in:
David Tomaschik
2026-02-09 23:11:54 -08:00
parent ff0a7d150d
commit f4e3447eb7
5 changed files with 108 additions and 46 deletions

View File

@@ -3,6 +3,11 @@
set -o nounset set -o nounset
set -o errexit set -o errexit
if [ "$(uname)" != "Linux" ]; then
echo "Error: This backup script is only intended for use on Linux." >&2
exit 1
fi
DEFAULT=`echo /media/${USER}/[bB]ackup/${USER}/` DEFAULT=`echo /media/${USER}/[bB]ackup/${USER}/`
DEST="${1:-${DEFAULT}}" DEST="${1:-${DEFAULT}}"

46
bin/prune-broken-symlinks.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
# shellcheck disable=SC2039,SC2086
set -o nounset
prune_broken_symlinks() {
ask=1
dir="."
if [ "${1:-}" = "-y" ]; then
ask=0
shift
fi
if [ -n "${1:-}" ]; then
dir="$1"
fi
# Check if there are any broken symlinks first
broken_links=$(find -L "$dir" -xdev -type l -print 2>/dev/null)
if [ -z "$broken_links" ]; then
return 0
fi
if [ "$ask" -eq 1 ]; then
# Print broken links
echo "$broken_links"
printf "Delete these links? [y/N] "
read -r reply
case "$reply" in
[yY]*)
;;
*)
echo "Aborted."
return 0
;;
esac
fi
# Perform deletion
find -L "$dir" -xdev -type l -exec rm -- {} + 2>/dev/null
}
# Execute the function
prune_broken_symlinks "$@"

View File

@@ -2,7 +2,7 @@
set -ue set -ue
VER="v2.2.2" VER="v3.4.0"
FONTS=( FONTS=(
https://github.com/ryanoasis/nerd-fonts/releases/download/${VER}/DejaVuSansMono.zip https://github.com/ryanoasis/nerd-fonts/releases/download/${VER}/DejaVuSansMono.zip
@@ -13,14 +13,21 @@ FONTS=(
https://github.com/ryanoasis/nerd-fonts/releases/download/${VER}/OpenDyslexic.zip https://github.com/ryanoasis/nerd-fonts/releases/download/${VER}/OpenDyslexic.zip
) )
FPATH=${HOME}/.fonts/nerdfonts if [ "$(uname)" = "Darwin" ]; then
mkdir -p ${FPATH} FPATH="${HOME}/Library/Fonts"
cd ${FPATH} else
FPATH="${HOME}/.local/share/fonts/nerdfonts"
fi
for f in ${FONTS[@]}; do mkdir -p "${FPATH}"
BN=$(basename $f) cd "${FPATH}"
wget -O ${FPATH}/${BN} ${f}
unzip -o -d ${FPATH} ${FPATH}/${BN} for f in "${FONTS[@]}"; do
BN=$(basename "$f")
wget -O "${FPATH}/${BN}" "$f"
unzip -o -d "${FPATH}" "${FPATH}/${BN}"
done done
fc-cache -v if command -v fc-cache >/dev/null 2>&1; then
fc-cache -v
fi

View File

@@ -22,10 +22,10 @@ prune-broken-symlinks() {
echo ${FILES} echo ${FILES}
echo -n 'Delete these links? [y/n] ' echo -n 'Delete these links? [y/n] '
if read -q ; then if read -q ; then
${FINDCMD} -print0 | xargs -r -0 rm ${FINDCMD} -exec rm {} +
fi fi
echo echo
else else
${FINDCMD} -print0 | xargs -r -0 rm ${FINDCMD} -exec rm {} +
fi fi
} }

View File

@@ -12,16 +12,13 @@ HOME=${HOME:-$(cd ~ && pwd)}
case $(uname) in case $(uname) in
Linux) Linux)
FINDTYPE="-xtype" FINDTYPE="-xtype"
MD5CMD="md5sum"
;; ;;
Darwin|*BSD) Darwin|*BSD)
FINDTYPE="-type" FINDTYPE="-type"
MD5CMD="md5 -q"
;; ;;
*) *)
echo "Unknown OS: $(uname), guessing no GNU utils." echo "Unknown OS: $(uname), guessing no GNU utils."
FINDTYPE="-type" FINDTYPE="-type"
MD5CMD="md5sum"
;; ;;
esac esac
@@ -33,7 +30,14 @@ prerequisites() {
if have_command zsh ; then if have_command zsh ; then
case $- in case $- in
*i*) *i*)
case "$(getent passwd "${USER}" | cut -d: -f7)" in local shell_path
if [ "$(uname)" = "Darwin" ]; then
# dscl output is "UserShell: /bin/zsh"
shell_path="$(dscl . -read "/Users/${USER}" UserShell | awk '{print $2}')"
else
shell_path="$(getent passwd "${USER}" | cut -d: -f7)"
fi
case "${shell_path}" in
*/zsh) */zsh)
;; ;;
*) *)
@@ -91,7 +95,7 @@ install_basic_dir() {
local SRCDIR="${1}" local SRCDIR="${1}"
local DESTDIR="${2}" local DESTDIR="${2}"
local file local file
find "${SRCDIR}" ${FINDTYPE} f -print | \ find "${SRCDIR}" \( -name .git -o -name README.md -o -name .gitignore \) -prune -o ${FINDTYPE} f -print | \
while read -r file ; do while read -r file ; do
local TARGET="${DESTDIR}/${file#"${SRCDIR}"/}" local TARGET="${DESTDIR}/${file#"${SRCDIR}"/}"
mkdir -p "$(dirname "${TARGET}")" mkdir -p "$(dirname "${TARGET}")"
@@ -174,30 +178,32 @@ install_keys() {
setup_git_email() { setup_git_email() {
local gc_local="${HOME}/.gitconfig.local" local gc_local="${HOME}/.gitconfig.local"
if test -f "${gc_local}" ; then local current_email=""
return 0
if [ -f "${gc_local}" ]; then
current_email=$(git config -f "${gc_local}" user.email || true)
fi fi
if [ "${USER:0:5}" != "david" ] ; then
return 0 if [ -n "${GIT_EMAIL:-}" ]; then
# Use environment variable
git config -f "${gc_local}" user.email "${GIT_EMAIL}"
elif [ -n "${current_email}" ]; then
# Already has an email set
GIT_EMAIL="${current_email}"
else
# Prompt the user
echo -n "Enter git email (leave blank to skip): " >&2
read -r GIT_EMAIL || true
if [ -n "${GIT_EMAIL}" ]; then
git config -f "${gc_local}" user.email "${GIT_EMAIL}"
fi
fi fi
local domain="$(hostname -f | grep -E -o '[a-z0-9-]+\.[a-z0-9-]+$')" export GIT_EMAIL
case "$(echo "${domain}" | ${MD5CMD} | awk '{print $1}')" in
b21a24d528346ef7d3932306ed96ede5|a5ed434a3f5089b489576cceab824f25)
;;
*)
return 0
;;
esac
echo -e "[user]\n email=${USER}@${domain}" > "${gc_local}"
} }
read_saved_prefs() { read_saved_prefs() {
# Can't use basedir here as we don't have it yet # Can't use basedir here as we don't have it yet
local old_pref_file="$(dirname "$0")/installed-prefs"
local pref_file="$(dirname "$0")/.installed-prefs" local pref_file="$(dirname "$0")/.installed-prefs"
if [ -f "${old_pref_file}" ] && ! [ -f "${pref_file}" ] ; then
mv "${old_pref_file}" "${pref_file}"
fi
if [ -f "${pref_file}" ] ; then if [ -f "${pref_file}" ] ; then
verbose "Loading saved skel preferences from ${pref_file}" verbose "Loading saved skel preferences from ${pref_file}"
# source is a bashism # source is a bashism
@@ -223,15 +229,10 @@ echo_pref() {
} }
cleanup() { cleanup() {
# Needs zsh if [ -x "${BASEDIR}/bin/prune-broken-symlinks.sh" ]; then
if ! have_command zsh ; then "${BASEDIR}/bin/prune-broken-symlinks.sh" -y "${HOME}/.zshrc.d"
return 0 "${BASEDIR}/bin/prune-broken-symlinks.sh" -y "${HOME}/bin"
fi fi
zsh >/dev/null 2>&1 <<EOF
source ${BASEDIR}/dotfiles/zshrc.d/prune-broken-symlinks.zsh
prune-broken-symlinks -y ${HOME}/.zshrc.d
prune-broken-symlinks -y ${HOME}/bin
EOF
} }
verbose() { verbose() {
@@ -259,11 +260,14 @@ install_dotfiles() {
} }
install_main() { install_main() {
if test -d "${BASEDIR}/.git" ; then if test -d "${BASEDIR}/.git" && have_command git ; then
have_command git && \ if [ -z "$(git -C "${BASEDIR}" status --porcelain)" ]; then
git -C "${BASEDIR}" pull --ff-only git -C "${BASEDIR}" pull --ff-only || true
test "$MINIMAL" = 1 || ( have_command git && \ test "$MINIMAL" = 1 || \
git -C "${BASEDIR}" submodule update --init --recursive --depth 1 ) git -C "${BASEDIR}" submodule update --init --recursive --depth 1
else
echo "Skipping self-update: repository has local changes." >&2
fi
fi fi
test "$MINIMAL" = 1 || { test "$MINIMAL" = 1 || {
prerequisites prerequisites