-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·76 lines (63 loc) · 1.76 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env bash
set -u
e_newline() {
printf "\n"
}
e_header() {
printf "\033[37;1m%s\033[m\n" "$*"
}
e_error() {
printf "\033[31m%s\033[m\n" "✖ $*" 1>&2
}
chmod -R go-w $(brew --prefix)/share
DOTPATH=${DOTPATH:-$HOME/.dotfiles}
REPO="https://github.com/faruryo/dotfiles"
if [ -d "$DOTPATH" ]; then
e_header "$DOTPATH: already exists"
cd "$DOTPATH" && git switch main && git pull
else
e_newline
e_header "Downloading dotfiles..."
git clone --recursive "$REPO" "$DOTPATH"
fi
brew bundle --file $DOTPATH/Brewfile
if ! command -v volta >/dev/null 2>&1; then
curl https://get.volta.sh | bash
volta install node@latest
fi
e_header "Symlink z files..."
XDG_CONFIG_HOME=$HOME/.config
# files
declare -A dot_files
dot_files=(
["zshenv"]="zsh/.zshenv" \
["gitconfig"]="git/gitconfig" \
)
for file in "${!dot_files[@]}"; do
if [[ -f $HOME/.$file && ! -L $HOME/.$file ]]; then
mv -v $HOME/.$file $HOME/.$file.$(date +'%Y%m%d%H%M%S').backup
fi
ln -vsnf $DOTPATH/${dot_files[$file]} $HOME/.$file
done
# directories
link_dirs=(zsh git tmux)
for dir in "${link_dirs[@]}"; do
if [[ -d "$XDG_CONFIG_HOME/$dir" && ! -L "$XDG_CONFIG_HOME/$dir" ]]; then
mv -v $XDG_CONFIG_HOME/$dir $XDG_CONFIG_HOME/$dir.$(date +'%Y%m%d%H%M%S').backup
fi
ln -vsnf $DOTPATH/$dir $XDG_CONFIG_HOME/$dir
done
# 変数チェック
vars=(GIT_NAME GIT_EMAIL GIT_SIGNINGKEY)
for var in "${vars[@]}"; do
eval 'echo $'$var > /dev/null
done
# template展開
vars_str=\$$(echo ${vars[@]} | sed 's/ /$/g')
for dir in "${link_dirs[@]}"; do
# envsubst < git/gitconfig.tmpl
for file in $(find . -path "./${dir}/*.tmpl"); do
echo $file => ${file%.tmpl}
cat ${file} | envsubst "${vars_str}" > ${file%.tmpl}
done
done