profile/install.sh

64 lines
1.3 KiB
Bash
Raw Normal View History

2018-02-17 17:19:24 +00:00
#!/bin/sh -e
2018-07-26 09:56:01 +00:00
if [ "$(uname -s)" = "Darwin" ]; then
READLINK="greadlink"
if ! command -v "${READLINK}" >/dev/null 2>&1; then
READLINK="readlink"
fi
else
READLINK="readlink"
fi
2018-02-17 17:19:24 +00:00
install_files() {
target_dir="$1"
source_dir="$("${READLINK}" -f "${2:-.}")"
target_filename_prefix="${3}"
mkdir -vp "${target_dir}"
target_dir="$("${READLINK}" -f "${target_dir}")"
2018-02-17 17:19:24 +00:00
if [ ! -d "${source_dir}" ]; then
echo "Source directory ${source_dir} does not exist, skipping."
return
fi
2018-02-19 08:26:04 +00:00
for f in "${source_dir}"/*; do
case "$(basename "$f")" in
dotfiles)
(install_files "${target_dir}" "$f" .)
2018-02-19 08:26:04 +00:00
;;
*.jq)
tmpfile="$(mktemp)"
if [ -f "$f" ]; then
tmpfile="$(mktemp)"
2018-02-19 08:26:04 +00:00
target_file="${target_dir}/$(basename "$f" .jq)"
if [ -f "$target_file" ]; then
cat "$target_file"
else
2018-02-19 08:26:04 +00:00
echo "{}"
fi | jq "$(cat "$f")" > "$tmpfile"
mv -v "$tmpfile" "$target_file"
else
echo "Expected source file with .jq extension not to be a directory."
exit 1
fi
;;
*)
if [ -d "$f" ]; then
(install_files "${target_dir}/${target_filename_prefix}$(basename "$f")" "$f")
2018-02-19 08:26:04 +00:00
else
cp -v "$f" "${target_dir}/${target_filename_prefix}$(basename "$f")"
fi
;;
esac
done
2018-02-17 17:19:24 +00:00
}
###
install_files "${HOME}" home
install_files "/etc" etc
if command -v fc-cache >/dev/null 2>&1; then
2022-06-08 15:42:21 +00:00
fc-cache -f
fi