-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_linux.sh
More file actions
executable file
·228 lines (197 loc) · 5 KB
/
setup_linux.sh
File metadata and controls
executable file
·228 lines (197 loc) · 5 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
function _usage()
{
echo "Usage: setup_linux.sh [OPTION]..."
echo "Options:"
echo " -b, --bash Use bash"
echo " -d, --development Setup for development"
echo " -g, --gui Setup for GUI"
echo " -l, --laptop Setup for laptop"
echo " -h, --help Show this message"
}
function _unrecognised_option()
{
echo "setup.sh: unrecognised option '$1'"
echo "Try 'setup.sh --help' for more information."
}
function _parse_options()
{
# Convert long options to short options
for arg in "$@"; do
shift
case "$arg" in
"--bash") set -- "$@" "-b" ;;
"--development") set -- "$@" "-d" ;;
"--gui") set -- "$@" "-g" ;;
"--laptop") set -- "$@" "-l" ;;
"--help") set -- "$@" "-h" ;;
"--"*) _unrecognised_option {$arg}; exit 2;;
*) set -- "$@" "$arg" ;;
esac
done
# Parse short options
OPTIND=1
while getopts "bdglh" opt
do
case "$opt" in
"b") bash=true ;;
"d") development=true ;;
"g") gui=true ;;
"l") laptop=true ;;
"h") _usage; exit 0 ;;
esac
done
shift $(expr $OPTIND - 1)
}
function _setup()
{
if [ "$bash" = true ]; then
linux_dotfiles+=" $bash_dotfiles"
fi
if [ "$development" = true ]; then
dependencies+=" curl"
fi
if [ "$gui" = true ]; then
linux_dotfiles+=" $gui_dotfiles"
dependencies+=" i3 i3blocks rofi rxvt-unicode xsel solaar mousepad pcmanfm ddcutil autorandr xclip"
fi
if [ "$laptop" = true ]; then
dependencies+=" xbacklight"
fi
}
function _find_package_manager()
{
pacman=`command -v pacman`
if [ -n "$pacman" ]; then
package_manager_command="$pacman -Syu --noconfirm "
return
fi
apt=`command -v apt`
if [ -n "$apt" ]; then
package_manager_command="$apt -y install "
return
fi
echo "Package manager not found"
exit 1
}
function _backup()
{
echo -e "${bold}Backing up existing config files...${normal}"
now=`date +%y%m%d_%H%M%S`
mkdir -p $backup_dir/$now
dotfiles="$shared_dotfiles $linux_dotfiles"
for file in $dotfiles; do
if [ -f ~/.$file ]; then
mv -v ~/.$file $backup_dir/$now
fi
done
for dir in $config_dirs; do
if [ -d ~/.config/$dir ]; then
mv -v ~/.config/$dir $backup_dir/$now
fi
done
for dir in $gui_config_dirs; do
if [ -d $dir ]; then
mv -v ~/.config/$dir $backup_dir/$now
fi
done
}
function _symlinks()
{
echo -e "${bold}Adding symlinks...${normal}"
for file in $shared_dotfiles; do
ln -sfv $dotfiles_dir/shared/$file ~/.$file
done
echo "linux dotfiles $linux_dotfiles"
for file in $linux_dotfiles; do
ln -sfv $dotfiles_dir/linux/$file ~/.$file
done
if [ "$gui" = true ]; then
for dir in $gui_config_dirs; do
ln -sfv $dotfiles_dir/$dir ~/.config
done
fi
}
function _packages()
{
echo -e "${bold}Installing dependencies...${normal}"
sudo $package_manager_command $dependencies
}
function _zsh()
{
echo -e "${bold}Installing zsh plugins...${normal}"
if [ ! -d ~/.zsh/zsh-autosuggestions ]; then
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
else
echo "zsh-autosuggestions already installed"
fi
if [ ! -d ~/.zsh/zsh-history-substring-search ]; then
git clone https://github.com/zsh-users/zsh-history-substring-search ~/.zsh/zsh-history-substring-search
else
echo "zsh-history-substring-search already installed"
fi
}
function _vim()
{
mkdir -p ~/.vim/undo ~/.vim/swp
echo -e "${bold}Installing Vundle...${normal}"
vundle_dir=~/.vim/bundle/Vundle.vim
if [ ! -d $vundle_dir ]; then install_vundle=true; else install_vundle=false; fi
if [ "$install_vundle" = true ]; then
git clone https://github.com/gmarik/vundle.git $vundle_dir
else
echo "Vundle already installed"
fi
}
function _nvm()
{
if [ "$development" = true ]; then
echo -e "${bold}Installing nvm...${normal}"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm -v > /dev/null
if [ $? != 0 ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
else
echo "nvm already installed"
fi
fi
}
function _x()
{
if [ "$gui" = true ]; then
xrdb ~/.Xresources
fi
}
function _cleanup()
{
echo -e "${bold}Backups of config files have been created in $backup_dir/$now${normal}"
if [ "$install_vundle" = true ]; then
echo -e "${bold}To finish setting up Vundle, open vim and run :PluginInstall${normal}"
fi
}
bash=false
development=false
gui=false
laptop=false
shared_dotfiles="aliases docker_aliases git_aliases gitconfig tmux.conf vimrc zshrc"
linux_dotfiles="dir_colors"
bash_dotfiles="bashrc bash_profile"
gui_config_dirs="i3 i3blocks rofi"
gui_dotfiles="Xresources"
dotfiles_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
dependencies="tmux vim git fzf gawk"
backup_dir=$dotfiles_dir/backup
vundle_dir=~/.vim/bundle/Vundle.vim
bold=`tput setaf 7`
normal=`tput sgr0`
_parse_options $@
_setup
_find_package_manager
_backup
_symlinks
_packages
_zsh
_vim
_nvm
_x
_cleanup