From b6aa9f86be5a71ab2859a40c6bc87dc3de320983 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 31 May 2016 10:20:34 +0200 Subject: [PATCH] Improve installation script. --- install.sh | 65 +++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 42 deletions(-) diff --git a/install.sh b/install.sh index 61bc493..a9cd890 100755 --- a/install.sh +++ b/install.sh @@ -6,29 +6,30 @@ commandAvailable() { command -v $1 >/dev/null } -confirm () { - # call with a prompt string or use a default - read -r -p "${1:-Are you sure? [y/N]} " response - case $response in - [yY][eE][sS]|[yY]) - true - ;; - *) - false - ;; - esac -} +installIfAvailable() { + if [ $# -lt 1 ]; then + echo "Usage: $0 command_required [package_name]" >&2 + return 1 + fi -confirmAndLink() { - if [ -e $2 ] - then - echo "Destination $2 already exists and will be overwritten." - confirm && rm -rf $2 && ln -s $1 $2 + COMMAND=$1 + if [ $# -eq 2 ]; then + PACKAGE=$2 else - ln -s $1 $2 + PACKAGE=$COMMAND + fi + + if commandAvailable $COMMAND; then + echo "Installing configuration files for $COMMAND…" + stow -t $HOME $PACKAGE fi } +if ! commandAvailable stow; then + echo "Error: stow not available. Skipping installation." >&2 + exit 1 +fi + cd $DIR && echo "Current working directory is ${DIR}" echo -n "Downloading dependencies... " @@ -38,34 +39,14 @@ git submodule init &> /dev/null && git submodule update &> /dev/null \ echo "done." -if ! commandAvailable stow; then - echo "Error: stow not available. Skipping installation." >&2; - exit 1; -fi -# Install vim -if commandAvailable vim -then - echo "Installing configuration files for vim."; - stow -t $HOME vim -fi - -# Install zsh, if relevant. -if commandAvailable zsh -then - echo "Installing configuration files for zsh." - stow -t $HOME zsh -fi - -if commandAvailable "sqlite3" -then - echo "Installing configuration files for sqlite." - stow -t $HOME sqlite -fi +installIfAvailable vim +installIfAvailable zsh +installIfAvailable sqlite3 sqlite # Install all XDG compatible packages -echo "Installing remaining packages" +echo "Installing remaining packages…" stow -t $HOME pacman git echo "Installation finished."