mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 13:19:07 -07:00
Cleanup skel
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
set -o nounset
|
||||
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}/`
|
||||
DEST="${1:-${DEFAULT}}"
|
||||
|
||||
|
||||
46
bin/prune-broken-symlinks.sh
Executable file
46
bin/prune-broken-symlinks.sh
Executable 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 "$@"
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
set -ue
|
||||
|
||||
VER="v2.2.2"
|
||||
VER="v3.4.0"
|
||||
|
||||
FONTS=(
|
||||
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
|
||||
)
|
||||
|
||||
FPATH=${HOME}/.fonts/nerdfonts
|
||||
mkdir -p ${FPATH}
|
||||
cd ${FPATH}
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
FPATH="${HOME}/Library/Fonts"
|
||||
else
|
||||
FPATH="${HOME}/.local/share/fonts/nerdfonts"
|
||||
fi
|
||||
|
||||
for f in ${FONTS[@]}; do
|
||||
BN=$(basename $f)
|
||||
wget -O ${FPATH}/${BN} ${f}
|
||||
unzip -o -d ${FPATH} ${FPATH}/${BN}
|
||||
mkdir -p "${FPATH}"
|
||||
cd "${FPATH}"
|
||||
|
||||
for f in "${FONTS[@]}"; do
|
||||
BN=$(basename "$f")
|
||||
wget -O "${FPATH}/${BN}" "$f"
|
||||
unzip -o -d "${FPATH}" "${FPATH}/${BN}"
|
||||
done
|
||||
|
||||
fc-cache -v
|
||||
if command -v fc-cache >/dev/null 2>&1; then
|
||||
fc-cache -v
|
||||
fi
|
||||
|
||||
@@ -22,10 +22,10 @@ prune-broken-symlinks() {
|
||||
echo ${FILES}
|
||||
echo -n 'Delete these links? [y/n] '
|
||||
if read -q ; then
|
||||
${FINDCMD} -print0 | xargs -r -0 rm
|
||||
${FINDCMD} -exec rm {} +
|
||||
fi
|
||||
echo
|
||||
else
|
||||
${FINDCMD} -print0 | xargs -r -0 rm
|
||||
${FINDCMD} -exec rm {} +
|
||||
fi
|
||||
}
|
||||
|
||||
74
install.sh
74
install.sh
@@ -12,16 +12,13 @@ HOME=${HOME:-$(cd ~ && pwd)}
|
||||
case $(uname) in
|
||||
Linux)
|
||||
FINDTYPE="-xtype"
|
||||
MD5CMD="md5sum"
|
||||
;;
|
||||
Darwin|*BSD)
|
||||
FINDTYPE="-type"
|
||||
MD5CMD="md5 -q"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown OS: $(uname), guessing no GNU utils."
|
||||
FINDTYPE="-type"
|
||||
MD5CMD="md5sum"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -33,7 +30,14 @@ prerequisites() {
|
||||
if have_command zsh ; then
|
||||
case $- in
|
||||
*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)
|
||||
;;
|
||||
*)
|
||||
@@ -91,7 +95,7 @@ install_basic_dir() {
|
||||
local SRCDIR="${1}"
|
||||
local DESTDIR="${2}"
|
||||
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
|
||||
local TARGET="${DESTDIR}/${file#"${SRCDIR}"/}"
|
||||
mkdir -p "$(dirname "${TARGET}")"
|
||||
@@ -174,30 +178,32 @@ install_keys() {
|
||||
|
||||
setup_git_email() {
|
||||
local gc_local="${HOME}/.gitconfig.local"
|
||||
if test -f "${gc_local}" ; then
|
||||
return 0
|
||||
local current_email=""
|
||||
|
||||
if [ -f "${gc_local}" ]; then
|
||||
current_email=$(git config -f "${gc_local}" user.email || true)
|
||||
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
|
||||
local domain="$(hostname -f | grep -E -o '[a-z0-9-]+\.[a-z0-9-]+$')"
|
||||
case "$(echo "${domain}" | ${MD5CMD} | awk '{print $1}')" in
|
||||
b21a24d528346ef7d3932306ed96ede5|a5ed434a3f5089b489576cceab824f25)
|
||||
;;
|
||||
*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
echo -e "[user]\n email=${USER}@${domain}" > "${gc_local}"
|
||||
export GIT_EMAIL
|
||||
}
|
||||
|
||||
read_saved_prefs() {
|
||||
# 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"
|
||||
if [ -f "${old_pref_file}" ] && ! [ -f "${pref_file}" ] ; then
|
||||
mv "${old_pref_file}" "${pref_file}"
|
||||
fi
|
||||
if [ -f "${pref_file}" ] ; then
|
||||
verbose "Loading saved skel preferences from ${pref_file}"
|
||||
# source is a bashism
|
||||
@@ -223,15 +229,10 @@ echo_pref() {
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
# Needs zsh
|
||||
if ! have_command zsh ; then
|
||||
return 0
|
||||
if [ -x "${BASEDIR}/bin/prune-broken-symlinks.sh" ]; then
|
||||
"${BASEDIR}/bin/prune-broken-symlinks.sh" -y "${HOME}/.zshrc.d"
|
||||
"${BASEDIR}/bin/prune-broken-symlinks.sh" -y "${HOME}/bin"
|
||||
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() {
|
||||
@@ -259,11 +260,14 @@ install_dotfiles() {
|
||||
}
|
||||
|
||||
install_main() {
|
||||
if test -d "${BASEDIR}/.git" ; then
|
||||
have_command git && \
|
||||
git -C "${BASEDIR}" pull --ff-only
|
||||
test "$MINIMAL" = 1 || ( have_command git && \
|
||||
git -C "${BASEDIR}" submodule update --init --recursive --depth 1 )
|
||||
if test -d "${BASEDIR}/.git" && have_command git ; then
|
||||
if [ -z "$(git -C "${BASEDIR}" status --porcelain)" ]; then
|
||||
git -C "${BASEDIR}" pull --ff-only || true
|
||||
test "$MINIMAL" = 1 || \
|
||||
git -C "${BASEDIR}" submodule update --init --recursive --depth 1
|
||||
else
|
||||
echo "Skipping self-update: repository has local changes." >&2
|
||||
fi
|
||||
fi
|
||||
test "$MINIMAL" = 1 || {
|
||||
prerequisites
|
||||
|
||||
Reference in New Issue
Block a user