-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·165 lines (141 loc) · 4.52 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
#!/bin/bash
# Script to bootstrap my dev environment. This installs required tools and sets
# up various dotfiles. This also assumes it is a barebones Linux machine with
# bash available.
# It does the following -
# - Install required software packages for development (e.g. zsh, tmux, vim, git
# etc.)
# - Create symlinks. The standard config files/dotfiles in $HOME are symlinked
# to files in this # repo.
set -e
# These are the requirements for my environ
CORE_REQUIREMENTS=(zsh tmux tmuxp vim git emacs ssh htop tree neovim alacritty)
is_installed() {
req=$1
# To find out a program is installed from shell script might not be
# straightforward and consistent. See this answer for more details:
# http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script#677212
if $(command -v "$req" > /dev/null); then # if found
return 0
else
return 1
fi
}
find_linux_distro() {
distrib_id=$(cat /etc/*-release | uniq -u | grep -Po 'DISTRIB_ID=\K.*')
}
check_core_requirements() {
for req in "${CORE_REQUIREMENTS[@]}"
do
if ! $(is_installed "$req"); then
to_install=( "${to_install[@]}" $req )
fi
done
if [ -z "${to_install[0]}" ]; then
echo "All requirements satisfy.."
return 0
else
return 1
fi
}
install_core_requirements() {
packages=(${to_install[@]})
# Check the system - and decide the package manager
# TODO: add arch
if $(is_installed apt-get); then # apt based distro
package_manager="apt-get"
elif $(is_installed yum); then # yum based distro
package_manager="yum"
elif $(is_installed pacman); then # arch linux
package_manager="pacman"
fi
if [ -z "$package_manager" ]; then
echo "Oops! Could not find any known package manager!"
echo "Maybe you can modify the script to add your package manager.."
exit 1
fi
echo "Found package manager: $package_manager"
echo "Packages to be insalled: ${packages[@]}"
read -p "Continue? [y/N]: "
if [ "$REPLY" != "y" ]; then
echo "Installation aborted."
exit 0
fi
if [ "$package_manager" == "pacman" ]; then
echo "sudo pacman -S ${packages[@]}"
sudo pacman -S --noconfirm ${packages[@]}
else
echo "sudo $package_manager install -y ${packages[@]}"
# System-wide installation; use sudo
sudo "$package_manager" install -y ${packages[@]}
fi
}
create_symlinks() {
echo "Creating symlinks for necessary files.."
ln -sf ~/dotfiles/alacritty.toml ~/.config/alacritty.toml
ln -sf ~/dotfiles/vim ~/.vim
ln -sf ~/dotfiles/vim/vimrc ~/.vimrc
ln -sf ~/dotfiles/zsh/zshrc ~/.zshrc
ln -sf ~/dotfiles/zsh/zshenv ~/.zshenv
ln -sf ~/dotfiles/tmux/tmux.conf ~/.tmux.conf
ln -sf ~/dotfiles/tmux/tmuxline.conf ~/.tmuxline.conf
ln -sf ~/dotfiles/tmux/tmuxp ~/.tmuxp
ln -sf ~/dotfiles/gitconfig ~/.gitconfig
ln -sf ~/dotfiles/shell/aliases ~/.aliases
ln -sf ~/dotfiles/doom.d ~/.doom.d
mkdir -p ~/.stack/templates
ln -sf ~/dotfiles/stack/config.yaml ~/.stack/config.yaml
ln -sf ~/dotfiles/stack/anonray.hsfiles ~/.stack/templates/anonray.hsfiles
}
# install extra tools that are not in the package manager; git clone and install step..
oh_my_zsh_dir="$HOME/.oh-my-zsh"
zsh_pure_dir="$HOME/.zsh/pure"
install_from_git_repo() {
name="$1"
repo_url="$2"
clone_dir="$3"
if [ -z "$package_manager" || -z "$repo_url" || -z "$clone_dir" ]; then
echo "WARN: Not all required arguments are passed to $0"
echo "WARN: Skipping git clone..."
return;
fi
echo "Cloning $name.."
git clone --depth 1 "$repo_url" "$clone_dir"
}
install_zsh_extras() {
install_from_git_repo "oh-my-zsh" "https://github.com/ohmyzsh/ohmyzsh.git" "$oh_my_zsh_dir"
install_from_git_repo "zsh-pure-theme" "https://github.com/ohmyzsh/ohmyzsh.git" "$zsh_pure_dir"
source ~/.zshrc
}
install_doom_emacs() {
install_from_git_repo "doom emacs" "https://github.com/doomemacs/doomemacs" "$HOME/.emacs.d"
echo "Setting up doom emacs..."
"$HOME/.emacs.d/bin/doom install"
"$HOME/.emacs.d/bin/doom sync"
}
install_extra_requirements() {
install_doom_emacs \
&& install_zsh_extras \
&& set_zsh_default
}
set_zsh_default() {
echo "Setting zsh to be default shell.."
chsh -s "$(which zsh)"
}
# main install function
install() {
if check_core_requirements; then
if [ ! -d "$oh_my_zsh_dir" ]; then
set_zsh_default && install_zsh_extras
fi
create_symlinks && set_zsh_default
exit 0 # all requirements satisfy
else
install_core_requirements \
&& install_extra_requirements \
&& create_symlinks
echo "Done"
exit 0
fi
}
install