-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·180 lines (150 loc) · 4.18 KB
/
install
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
#
# Install important packages AND
# Symlink dotfiles in home with dotfiles in this folder.
# Backs up home files in the dotfiles/backup folder.
#
# installs files passed or .* if this script is run with no arguments.
# ignore installing those files, they are not to be symlinked
GLOBIGNORE='.:..:.DS_Store:.git:.gitignore'
homebrew_packages="$(cat packages_brew.csv | xargs)"
apt_packages="$(cat packages_apt.csv | xargs)"
spin_packages="$(cat packages_spin.csv | xargs)"
os="$(uname -s | tr -d '\n')"
is_installed () {
# This works with scripts and programs. For more info, check
# http://goo.gl/B9683D
type $1 &> /dev/null 2>&1
}
is_brew_installed () {
brew --prefix "$1" &> /dev/null
}
installed=""
is_apt_installed() {
[[ -z $installed ]] && installed="$(apt list --installed)"
echo $installed | grep -q "$1"
}
install_homebrew () {
if ! is_installed brew; then
step "Installing Homebrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
}
install_homebrew_packages () {
step "Installing missing packages: $homebrew_packages"
for package in $homebrew_packages; do
if ! is_brew_installed $package; then
echo "Installing $package"
brew install $package
fi
done
}
install_apt_packages () {
step "Installing missing packages: $apt_packages"
for package in $apt_packages; do
if ! is_apt_installed $package; then
echo "Installing $package"
sudo apt-get install -y $package
fi
done
}
install_spin_packages () {
step "Installing missing packages: $spin_packages"
for package in $spin_packages; do
if ! is_apt_installed $package; then
echo "Installing $package"
sudo apt-get install -y $package
fi
done
}
install_oh_my_zsh () {
if ! [[ -d ~/.oh-my-zsh ]] ; then
step "Installing oh-my-zsh"
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# make zsh default shell
chsh -s `which zsh`
fi
}
create_backup_folder () {
mkdir -p "./backup"
}
backup_file () {
local file="$1"
local current_dir="$2"
if [[ -f ${file} ]] || [[ -d ${file} ]]; then
echo "backing up ${file} to ${current_dir}/backup..."
mv "${file}" "${current_dir}/backup"
return "$?"
fi
}
install_file () {
local file="$1"
local current_dir="$2"
local dot_file_path="${current_dir}/${file}"
# We don't want to install on top of symlinks
if [[ -L ${file} ]]; then
echo "${file} is already installed."
elif [[ -e ${dot_file_path} ]]; then
# backup_file "${file}" "${current_dir}"
echo "installing ${file}"
ln -s "${dot_file_path}" "${HOME}/${file}"
fi
}
install_nvim_dependencies() {
if ! ls -A "$HOME/.config/nvim/plugged" &> /dev/null; then
step "Installing nvim dependencies"
echo 'PlugInstall | qa!' | nvim -n -u $HOME/.config/nvim/config/plugins.vim -es
(cd $HOME/.config/nvim/plugged/coc.nvim && yarn)
echo 'CocInstall -sync coc-json coc-tsserver coc-snippets | qa!' | nvim -n -es
fi
}
step() {
cat <<-EOF 1>&2
==============================
$1
------------------------------
EOF
}
main () {
local dot_files="${@:-.*}"
local current_dir
current_dir="$(pwd)"
install_oh_my_zsh
if [[ $# -eq 0 ]]; then
if [[ $os = "Darwin" ]]; then
install_homebrew
install_homebrew_packages
fi
if [[ $SPIN ]]; then
install_spin_packages
rsync -av "$HOME/.config/" "$current_dir/config/"
rm -rf $HOME/.config
rm $HOME/.zshrc
rm $HOME/.gitconfig
fi
fi
step "Symlinking dotfile(s): $dot_files"
for dot_file in bin $dot_files; do
cd "$HOME"
install_file "$dot_file" "$current_dir"
cd "$current_dir"
done
if [[ $SPIN ]]; then
ln -s bin binbin
cd "$HOME"
install_file binbin "$current_dir"
cd "$current_dir"
fi
if [[ $SPIN ]]; then
step "spin git config"
git config --global user.email "[email protected]"
git config --global user.name "CP Clermont"
git config --global --unset-all credential.helper
fi
if [[ "$SPIN" = 1 ]] && [[ -f ~/.data/cartridges/default/setup.sh ]]; then
. ~/.data/cartridges/default/setup.sh
fi
install_nvim_dependencies
}
main "$@"
unset GLOBIGNORE