-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTALL.sh
executable file
·94 lines (75 loc) · 2.58 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -eu -o pipefail
DOTFILES_HOME="$(cd "$(dirname "$0")" && pwd)"
DOTFILES_DATA_DIR="$HOME/.dotfiles"
DOTFILES_HIST_DIR="$DOTFILES_DATA_DIR/history"
DOTFILES_SAVE_DIR="$DOTFILES_HIST_DIR/$(date "+%Y%m%dT%H%M%S")"
DOTFILES_FIXED_HOME="/Users/.akkinoc"
function initialize_data {
printf '\e[35m%s\e[m: Initializing...\n' "$(shorten_item "$DOTFILES_DATA_DIR")"
mkdir -p -m go-rwx "$DOTFILES_DATA_DIR" "$DOTFILES_HIST_DIR" "$DOTFILES_SAVE_DIR"
}
function link_fixed_home {
local src_item="$HOME"
local dest_item="$DOTFILES_FIXED_HOME"
local save_item="$DOTFILES_SAVE_DIR/${dest_item/#\//}"
printf '\e[35m%s\e[m: Linking... \e[2m(src: %s)\e[m\n' "$(shorten_item "$dest_item")" "$(shorten_item "$src_item")"
if [[ -e "$dest_item" || -L "$dest_item" ]]; then
mkdir -p "$(dirname "$save_item")"
sudo mv "$dest_item" "$save_item"
fi
sudo ln -s "$src_item" "$dest_item"
sudo chown -h "$USER:$GROUPS" "$dest_item"
}
function link_item {
local target="$1"
local src_item="$DOTFILES_HOME/$target"
local dest_item="$HOME/$target"
local save_item="$DOTFILES_SAVE_DIR/${dest_item/#\//}"
printf '\e[35m%s\e[m: Linking... \e[2m(src: %s)\e[m\n' "$(shorten_item "$dest_item")" "$(shorten_item "$src_item")"
if [[ -e "$dest_item" || -L "$dest_item" ]]; then
mkdir -p "$(dirname "$save_item")"
mv "$dest_item" "$save_item"
fi
mkdir -p "$(dirname "$dest_item")"
ln -s "$src_item" "$dest_item"
}
function ensure_dir {
local target="$1" mode="${2:--}"
local dest_item="$HOME/$target"
printf '\e[35m%s\e[m: Ensuring... \e[2m(mode: %s)\e[m\n' "$(shorten_item "$dest_item")" "$mode"
mkdir -p -m "$mode" "$dest_item"
}
function shorten_item {
local item="$1"
item="${item/#$HOME/~}"
printf '%s' "$item"
}
function report_results {
local code=$?
if (( ! $code )); then
printf '\e[32m✔ The dotfiles installation succeeded!\e[m\n'
else
printf '\e[31m✘ The dotfiles installation failed...\e[m\n'
fi
}
trap report_results EXIT
initialize_data
link_fixed_home
link_item ".bash_profile"
link_item ".bash_profile.d"
link_item ".dotfiles/bin"
link_item ".gitattributes"
link_item ".gitconfig"
link_item ".gitignore"
ensure_dir ".gnupg" go-rwx
link_item ".gnupg/gpg.conf"
link_item ".gnupg/gpg-agent.conf"
link_item ".inputrc"
ensure_dir ".ssh" go-rwx
link_item ".ssh/config"
link_item ".ssh/github.hosts"
link_item ".vimrc"
link_item ".Brewfile"
link_item "Library/Application Support/iTerm2/DynamicProfiles/Akihiro Kondo.json"
ensure_dir "Library/Logs/iTerm2/Sessions" go-rwx