-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·123 lines (106 loc) · 4.08 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
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
#! /bin/bash -e
cd "$(dirname "$0")"
if [ "$(uname)" = 'Darwin' ]; then
os='MACOS'
find . -type f -name '.DS_Store' -delete
# see https://support.apple.com/kb/HT208050
[ ! -f "$HOME/.bashrc" ] && echo 'export BASH_SILENCE_DEPRECATION_WARNING=1' > "$HOME/.bashrc"
elif uname -v | grep -q 'Ubuntu'; then
os='UBUNTU_DESKTOP'
else
os='UBUNTU_WSL'
sed -i '/shellcheck/s/^#*/#/' Brewfile
fi
MACOS=(
"home:$HOME"
"vscode:$HOME/Library/Application Support/Code/User"
)
UBUNTU_DESKTOP=(
"home:$HOME"
"vscode:$HOME/.config/Code/User"
)
UBUNTU_WSL=("home:$HOME")
case $os in
'MACOS' ) mappings=("${MACOS[@]}") ;;
'UBUNTU_DESKTOP' ) mappings=("${UBUNTU_DESKTOP[@]}") ;;
'UBUNTU_WSL' ) mappings=("${UBUNTU_WSL[@]}") ;;
esac
printf 'run in %s mode.\n' $os
# mainly for macOS
read -rp 'install homebrew and formulae? (y/N): ' yn
if [ "$yn" = 'y' ]; then
if ! command -v brew >/dev/null 2>&1; then
# see https://brew.sh/#install
curl -sSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh | /bin/bash
[ -d '/home/linuxbrew/.linuxbrew' ] && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
brew bundle
fi
# if `false && read yn`, yn is not updated, so check if `read` was called on `[ $? -eq 0 ]`
! command -v zsh >/dev/null 2>&1 && [ ! -x "$HOME/.local/bin/zsh" ] && \
read -rp 'install zsh and antigen via curl? (y/N): ' yn
if [ $? -eq 0 ] && [ "$yn" = 'y' ]; then
mkdir -p "$HOME/.local"
# see https://github.com/xxh/xxh-shell-zsh/blob/40d16b1/build.sh#L26-L27
curl -sSL https://github.com/romkatv/zsh-bin/releases/download/v4.1.0/zsh-5.8-linux-x86_64.tar.gz |\
tar -xzC "$HOME/.local"
# for add-zsh-hook, is-at-least and compinit
# see https://github.com/romkatv/zsh-bin/blob/v4.1.0/install#L478
"$HOME/.local/share/zsh/5.8/scripts/relocate"
# see https://github.com/zsh-users/antigen/issues/659
[ ! -f 'antigen.zsh' ] && curl -sSLo 'antigen.zsh' git.io/antigen
fi
command -v zsh >/dev/null 2>&1 && \
read -rp 'change default shell to zsh? (y/N): ' yn
if [ $? -eq 0 ] && [ "$yn" = 'y' ]; then
grep -q 'zsh' /etc/shells || command -v zsh | sudo tee -a /etc/shells >/dev/null
chsh -s "$(command -v zsh)"
fi
read -rp 'create symbolic links? (y/N): ' yn
if [ "$yn" = 'y' ]; then
for mapping in "${mappings[@]}"; do
from="${mapping%:*}"
to="${mapping#*:}"
files=$(find "$from" -type f ! -name '_*')
defaultIFS="$IFS"; IFS=$'\n'
for file in $files; do
target="$to/${file#*/}"
mkdir -p "${target%/*}"
ln -is "$PWD/$file" "$target"
done
IFS="$defaultIFS"
done
fi
[ "$os" = 'UBUNTU_DESKTOP' ] && ! command -v code >/dev/null 2>&1 && \
read -rp 'install VS Code via umake? (y/N): ' yn
if [ $? -eq 0 ] && [ "$yn" = 'y' ]; then
if ! command -v umake >/dev/null 2>&1; then
# see https://github.com/ubuntu/ubuntu-make#ppa
sudo sh -c 'add-apt-repository -y ppa:lyzardking/ubuntu-make && apt-get update && apt-get -y install ubuntu-make'
fi
# see https://github.com/ubuntu/ubuntu-make/issues/403
umake ide visual-studio-code --accept-license "$HOME/.local/share/umake/ide/visual-studio-code"
fi
# for install VS Code extensions
# see https://unix.stackexchange.com/questions/1496/why-doesnt-my-bash-script-recognize-aliases
command -v visual-studio-code >/dev/null 2>&1 && code() { visual-studio-code "$@"; }
[ "$os" != 'UBUNTU_WSL' ] && command -v code >/dev/null 2>&1 && \
read -rp 'install VS Code extensions? (y/N): ' yn
if [ $? -eq 0 ] && [ "$yn" = 'y' ]; then
while read -r extension; do
[[ "$extension" =~ ^\# ]] && continue
code --install-extension "$extension"
done < vscode/_extensions.txt
fi
[ "$os" = 'MACOS' ] && \
read -rp 'customize Finder? (y/N): ' yn
if [ $? -eq 0 ] && [ "$yn" = 'y' ]; then
# about display
defaults write com.apple.finder AppleShowAllFiles -bool true
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
defaults write com.apple.finder ShowPathbar -bool true
# about generating .DS_Store
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
killall Finder
fi