-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·172 lines (146 loc) · 4.29 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
#!/bin/bash
DOTFILES_DIRS=(python tmux git vim zsh ssh i3 subversion alacritty)
PACKAGES_FILE="packages"
LIGHT_GREEN="\033[1;32m"
LIGHT_RED="\033[1;31m"
NO_COLOR="\033[0m"
OH_MY_ZSH_PATH="${HOME}/.oh-my-zsh"
ZSH_AUTOSUGGESTIONS_PATH="${OH_MY_ZSH_PATH}/custom/plugins/zsh-autosuggestions"
VIM_BASE_PATH="${HOME}/.vim/"
VIM_VUNDLE_PATH="${VIM_BASE_PATH}/bundle/Vundle.vim"
function pushd () {
command pushd "$@" > /dev/null
}
function popd () {
command popd "$@" > /dev/null
}
function store_sudo_password {
for ((attempts = 0; attempts < 3; attempts++)); do
IFS= read -srp "${USER} password: " SUDO_PASSWORD
sudo -k
if sudo -lS &> /dev/null << EOF
${SUDO_PASSWORD}
EOF
then
return
else
echo -e "\nPermission denied, please try again."
fi
done
echo -e "${LIGHT_RED}[ERROR]${NO_COLOR} Permission denied"
exit 1
}
function store_option {
local promt="$@"
read -p "${promt}" answer
case ${answer} in
y)
echo "True"
;;
esac
}
function store_installation_options {
INSTALL_PACKAGES=$(store_option "Are you going to install base .deb packages? y/n: ")
INSTALL_PLUGINS=$(store_option "Are you going to install zsh and vim plugins? y/n: ")
INSTALL_DOTFILES=$(store_option "Are you going to overwrite existing dotfiles? y/n: ")
CHANGE_SHELL=$(store_option "Are you going change corrent shell to zsh y/n: ")
}
function install_packages {
local packages="$(cat ${PACKAGES_FILE})"
set +e
for package in ${packages}; do
echo ${SUDO_PASSWORD} | sudo apt-get install -y ${package}
if [ $? -ne 0 ]; then
echo -e "${LIGHT_RED}[FAILURE]${NO_COLOR} ${package} package installation failed"
else
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} \"${package}\" package is installed"
fi
done
echo ${SUDO_PASSWORD} | sudo cargo install alacritty
set -e
}
function install_plugins {
if [[ ! -d ${OH_MY_ZSH_PATH} ]]; then
bash -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -) --unattended"
fi
if [[ ! -d ${ZSH_AUTOSUGGESTIONS_PATH} ]]; then
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_AUTOSUGGESTIONS_PATH}
fi
if [[ ! -d ${VIM_VUNDLE_PATH} ]]; then
git clone https://github.com/VundleVim/Vundle.vim.git ${VIM_VUNDLE_PATH}
fi
vim -u ${HOME}/dotfiles/vim/.vimrc +PluginInstall +qall
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} plugins intalled"
}
function perform_dotfiles_installation {
dotfiles_dirs=$@
for dotfiles_directory in ${dotfiles_dirs[*]}; do
pushd ${dotfiles_directory}
dotfiles=$(find -follow -type f -printf '%P\n')
for dotfile in ${dotfiles}; do
dotfile_path=$(dirname ${dotfile})
dotfile_abspath=${HOME}/${dotfile_path}
mkdir -p ${dotfile_abspath}
ln -fs ${PWD}/${dotfile} ${HOME}/${dotfile}
echo Created symlink "\"${HOME}/${dotfile}\""
done
popd
done
}
function install_dotfiles {
perform_dotfiles_installation "${DOTFILES_DIRS[@]}"
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} Regular dotfiles installed"
}
function setup_default_shell {
echo ${SUDO_PASSWORD} | sudo chsh -s /usr/bin/zsh ${USER}
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} default shell is changed"
}
function setup_chosen {
if [[ -n ${INSTALL_PACKAGES} || -n ${CHANGE_SHELL} ]]; then
store_sudo_password
fi
if [[ -n ${INSTALL_PACKAGES} ]]; then
install_packages
fi
if [[ -n ${INSTALL_PLUGINS} ]]; then
install_plugins
fi
if [[ -n ${INSTALL_DOTFILES} ]]; then
install_dotfiles
fi
if [[ -n ${CHANGE_SHELL} ]]; then
setup_default_shell
fi
}
if [ -z $* ]; then
echo -e "${LIGHT_GREEN}[INFO]${NO_COLOR} No options found, proceeding with manual install..."
fi
while getopts "ad" flag; do
case ${flag} in
a)
store_sudo_password
install_packages
install_plugins
install_dotfiles
setup_default_shell
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} All done"
exit 0
;;
d)
install_dotfiles
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} All done"
exit 0
;;
*)
echo -e "${LIGHT_RED}[ERROR]${NO_COLOR} Illegal option found!"
exit 1
;;
esac
done
# if no options provided
if [[ $OPTIND -eq "1" ]]; then
store_installation_options
setup_chosen
echo -e "${LIGHT_GREEN}[SUCCESS]${NO_COLOR} All done"
exit 0
fi