From 501fb4cd64d8660b185415747dcc5dc66853493a Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Sat, 17 Feb 2018 18:19:24 +0100 Subject: [PATCH] Add initial installation script. --- install.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..3b6ed46 --- /dev/null +++ b/install.sh @@ -0,0 +1,39 @@ +#!/bin/sh -e + +install_dotfiles() { + local target_dir="$1" + for d in dotfiles/*; do + cp -v "$d" "${target_dir}/$(basename "$d")" + done +} + +install_files() { + local target_dir="$1" + local source_dir="${2:-.}" + if [ ! -d "${source_dir}" ]; then + echo "Source directory ${source_dir} does not exist, skipping." + return + fi + ( + cd "${source_dir}" + for f in *; do + case "$f" in + ^dotfiles) + install_dotfiles "${target_dir}" + ;; + *) + if [ -d "$f" ]; then + (cd "$d" && install_files "${target_dir}/$f") + else + cp -v "$f" "${target_dir}" + fi + ;; + esac + done + ) +} + +### + +install_files "${HOME}" home +install_files "/etc" etc