@ -1,6 +1,6 @@
#!/bin/zsh
#!/bin/zsh
# .files/installer
# .files/install
# (c) 2014 MORI Taeyeon
# (c) 2014-2017 MORI Taeyeon
# Paths & Utils
# Paths & Utils
DOT="$(realpath "$(dirname "$0")")"
DOT="$(realpath "$(dirname "$0")")"
@ -9,7 +9,9 @@ cd "$DOT"
setopt EXTENDED_GLOB
setopt EXTENDED_GLOB
source "$DOT/lib/libzsh-utils.zsh"
source "$DOT/lib/libzsh-utils.zsh"
# Parse commandline
# Parse commandline
# =============================
OVERWRITE=false
OVERWRITE=false
ASK=true
ASK=true
@ -41,7 +43,9 @@ for arg in "$@"; do
done
done
[[ -n "$STATE" ]] && err "Option $STATE is missing it's parameter!" && exit 1
[[ -n "$STATE" ]] && err "Option $STATE is missing it's parameter!" && exit 1
# Helper functions
# Helper functions
# =============================
function generate() {
function generate() {
[[ -e "$1" ]] && ! $OVERWRITE && ! grep -q "Generated by .files/install" "$1" && \
[[ -e "$1" ]] && ! $OVERWRITE && ! grep -q "Generated by .files/install" "$1" && \
err "Custom version of $1 detected. Please delete it before running .files/install" && exit 1
err "Custom version of $1 detected. Please delete it before running .files/install" && exit 1
@ -58,6 +62,9 @@ function relink() {
color 31 ln -s "$(relpath "$1" "$(dirname "$2")")" "$2"
color 31 ln -s "$(relpath "$1" "$(dirname "$2")")" "$2"
}
}
# Prepare
# =============================
# Update git modules
# Update git modules
msg "Updating git submodules..."
msg "Updating git submodules..."
git submodule update --init --recursive
git submodule update --init --recursive
@ -77,12 +84,16 @@ else
color 36 echo " default EMAIL=\"$EMAIL\""
color 36 echo " default EMAIL=\"$EMAIL\""
fi
fi
# Write down answers
color 32 echo " Writing etc/user-info"
color 32 echo " Writing etc/user-info"
generate "$DOT/etc/user-info" <<EOF
generate "$DOT/etc/user-info" <<EOF
REALNAME="$REALNAME"
REALNAME="$REALNAME"
EMAIL="$EMAIL"
EMAIL="$EMAIL"
EOF
EOF
# Write files to $HOME
# =============================
# Setup dotfiles
# Setup dotfiles
msg "Linking dotfiles..."
msg "Linking dotfiles..."
for file in "$DOT/dotfiles"/*; do
for file in "$DOT/dotfiles"/*; do
@ -113,7 +124,9 @@ msg "Linking .config files... ($XDG_CONFIG_HOME)"
done
done
)
)
# Setup git
# Setup git
# =============================
msg "Setting up Git configuration..."
msg "Setting up Git configuration..."
GIT="$DOT/git"
GIT="$DOT/git"
@ -138,7 +151,9 @@ generate "$GIT/user-info" <<EOF
email = $EMAIL
email = $EMAIL
EOF
EOF
# Setup ZSH/Prezto
# Setup ZSH/Prezto
# =============================
msg "Setting up ZSH configuration..."
msg "Setting up ZSH configuration..."
ZSH="$DOT/zsh"
ZSH="$DOT/zsh"
@ -154,7 +169,10 @@ for file in zshrc zpreztorc zlogin zlogout zprofile; do
relink "$ZSH/$file" "$ZSH/.$file"
relink "$ZSH/$file" "$ZSH/.$file"
done
done
relink "$ZSH/prezto" "$ZSH/.zprezto"
# Do misc setup
# =============================
test -f "$DOTFILES/install.extra" && "$DOTFILES/install.extra"
# Check login shell
# Check login shell
if getent passwd $(id -un) | grep -q 'zsh$'; then
if getent passwd $(id -un) | grep -q 'zsh$'; then
@ -164,7 +182,7 @@ else
chsh -s "$(which zsh)"
chsh -s "$(which zsh)"
fi
fi
# Done.
warn "You may need to relog for all changes to take effect."
warn "You may need to relog for all changes to take effect."
warn "If you're currently running zsh, you definitely need to at least restart the shell to apply changes."
warn "If you're currently running zsh, you definitely need to at least restart the shell to apply changes."