-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
157 lines (122 loc) · 2.83 KB
/
install.sh
File metadata and controls
157 lines (122 loc) · 2.83 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env bash
set -e
set -u
INCLUDES=( ".??*" )
EXCLUDES=( ".git" )
DOTFILES_ROOT=$(cd $(dirname "$0"); pwd)
SYMLINK_CMD="ln -snf"
case "$OSTYPE" in
cygwin) [[ "$CYGWIN" =~ winsymlinks:native ]] || SYMLINK_CMD="mklink" ;;
msys) [[ "$MSYS" =~ winsymlinks:native ]] || SYMLINK_CMD="mklink" ;;
*) ;;
esac
function symlink() {
echo "$2 -> $1"
eval "$SYMLINK_CMD" "$1" "$2"
}
function mklink() {
local src=$(cygpath -aw "$1")
local dest=$(cygpath -aw "$2")
local opt=
if [ -d "$1" ]; then
opt="/D"
fi
## シンボリックリンクか通常ファイルなら上書き
if [ -L "$2" ] || [ -f "$2" ]; then
rm "$2"
fi
cmd /c mklink $opt "$dest" "$src" 2>&1 >/dev/null | iconv -f sjis -t utf8
}
function find_files() {
local dir=${1:-$DOTFILES_ROOT}
local ext=${2:-}
## EXCLUDES
local prune=()
if [ ${#EXCLUDES[*]} -gt 0 ]; then
prune+=("(")
for i in ${!EXCLUDES[*]}
do
if [ $i -ne 0 ]; then
prune+=("-o")
fi
prune+=("-name" "${EXCLUDES[$i]}")
done
prune+=(")" "-prune" "-o")
fi
## INCLUDES
local match=()
if [ ${#INCLUDES[*]} -gt 0 ]; then
match+=("(")
for i in ${!INCLUDES[*]}
do
if [ $i -ne 0 ]; then
match+=("-o")
fi
match+=("-name" "${INCLUDES[$i]}")
done
match+=(")")
fi
## 指定されたディレクトリ直下のファイルをリストアップ
find -H "$dir" -mindepth 1 -maxdepth 1 "${prune[@]}" "${match[@]}" -print
}
function install() {
## OS 判別
local platform=
case "$OSTYPE" in
linux*)
if [[ $(uname -a) =~ [Mm]icrosoft ]]; then
platform="wsl"
else
platform="linux"
fi
;;
darwin*)
platform="macos"
;;
cygwin | msys)
platform="cygwin"
;;
*)
echo "Unknown \$OSTYPE: '$OSTYPE'" 1>&2
;;
esac
## この OS 向けの設定ファイルについている拡張子
local ext=${platform:+.$platform}
## $DOTFILES_ROOT/.* から $HOME/.* にリンク作成
local src=
for src in $(find_files "$DOTFILES_ROOT")
do
local suffix=
case "$(basename "$src")" in
## Git 管理ディレクトリは除外
.git)
continue
;;
## OS ごとの設定ファイルは該当するものの拡張子を *.os に変更してリンク
*.wsl | *.linux | *.macos | *.cygwin)
if [[ $src == *.$platform ]]; then
suffix=".os"
else
continue
fi
;;
*)
;;
esac
local dest="$HOME/$(basename "$src" "$ext")$suffix"
symlink "$src" "$dest"
done
## Cygwin 環境での追加処理
## - 名前がドットではじまらない設定ファイル
## - %USERPROFILE% に配置しなくてはならない設定ファイル
if [ "$platform" == "cygwin" ]; then
## R GUI で必要なファイルのシンボリックリンクを作成
for file in Rconsole Rdevga;
do
if [ -f "$DOTFILES_ROOT/$file" ]; then
symlink "$DOTFILES_ROOT/$file" "$HOME/$file"
fi
done
fi
}
install