-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
111 lines (91 loc) · 2.66 KB
/
run.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env sh
link_item()
{
SRC_PATH="$1"
DST_PATH="$2"
if [ -L "$DST_PATH" ] && [ "$(realpath "$DST_PATH")" = "$(realpath "$SRC_PATH")" ]; then
echo "SKIP: $DST_PATH <- $SRC_PATH"
elif [ -f "$DST_PATH" ] || [ -L "$DST_PATH" ]; then
while true; do
read -rp "You already have a $DST_PATH. What should I do? (S)kip/(O)verwrite: " answer
case $answer in
[Oo] ) rm "$DST_PATH" && ln -s "$SRC_PATH" "$DST_PATH"; break;;
[Ss] ) echo "SKIP: $DST_PATH <- $SRC_PATH"; break;;
* ) echo "Please answer 's' for skip or 'o' for overwrite.";;
esac
done
else
mkdir -p "$(dirname "$DST_PATH")"
ln -s "$SRC_PATH" "$DST_PATH"
fi
}
link_config()
{
SRC_RELPATH="$1"
DST_RELPATH="$2"
link_item "$CONFIGS_DIR/$SRC_RELPATH" "$HOME/$DST_RELPATH"
}
link_repo()
{
SRC_RELPATH="$1"
DST_RELPATH="$2"
link_item "$REPOS_DIR/$SRC_RELPATH" "$HOME/$DST_RELPATH"
}
detect_os()
{
if [ "$(uname -s)" = "Darwin" ]; then
echo "macos"
else
echo "linux"
fi
}
load_platform_specific_module()
{
MODULE_NAME="$1"
MODULE_PATH="$LAPTOP_DIR/modules/$MODULE_NAME.$CURRENT_OS.sh"
if [ -f "$MODULE_PATH" ]; then
sh "$MODULE_PATH"
fi
}
CURRENT_OS="$(detect_os)"
if [ "$CURRENT_OS" = "macos" ]; then
if [ -z "$(command -v realpath)" ]; then
# shellcheck disable=2016
echo 'FATAL: Please install realpath with `brew install coreutils` before running this script.'
exit 1
fi
fi
LAPTOP_RUNNER=$(realpath "$0")
LAPTOP_DIR=$(dirname "$LAPTOP_RUNNER")
CONFIGS_DIR="$LAPTOP_DIR"/configs
REPOS_DIR="$LAPTOP_DIR"/repos
HOME_BIN="$HOME/bin"
WHOAMI="$(whoami)"
mkdir -p "$HOME_BIN"
load_platform_specific_module "before-packages"
load_platform_specific_module "packages"
load_platform_specific_module "after-packages"
link_config "dot.gitconfig" ".gitconfig"
link_config "dot.config/nvim" ".config/nvim"
link_config "dot.gemrc" ".gemrc"
link_config "dot.ctags" ".ctags"
link_config "Sublime Text 3" ".config/sublime-text-3"
link_repo "minpac" ".config/nvim/pack/minpac/opt/minpac"
# Ensure latest stable release of asdf
link_repo "asdf" ".asdf"
cd "$HOME/.asdf" && git checkout "$(git describe --abbrev=0 --tags)" > /dev/null
# Zsh and friends
link_config "dot.zshrc" ".zshrc"
link_repo "oh-my-zsh" ".oh-my-zsh"
link_repo "zsh-syntax-highlighting" ".oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
export PASSWORD_STORE_EXTENSIONS_DIR="$HOME/.password-store/.extensions"
mkdir -p "$PASSWORD_STORE_EXTENSIONS_DIR"
link_item "$REPOS_DIR/pass-otp/otp.bash" "$PASSWORD_STORE_EXTENSIONS_DIR"
if [ "$SHELL" != "/usr/bin/zsh" && -e "/usr/bin/zsh"]; then
sudo chsh -s /usr/bin/zsh "$WHOAMI"
zsh
fi
if [ "$SHELL" != "/bin/zsh" && -e "/bin/zsh"]; then
sudo chsh -s /bin/zsh "$WHOAMI"
zsh
fi