dotfiles/bootstrap/autostow.sh
Marty Oehme 6fd8fcf8ca Restructure bootstrap dir, fix install.sh
With bootstrap files no longer linked to config directory, we can have
an easier directory structure with less nesting for them. Install.sh
needs to use the new structure when calling its bootstrap scripts.
2019-12-30 11:04:54 +01:00

100 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# autostow.sh
#
# Stow automatic symlinking script
#
# Invokes stow for every folder within this repository, and that's it.
ignore="${AUTOSTOW_IGNORED_DIRS:-"bootstrap:assets"}"
main() {
case "$1" in
-s | --stow)
have_stow
echo "Creating dotfile symlinks ................................................."
stow_dirs
echo "Done creating symlinks ...................................................."
exit 0
;;
-d | --delete)
have_stow
echo "Removing dotfile symlinks ................................................."
unstow_dirs
echo "Done removing symlinks ...................................................."
exit 0
;;
-v | --version)
printf "System bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.2\n"
;;
-h | --help | *)
usage
exit 0
;;
esac
shift
}
stow_dirs() {
for d in */; do
if is_ignored "$d"; then
printf "ignoring %s\n" "$d"
continue
fi
printf "stowing %s\n" "$d"
stow -S -t ~ "$d"
done
}
unstow_dirs() {
for d in */; do
if is_ignored "$d"; then
printf "ignoring %s\n" "$d"
continue
fi
printf "unstowing %s\n" "$d"
stow -D -t ~ "$d"
done
}
is_ignored() {
IFS=":"
for ign in $ignore; do
if [ "$ign" == "$1" ] || [ "$ign/" == "$1" ]; then
return 0
fi
done
return 1
}
have_stow() {
if ! type stow >/dev/null 2>&1; then
printf "GNU stow needs to be installed for this script to function. Please install stow through your package manager.\n"
exit 1
fi
}
usage() {
printf "%s\n" \
"" \
" autostow.sh - Automatically stow your dotfiles." \
" Uses GNU stow to set up automatic links to any dotfiles in subdirectories of this directory." \
"" \
" Usage: stow.sh -dhs" \
"" \
" Options:" \
"" \
" -h Print out this help." \
"" \
" -s Install dotfiles, by symlinking any directory found next to stow.sh using GNU stow." \
"" \
" -d Remove dotfiles, by unlinking any directory found next to stow.sh using GNU stow." \
"" \
""
}
main "$@"